Small background info, because I life nearby chemical industy where it's most of the time safe but for that one moment there is an problem I like to shutdown my mechanical ventilation at home.
So I have found that based on the website https://www.luchtmeetnet.nl/ the info from the RIVM is avalible to use (http://www.lml.rivm.nl/tabel/)
(sorry only usefull for the Netherlands)
From that part is possible to import the data into Domoticz, but therefore you must manual insert total 7 virtual text sensors with the next labels:
PM10 = Fijnstof (particulates)
O3 = Ozon (ozone)
NO = Stikstofmonoxide (nitric oxide)
CO = Koolstofmonoxide (carbon monoxide)
SO2 = Zwaveldioxide (sulfur dioxide)
NH3 = Ammoniak (Ammonia) -> (R717 for the Refrigeration engineers )
NO2 = Stikstofdioxide (nitrogen dioxide)
then inside the script:
1) set the idx codes at the right place.
2) set the used AirQuality location from the website nearby your location into the script (sorry it's in the bottem of the script)
Code: Select all
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xml.etree.ElementTree as ET
import requests
from requests.exceptions import ConnectionError
domoticz_devicesIdx = {"PM10": 1,
"O3": 2,
"NO": 3,
"CO": 4,
"SO2": 5,
"NH3": 6,
"NO2": 7
}
domoticz_server = "http://localhost"
domoticz_port = 8080
class AirQuality:
def __init__(self, location):
self.link = "http://www.lml.rivm.nl/xml/actueel.xml"
self.location = location
timedata = "http://www.lml.rivm.nl/xml/actueel-update.xml"
z = requests.get(timedata)
f = ET.fromstring(z.content)
data = f.getchildren()[0].getchildren()[0].getchildren()
year = data[0].text
month = data[1].text
day = data[2].text
hour = data[3].text
self.fetch()
print "Fetching data from: %s/%s/%s, hour: %s" % (day, month, year, hour)
def push(self, device, value):
try:
requests.get(
"%s:%d/json.htm?type=command¶m=udevice&idx=%d&nvalue=0&svalue=%s" %
(domoticz_server, domoticz_port, device, value))
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()
components = {}
for element in elements:
data = element.getchildren()
station = data[2].text
component = data[3].text
unit = data[4].text
value = data[5].text
if not (station.lower() == self.location.lower()):
continue
components[component] = '%s%s' % (value, unit)
for component in domoticz_devicesIdx.keys():
device = domoticz_devicesIdx[component]
try:
value = components[component]
except KeyError:
value = "n/a"
self.push(device, value)
AirQuality("NL01489")
At this moment there are an few point that must be changed in the future:
- text sensor to airquality sensor with the correct units.
- find out the save thresholds of the sensors and send it maybe to an alert level sensor.