Luftdaten

Post Reply
svde
Posts: 17
Joined: Sunday 17 April 2016 10:36
Target OS: Linux
Domoticz version:
Contact:

Luftdaten

Post by svde » Thursday 10 May 2018 16:34

dzVents script to retreive sensor data from my https://luftdaten.info sensor.

My luftdaten device contains SDS10, DHT22 and BME280 sensors. I created 4 dummy devices:
  • PM10: custom sensor, X-axis: µg/m3
  • PM2.5, custom sensor, X-axis: µg/m3
  • DHT22: Temp + Humidity
  • BM280: Temp + Humidity + Baro

Code: Select all

local FQDN = 'luftdaten.xxxx.xx'

return {
        active = true,
        on = {
                timer = { 'every minute' },
                httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
        },
        execute = function(domoticz, item)

                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 hum, 7: BME280 baro
                                        domoticz.devices('Luftdaten PM10').updateCustomSensor(item.json.sensordatavalues[1].value)
                                        domoticz.devices('Luftdaten PM2.5').updateCustomSensor(item.json.sensordatavalues[2].value)
                                        domoticz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
                                        domoticz.devices('Luftdaten BME280').updateTempHumBaro(item.json.sensordatavalues[5].value,item.json.sensordatavalues[6].value,0,(item.json.sensordatavalues[7].value/100),0)
                                end
                        else
                                -- oops
                                domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
                                domoticz.log(item.data, domoticz.LOG_ERROR)
                        end
                end
        end
}

PieterS
Posts: 20
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 3.8153
Location: Netherlands
Contact:

Re: Luftdaten

Post by PieterS » Wednesday 16 May 2018 23:50

Thanks for this script.
Running stable version of Domoticz V3.8153
Renamed the name of sensors and filled in right URL in line 13

In the logfile/Status is written:
2018-05-16 23:38:00.338 dzVents: Info: ------ Start internal script: Luftdaten:, trigger: every minute
2018-05-16 23:38:00.338 dzVents: Info: ------ Finished Luftdaten

In the logfile/Problem is written:
2018-05-16 23:38:00.338 Error: dzVents: Error: An error occured when calling event handler Luftdaten
2018-05-16 23:38:00.338 Error: dzVents: Error: ...ticz/var/scripts/dzVents/generated_scripts/Luftdaten.lua:11: attempt to index local 'item' (a nil value)

Line 11: if (item.isTimer) then

Hope you can give me some hints because I got no data :roll:
Maybe because of the first line in the script? Missed some info...

Code: Select all

local FQDN = 'luftdaten.xxxx.xx'

return {
        active = true,
        on = {
                timer = { 'every minute' },
                httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
        },
        execute = function(domoticz, item)

                if (item.isTimer) then
                        domoticz.openURL({
                                url = 'http://192.168.1.41/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 hum, 7: BME280 baro
                                        domoticz.devices('Luftdaten PM10').updateCustomSensor(item.json.sensordatavalues[1].value)
                                        domoticz.devices('Luftdaten PM2.5').updateCustomSensor(item.json.sensordatavalues[2].value)
                                        domoticz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
                                        domoticz.devices('Luftdaten BME280').updateTempHumBaro(item.json.sensordatavalues[5].value,item.json.sensordatavalues[6].value,0,(item.json.sensordatavalues[7].value/100),0)
                                end
                        else
                                -- oops
                                domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
                                domoticz.log(item.data, domoticz.LOG_ERROR)
                        end
                end
        end
}
Thanks in advance.

dannybloe
Posts: 1405
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: Luftdaten

Post by dannybloe » Thursday 17 May 2018 6:41

You are using features that are not available in your version of Domoticz. Switch to the beta version.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests