Page 1 of 1

P2000 to Domoticz for central ventilation

Posted: Monday 05 June 2017 15:27
by phoenixblue
Hi,

I have for the Dutch users maybe an nice script for Domoticz to control your home ventilation when there is an current fire or other problem where it's handy to shutdown you home ventilation.

The script is build to import P2000 messages that will check if there is an active "GRIP" messages, after import it will compare the location with the GPS location that is set into the script.
When the result is positive it will send the info to Domoticz to control for example the home ventilation system.

Setup
First create an virtual Alert device into domoticz to push the info to and setup inside this script the following info:
domoticz_server = "http://localhost"
domoticz_port = 8080
domoticz_device = 1
alert_range = 25 # in km
llatHome = xx.xxxxx
lngHome = xx.xxxx

Note: The script is also able to check the GPS location from Domoticz.

Made an cronejob to run this script every x time to check the P2000 server. For test you can set the random_debug to 1 to send GRIP alerts to domotics when needed.

There are some issues to solve but maybe someone has an nice idea to solve it.
- Insert an option to send messages 1 time so there are no double messages in the system.
- Debug the default level to green when there is no actual message (already start it with it)
- Use an RTL_SDR stick to receive local the P2000 messages like the airplane script.

Code: Select all

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import xml.etree.ElementTree as ET
import requests
import json
import math
import random
from requests.exceptions import ConnectionError


domoticz_server = "http://localhost"
domoticz_port = 8080
domoticz_device = 1
alert_range = 25  # in km
random_debug = 0 # 1 for enable

llatHome = xx.xxxxx
lngHome = xx.xxxx
# Try to get the data from domoticz
try:
    data = json.loads(
        requests.get(
            "%s:%d/json.htm?type=settings" %
            (domoticz_server, domoticz_port)).content)
    latHome = float(data['Location']['Latitude'])
    lngHome = float(data['Location']['Longitude'])
except:
    pass


class GripAlert:

    def __init__(self):
        self.link = "http://feeds.livep2000.nl/"
        if random_debug:
            self.push(random.randint(0, 4), "debug push")
        self.fetch()

    def push(self, level, text):
        try:
            requests.get(
                "%s:%d/json.htm?type=command&param=udevice&idx=%d&nvalue=%d&svalue=%s" %
                (domoticz_server, domoticz_port, domoticz_device, level, text))
        except ConnectionError:
            print "I wasn't able to contact the domoticz server, is it up?"

    def fetch(self):
        # fetch the data and push it
        z = requests.get(self.link)
        elements = ET.fromstring(z.content).getchildren()[0].getchildren()

        pushed = 0
        for element in elements[7:]:
            data = element.getchildren()
            try:
                title = data[0].text.replace("<br/>", "\n")
                description = data[3].text.replace("<br/>", "\n")
                lat = float(data[6].text)
                lng = float(data[7].text)
                if not (self.calculateDistance(latHome, lngHome, lat,
                        lng) <= alert_range):
                    continue

                level = 0
                if ("grip: 1" in title.lower()
                        or "grip: 1" in description.lower()):
                    level = 1
                elif ("grip: 2" in title.lower() or "grip: 2" in description.lower()):
                    level = 2
                elif ("grip: 3" in title.lower() or "grip: 3" in description.lower()):
                    level = 3
                elif ("grip: 4" in title.lower() or "grip: 4" in description.lower()):
                    level = 4

                if not level:
                    continue

                message = "%s\n%s" % (title, description)
                self.push(level, message)
                print "Pushed alert, GRIP Level: %d\nMessage: %s" % (level, message)

                pushed += 1
            except:
                pass

        if not pushed:
            print "No alerts were pushed"

    def calculateDistance(self, lat1, lng1, lat2, lng2):
        radius = 6371

        dLat = (lat2 - lat1) * math.pi / 180
        dLng = (lng2 - lng1) * math.pi / 180

        lat1 = lat1 * math.pi / 180
        lat2 = lat2 * math.pi / 180

        val = math.sin(dLat / 2) * math.sin(dLat / 2) + math.sin(dLng / 2) * \
            math.sin(dLng / 2) * math.cos(lat1) * math.cos(lat2)
        ang = 2 * math.atan2(math.sqrt(val), math.sqrt(1 - val))
        return radius * ang


GripAlert()

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 06 June 2017 21:25
by assenzuid
Nice and thanks for sharing.

Re: P2000 to Domoticz for central ventilation

Posted: Wednesday 07 June 2017 10:16
by EdwinK
I created the device, but can't seem to find it. It is in the device list, but not on any of the other tabs.
Device list
Device list
Screen Shot 2017-06-07 at 10.11.13.png (30.32 KiB) Viewed 4837 times
Duh... Should have enabled the device. Smart me.

Re: P2000 to Domoticz for central ventilation

Posted: Monday 21 August 2017 23:09
by EdwinK
And now that we have a GRIP 2 situation in my region, it doesn't show on Domoticz :(

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 8:42
by EdwinK
Mmm... Now the alerts show up.

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 9:09
by EdwinK
Something looks wrong. I think I get the same data over and over.
Spoiler: show
2017-08-22 00:13:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:12:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:11:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:10:07 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:09:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:08:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:07:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:06:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:05:06 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:04:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:03:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:02:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:01:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-22 00:00:06 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:59:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:58:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:57:02 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:56:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:55:06 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:54:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:53:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:52:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:51:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:50:05 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:49:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:48:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:47:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:46:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:45:06 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:44:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:43:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:42:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:41:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:40:06 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )
2017-08-21 23:39:03 A1 (GRIP: 2) AMBU 17114 Botlekweg 3197KA Botlek Rotterdam BOTLEK bon 80414 1420999 MKA Rotterdam-Rijnmond ( Monitorcode ) 1420014 MKA Rotterdam-Rijnmond ( Ambulance 17-114 )

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 9:59
by EdwinK
Screen Shot 2017-08-22 at 09.58.52.png
Screen Shot 2017-08-22 at 09.58.52.png (91.04 KiB) Viewed 4472 times

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 19:17
by Derik
should this not be possible without a stick?
There are different site where the alarms can be found,,

Sorry i cannot make the script respect for the builder!

Only a web location to get the data is perhaps better?

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 19:46
by EdwinK
You don't need any stick for this. The data comes from a website.

self.link = "http://feeds.livep2000.nl/"

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 19:51
by Derik
EdwinK wrote: Tuesday 22 August 2017 19:46 You don't need any atick for this. The data comes from a website.
mmm Sorry..
I read this....
Use an RTL_SDR stick to receive local the P2000 messages like the airplane script.

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 19:56
by Derik
mmm what type virtual do i need?

And can i run this script with the intern python option?
ScreenShot130.png
ScreenShot130.png (31.32 KiB) Viewed 4427 times
What type is the best option [ i do not understand a thing of this optiosn...:_( ]
Or just external script, and use a crontab?

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 22 August 2017 20:08
by EdwinK
First create an virtual Alert device into domoticz to push the info to

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 30 January 2018 13:57
by Siewert308SW
Just a thought.
What if i only want to follow our local fire dep.
Could it be possible to insert a option to show only alarms from a specfic CAP code

Re: P2000 to Domoticz for central ventilation

Posted: Tuesday 30 January 2018 23:40
by phoenixblue
I think this will not be an problem, in that case there must be made an other version op de script without the gps part.

Re: P2000 to Domoticz for central ventilation

Posted: Wednesday 31 January 2018 19:37
by Siewert308SW
thx, looking forward to it...

Re: P2000 to Domoticz for central ventilation

Posted: Monday 01 October 2018 23:24
by EdwinK
Any luck with this?

Re: P2000 to Domoticz for central ventilation

Posted: Wednesday 25 December 2019 16:39
by hendrikenrenny
Hi guys,

I get the error message "ModuleNotFoundError: No module named 'requests' "

Any idea how to solve this?

I'm using Domoticz 4.0717.

Thanks,


Hendrik

Re: P2000 to Domoticz for central ventilation

Posted: Wednesday 25 December 2019 20:34
by FireWizard
Hi.

In case of Python 2 use: pip install requests.
In case of Python 3 use: pip3 install requests.

In case you encounter permission problems use: sudo pip install requests or
sudo pip3 install requests

Regards

Re: P2000 to Domoticz for central ventilation

Posted: Sunday 29 December 2019 13:04
by hendrikenrenny
Hi,

Thanks. It is installed now (for both Python 2 and 3):

pi@DOMOTICZ-MAIN2:~ $ sudo pip install requests
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: requests in /usr/lib/python2.7/dist-packages (2.21.0)
pi@DOMOTICZ-MAIN2:~ $ sudo pip3 install requests
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.21.0)
pi@DOMOTICZ-MAIN2:~ $

But I keep seeing this errors in the Domoticz logs:

2019-12-29 13:01:00.470 Error: EventSystem: Failed to execute python event script "P2000"
2019-12-29 13:01:00.470 Error: EventSystem: Traceback (most recent call last):
2019-12-29 13:01:00.470 Error: EventSystem: File "<string>", line 5, in <module>
2019-12-29 13:01:00.470 Error: EventSystem: ModuleNotFoundError: No module named 'requests'

So I made the python script in the script editor of Domoticz, time triggered. The script is being called every minute, which is ok. I didnot install a crontab, as Domoticz starts the script.

So issue is still not solved.

Would be great if somebody can help me out...

Hendrik