Page 3 of 4
Re: Luftdaten
Posted: Wednesday 19 August 2020 12:17
by Stimpy68
Code: Select all
2020-08-19 12:17:28.460 Error: dzVents: Error: (3.0.2) error loading module 'Luftdaten' from file '/domoticz/scripts/dzVents/generated_scripts/Luftdaten.lua':
2020-08-19 12:17:28.460 /domoticz/scripts/dzVents/generated_scripts/Luftdaten.lua:29: unexpected symbol near '0'

Re: Luftdaten
Posted: Wednesday 19 August 2020 20:22
by waaren
Stimpy68 wrote: ↑Wednesday 19 August 2020 12:17
2020-08-19 12:17:28.460 /domoticz/scripts/dzVents/generated_scripts/Luftdaten.lua:29: unexpected symbol near '0'[/code]
Another try
Code: Select all
local FQDN = '192.168.0.85'
return {
active = true,
on = {
timer = { 'every minute' },
httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
},
execute = function(domoticz, item)
local maxValue = 100000
local minValue = 0
if (item.isTimer) then
domoticz.openURL({
url = 'http://' .. FQDN .. '/data.json',
method = 'GET',
callback = 'luftdatenRetrieved'
})
elseif (item.isHTTPResponse) then
if (item.ok and item.isJSON) then -- statusCode == 2xx
if tonumber(item.json.age) < 60 then
-- 1: SDS_P1 PM10, 2: SDS_P2 PM2.5, 3: DHT22 temp, 4: DHT22 hum, 5: BME280 temp, 6: BME280 baro, 7: BME280 hum
domoticz.log(item.json,domoticz.LOG_FORCE)
if item.json.sensordatavalues and
item.json.sensordatavalues[1] and
item.json.sensordatavalues[1].value and
tonumber(item.json.sensordatavalues[1].value) ~= nil and
tonumber(item.json.sensordatavalues[1].value) < maxValue and
tonumber(item.json.sensordatavalues[1].value) > minValue then
domoticz.devices('Fijn stof PM10').updateCustomSensor(item.json.sensordatavalues[1].value)
domoticz.devices('Fijn stof PM2.5').updateCustomSensor(item.json.sensordatavalues[2].value)
else
domoticz.log('Skipping this reading', domoticz.LOG_ERROR)
end
--[[
domoticz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
if item.json.sensordatavalues[5] and item.json.sensordatavalues[6] and item.json.sensordatavalues[6].value and item.json.sensordatavalues[6].value then
if ( ( tonumber (item.json.sensordatavalues[5].value) or 100 ) < 100) and ( (tonumber (item.json.sensordatavalues[6].value) or 105000 ) < 105000) then
domoticz.devices('Luftdaten BME280').updateTempHumBaro(item.json.sensordatavalues[5].value,item.json.sensordatavalues[7].value,0,(item.json.sensordatavalues[6].value/100),0)
end
end
]]--
end
else
-- oops
domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
domoticz.log(item.data, domoticz.LOG_ERROR)
end
end
end
}
Re: Luftdaten
Posted: Thursday 20 August 2020 6:36
by Stimpy68
waaren wrote: ↑Wednesday 19 August 2020 20:22
Stimpy68 wrote: ↑Wednesday 19 August 2020 12:17
2020-08-19 12:17:28.460 /domoticz/scripts/dzVents/generated_scripts/Luftdaten.lua:29: unexpected symbol near '0'[/code]
Another try
Thanks, no errors this time. Will keep you posted about the results!
Re: Luftdaten
Posted: Saturday 22 August 2020 7:51
by Stimpy68
It's 48 hours now, and no spikes! Thanks Waaren!

Re: Luftdaten
Posted: Saturday 22 August 2020 9:48
by svde
Stimpy68 wrote: ↑Saturday 22 August 2020 7:51
It's 48 hours now, and no spikes! Thanks Waaren!
Can you also test with the latest script? The reason why I changed it (to where it is now) is to be able to cope with sensors not being read once in a while...
Re: Luftdaten
Posted: Saturday 22 August 2020 11:34
by Stimpy68
svde wrote: ↑Saturday 22 August 2020 9:48
Stimpy68 wrote: ↑Saturday 22 August 2020 7:51
It's 48 hours now, and no spikes! Thanks Waaren!
Can you also test with the latest script? The reason why I changed it (to where it is now) is to be able to cope with sensors not being read once in a while...
This was the test with the latest script, the one a few posts up.
Re: Luftdaten
Posted: Saturday 22 August 2020 12:01
by svde
No it’s not... latest script I wrote is in the first post of this topic.
Re: Luftdaten
Posted: Monday 26 October 2020 18:36
by Eosfoto
I went through the steps exactly as described in the opening post. I do get data from the DHT22 (temperature and humidity), but I get this error from the particulate matter sensor:
Code: Select all
2020-10-26 18: 19: 00.622 Error: dzVents: Error: (3.0.15) Method updateCustomSensor is not available for device "Luftdaten PM10" (deviceType = Air Quality, deviceSubType = Voltcraft CO-20). If you believe this is not correct, please report.
Re: Luftdaten
Posted: Monday 26 October 2020 18:43
by svde
I think you created the wrong type of dummy device (deviceType = Air Quality, deviceSubType = Voltcraft CO-20). The instructions state a customer sensor:
Name: "Luftdaten PM10", Type: custom sensor, X-axis: µg/m3
Name: "Luftdaten PM2.5", Type: custom sensor, X-axis: µg/m3
Re: Luftdaten
Posted: Monday 26 October 2020 19:31
by Eosfoto
Thanks a lot, that brought the solution... Reading....

Re: Luftdaten
Posted: Thursday 10 December 2020 19:47
by GeyerA
Hi,
I initially implemented the way described by you, but since I also do run Weewx, I managed to alter the code in order to retrieve data just from one source. It will also prevent from reading very high values because the data creation is driven by the setting in the sensor/configuration/APIs and a PHP script.
1. PHP script. I keep that one in my /srv/http/weewx folder. I created an empty feinstaub.json (and sds011pmdata.txt which is needed for Weewx and filepile). I think you can obmit the part after feinstaub.json). The name of the file is sds011.php (in my case) and this needs to be set in the API of sensor.
Code: Select all
<?php
$json = file_get_contents("php://input");
$json = file_put_contents("feinstaub.json", $json);
$json_string = file_get_contents("/srv/http/weewx/feinstaub.json");
$parsed_json = json_decode($json_string, true);
$sds011file = fopen("/srv/http/weewx/sds011pmdata.txt", "w") or die("Unable to open file!");
$txt = "pm10_0 = ".($parsed_json['sensordatavalues'][0]['value'])."\n";
fwrite($sds011file, $txt);
$txt = "pm2_5 = ".($parsed_json['sensordatavalues'][1]['value'])."\n";
fwrite($sds011file, $txt);
$txt = "temp = ".($parsed_json['sensordatavalues'][2]['value'])."\n";
fwrite($sds011file, $txt);
$txt = "humid = ".($parsed_json['sensordatavalues'][3]['value'])."\n";
fwrite($sds011file, $txt);
$txt = "signal = ".($parsed_json['sensordatavalues'][8]['value'])."\n";
fwrite($sds011file, $txt);
fclose($sds011file);
?>
This will update/overwrite the data in the feinstaub.json file according your cycle set in sensor (default 145 seconds, I changed to 300 since Weewx just records every 5 mins).
I then created a dvents script looking like this; I kept the email notification for skipped reading. I think this is now not needed anymore since the file is always fed by the API in the sensor.
Code: Select all
return {
active = true,
on = {
timer = { 'every minute' },
httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
},
execute = function(domoticz, item)
local maxValue = 100000
local minValue = -50
if (item.isTimer) then
domoticz.openURL({
url = 'http://192.168.178.39/weewx/feinstaub.json',
method = 'GET',
callback = 'luftdatenRetrieved'
})
elseif (item.isHTTPResponse) then
if (item.ok and item.isJSON) then -- statusCode == 2xx
-- 1: SDS_P1 PM10, 2: SDS_P2 PM2.5, 3: DHT22 temp, 4: DHT22 hum, 5: BME280 temp, 6: BME280 baro, 7: BME280 hum
domoticz.log(item.json,domoticz.LOG_FORCE)
if item.json.sensordatavalues and
item.json.sensordatavalues[2] and
item.json.sensordatavalues[2].value and
tonumber(item.json.sensordatavalues[2].value) ~= nil and
tonumber(item.json.sensordatavalues[2].value) < maxValue and
tonumber(item.json.sensordatavalues[2].value) > minValue then
domoticz.devices('Feinstaub PM10').updateCustomSensor(item.json.sensordatavalues[1].value)
domoticz.devices('Feinstaub PM2.5').updateCustomSensor(item.json.sensordatavalues[2].value)
domoticz.devices('Signal SDS011').updateCustomSensor(item.json.sensordatavalues[9].value)
domoticz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
else
domoticz.log('Skipping this reading', domoticz.LOG_ERROR)
domoticz.email('Error fetching Luftdaten', 'PM10 was above 100000 and measurement was skipped', '[email protected]')
end
--[[
domoticz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
if item.json.sensordatavalues[5] and item.json.sensordatavalues[6] and item.json.sensordatavalues[6].value and item.json.sensordatavalues[6].value then
if ( ( tonumber (item.json.sensordatavalues[5].value) or 100 ) < 100) and ( (tonumber (item.json.sensordatavalues[6].value) or 105000 ) < 105000) then
domoticz.devices('Luftdaten BME280').updateTempHumBaro(item.json.sensordatavalues[5].value,item.json.sensordatavalues[7].value,0,(item.json.sensordatavalues[6].value/100),0)
end
end
]]--
else
-- oops
domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
domoticz.log(item.data, domoticz.LOG_ERROR)
domoticz.email('Error fetching Luftdaten', 'Check log for details', '[email protected]')
end
end
end
}
This could be an alternative to the pulling mode from sensor since it is driven by the sensor updating the .json file after the sensor measured the data.
Re: Luftdaten
Posted: Wednesday 31 March 2021 19:58
by reddo
I copied the latest script in a luftdaten.lua file with my domoticz IP adress in first line (is that what it should be ? That's where this might go wrong actually), placed that in the desired directory /home/ip/domoticz/scripts/dzvents/ and it seems to be runnign but with errors...
Code: Select all
2021-03-31 19:54:58.543 Status: Domoticz V2020.2 (c)2012-2020 GizMoCuz
2021-03-31 19:54:58.573 Status: Build Hash: b63341bc0, Date: 2020-04-26 13:47:55
2021-03-31 19:54:58.575 Status: Startup Path: /home/pi/domoticz/
2021-03-31 19:55:00.025 Sunrise: 07:13:00 SunSet: 20:10:00
2021-03-31 19:55:00.025 Day length: 12:58:00 Sun at south: 13:41:00
2021-03-31 19:55:00.026 Civil twilight start: 06:38:00 Civil twilight end: 20:45:00
2021-03-31 19:55:00.026 Nautical twilight start: 05:55:00 Nautical twilight end: 21:28:00
2021-03-31 19:55:00.026 Astronomical twilight start: 05:09:00 Astronomical twilight end: 22:14:00
2021-03-31 19:55:04.421 Active notification Subsystems: (0/13)
2021-03-31 19:55:04.657 Starting shared server on: :::6144
2021-03-31 19:55:04.159 Status: PluginSystem: Started, Python version '3.7.3'.
2021-03-31 19:55:04.484 Status: WebServer(HTTP) started on address: :: with port 8080
2021-03-31 19:55:04.621 Status: WebServer(SSL) started on address: :: with port 443
2021-03-31 19:55:04.682 Status: TCPServer: shared server started...
2021-03-31 19:55:04.690 Status: RxQueue: queue worker started...
2021-03-31 19:55:07.649 Status: PVOutput (Input): Worker started...
2021-03-31 19:55:07.657 Status: EventSystem: reset all events...
2021-03-31 19:55:07.677 Status: NotificationSystem: thread started...
2021-03-31 19:55:07.695 Status: PluginSystem: Entering work loop.
2021-03-31 19:55:07.712 Status: EventSystem: reset all device statuses...
2021-03-31 19:55:07.888 Status: RFLink: Using serial port: /dev/ttyACM0
2021-03-31 19:55:08.771 Status: MQTT: Connecting to 192.168.1.175:1883
2021-03-31 19:55:08.798 Error: MQTT: Failed to start, return code: 14 (Check IP/Port)
2021-03-31 19:55:13.074 Status: Python EventSystem: Initalizing event module.
2021-03-31 19:55:13.118 Status: EventSystem: Started
2021-03-31 19:55:13.118 Status: EventSystem: Queue thread started...
2021-03-31 19:55:32.203 Error: PVOutput (Input): Error login!
2021-03-31 19:55:37.399 Status: Incoming connection from: 192.168.1.242
2021-03-31 19:55:39.239 Status: MQTT: Connecting to 192.168.1.175:1883
2021-03-31 19:55:39.447 Status: MQTT: connected to: 192.168.1.175:1883
2021-03-31 19:55:44.534 (rflink) Light/Switch (beweginsmelder achtertuin)
2021-03-31 19:55:49.961 (rflink) Temp + Humidity (douche)
2021-03-31 19:55:53.133 EventSystem: Event triggered: CO2_2
2021-03-31 19:56:01.682 Status: dzVents: Info: ------ Start external script: luftdaten.lua:, trigger: "every minute"
2021-03-31 19:56:01.684 Status: dzVents: Info: ------ Finished luftdaten.lua
2021-03-31 19:56:01.687 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2021-03-31 19:56:01.770 Error: Error opening url: http://192.168.1.175/data.json
2021-03-31 19:56:03.058 Status: dzVents: Info: Handling httpResponse-events for: "luftdatenRetrieved"
2021-03-31 19:56:03.058 Status: dzVents: Info: ------ Start external script: luftdaten.lua: HTTPResponse: "luftdatenRetrieved"
2021-03-31 19:56:03.088 Status: dzVents: Info: ------ Finished luftdaten.lua
2021-03-31 19:56:03.059 Error: dzVents: Error: (3.0.2) HTTP/1.1 response: 7 ==>> Couldn't connect to server
2021-03-31 19:56:03.059 Error: dzVents: Error: (3.0.2) Error fetching Luftdaten data
2021-03-31 19:56:03.088 Error: dzVents: Error: (3.0.2)
Dummies are all there in Domoticz, as recommended (temp-hum-baro and customs for the 2.5 and 10, names exactly copied)
Data shows up on the luftdaten map so that side is fine
Anyone any clues on what goes wrong ? I have no idea....
Thanks
EDIT : Used IP of sensor device... working now

Re: Luftdaten
Posted: Tuesday 13 July 2021 11:03
by Herman-H
Is it possible with dzVents to combine these two Custom Sensors to one Sensor Window so that from both the data, PM2.5 and PM10 are visible in one graph. Just like Temperature/Huminity.

- Luftdaten-1.jpg (30.26 KiB) Viewed 2797 times
Re: Luftdaten
Posted: Tuesday 13 July 2021 11:16
by svde
I'm not familiar enough with "custom sensor", is it possible to have it take multiple values? I don't see anything about that here:
https://www.domoticz.com/wiki/Dummy_for ... tom_Sensor.
Re: Luftdaten
Posted: Tuesday 13 July 2021 13:05
by Herman-H
The same here, read a lot but didn't find a solution. I hope maybe "waaren" has a suggestion.
Re: Luftdaten
Posted: Tuesday 13 July 2021 16:19
by waltervl
There is unfortunately no sensor that can store, show and graph multiple custom values.
Re: Luftdaten
Posted: Monday 04 October 2021 20:28
by rrozema
Push your data into an
influx database using 'Settings' -> 'More options' -> 'Data push' -> 'InfluxDB', then you can make any graphs, combining all data from as many sources you want in for example
Grafana. You can install both influxdb and grafana in your local raspberry. Both influxdb and grafana are great products and they're free! Google is your friend for finding instructions how to install and use. There are however a lot of outdated topics on how to get data from Domoticz into Influxdb. Best follow the menu I indicated above and do not use old alternatives like http calls.
Re: Luftdaten
Posted: Monday 04 October 2021 20:41
by waltervl
Or, if you have some SQL knowledge, use the grafana SQLite plugin so you can skip the influxdb export step.
viewtopic.php?f=21&t=35101
Re: Luftdaten
Posted: Monday 04 October 2021 20:58
by rrozema
Yes, that is an option too. However, the amount of data kept in the domoticz.db is quite limited and it's compacted and cleaned from time to time by Domoticz. For more serious data collection it's better to use a separate database like influxdb, as you can store much more data in there, plus you can keep the data in there for as long as you want. Plus you won't lose all your collected data if your domoticz crashes and needs to be re-installed.
Re: Luftdaten
Posted: Monday 04 October 2021 21:51
by waltervl
Agreed on the 5 min interval data (max 7 days in domoticz). For air quality data the Domoticz daily summary would be good enough I suppose.
Not agreed on losing data on a Domoticz crash as automatic database backup is part of Domoticz setup.
If your sd/ssd crashes you would also loose the influxdb data if you did not backup externally (influxdb and Domoticz).