P2000 to Domoticz for central ventilation

Python and python framework
Post Reply
User avatar
phoenixblue
Posts: 82
Joined: Friday 25 November 2016 12:20
Target OS: Raspberry Pi
Domoticz version: 3.7392
Contact:

P2000 to Domoticz for central ventilation

Post by phoenixblue » Monday 05 June 2017 15:27

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()
scripts on github: Link

assenzuid
Posts: 166
Joined: Friday 13 November 2015 10:11
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands, Emmen Area
Contact:

Re: P2000 to Domoticz for central ventilation

Post by assenzuid » Tuesday 06 June 2017 21:25

Nice and thanks for sharing.

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Wednesday 07 June 2017 10:16

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.
Screen Shot 2017-06-07 at 10.11.13.png
Device list
Screen Shot 2017-06-07 at 10.11.13.png (30.32 KiB) Viewed 2863 times
Duh... Should have enabled the device. Smart me.
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Monday 21 August 2017 23:09

And now that we have a GRIP 2 situation in my region, it doesn't show on Domoticz :(
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Tuesday 22 August 2017 8:42

Mmm... Now the alerts show up.
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Tuesday 22 August 2017 9:09

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 )
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Tuesday 22 August 2017 9:59

Screen Shot 2017-08-22 at 09.58.52.png
Screen Shot 2017-08-22 at 09.58.52.png (91.04 KiB) Viewed 2498 times
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
Derik
Posts: 2173
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: P2000 to Domoticz for central ventilation

Post by Derik » Tuesday 22 August 2017 19:17

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?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Tuesday 22 August 2017 19:46

You don't need any stick for this. The data comes from a website.

self.link = "http://feeds.livep2000.nl/"
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
Derik
Posts: 2173
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: P2000 to Domoticz for central ventilation

Post by Derik » Tuesday 22 August 2017 19:51

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.
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
Derik
Posts: 2173
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: P2000 to Domoticz for central ventilation

Post by Derik » Tuesday 22 August 2017 19:56

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 2453 times
What type is the best option [ i do not understand a thing of this optiosn...:_( ]
Or just external script, and use a crontab?
Last edited by Derik on Tuesday 22 August 2017 20:29, edited 1 time in total.
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Tuesday 22 August 2017 20:08

First create an virtual Alert device into domoticz to push the info to
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

User avatar
Siewert308SW
Posts: 607
Joined: Monday 29 December 2014 16:47
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands - Zoutkamp (gn)
Contact:

Re: P2000 to Domoticz for central ventilation

Post by Siewert308SW » Tuesday 30 January 2018 14:57

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
Setup:
- RPi3 - PIco HV3.0A / Domo Beta 3.9XXX / RFXtrx433E / Aeotec Gen5
- RPi3 - PIco HV3.0A / PiHole / PiVPN / NAS / Print Server
- Youless Elec&Gas
- FI9803P Cams
- KD101 detectors
- Zwave & KaKu

MyDomoticz scripts: @GitHub
PIco UPS Toolkit: @GitHub

User avatar
phoenixblue
Posts: 82
Joined: Friday 25 November 2016 12:20
Target OS: Raspberry Pi
Domoticz version: 3.7392
Contact:

Re: P2000 to Domoticz for central ventilation

Post by phoenixblue » Wednesday 31 January 2018 0:40

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.
scripts on github: Link

User avatar
Siewert308SW
Posts: 607
Joined: Monday 29 December 2014 16:47
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands - Zoutkamp (gn)
Contact:

Re: P2000 to Domoticz for central ventilation

Post by Siewert308SW » Wednesday 31 January 2018 20:37

thx, looking forward to it...
Setup:
- RPi3 - PIco HV3.0A / Domo Beta 3.9XXX / RFXtrx433E / Aeotec Gen5
- RPi3 - PIco HV3.0A / PiHole / PiVPN / NAS / Print Server
- Youless Elec&Gas
- FI9803P Cams
- KD101 detectors
- Zwave & KaKu

MyDomoticz scripts: @GitHub
PIco UPS Toolkit: @GitHub

User avatar
EdwinK
Posts: 1324
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: P2000 to Domoticz for central ventilation

Post by EdwinK » Monday 01 October 2018 23:24

Any luck with this?
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests