P2000 to Domoticz for central ventilation
Posted: 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.
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¶m=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()