My luftdaten device contains SDS10, DHT22 and BME280 sensors. I created 4 dummy devices (name of the devices needs to match the names in the script):
- Name: "Luftdaten PM10", Type: custom sensor, X-axis: µg/m3
- Name: "Luftdaten PM2.5", Type: custom sensor, X-axis: µg/m3
- Name: "Luftdaten DHT22", Type: Temp + Humidity
- Name: "Luftdaten BME280", Type: Temp + Humidity + Baro, (optional sensor)
Code: Select all
local FQDN = 'luftdaten.xxx.com'
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
for i, t2 in pairs(item.json.sensordatavalues) do
if (t2.value_type == 'SDS_P1') then
domoticz.devices('Luftdaten PM10').updateCustomSensor(t2.value)
elseif (t2.value_type == 'SDS_P2') then
domoticz.devices('Luftdaten PM2.5').updateCustomSensor(t2.value)
elseif (t2.value_type == 'temperature') then
temperature = t2.value
elseif (t2.value_type == 'humidity') then
humidity = t2.value
elseif (t2.value_type == 'BME280_temperature') then
BME280_temperature = t2.value
elseif (t2.value_type == 'BME280_pressure') then
BME280_pressure = t2.value/100
elseif (t2.value_type == 'BME280_humidity') then
BME280_humidity = t2.value
end
end
-- if (SDS_P1 ~= nil) then
-- domoticz.devices('Luftdaten PM10').updateCustomSensor(SDS_P1)
-- end
-- if (SDS_P2 ~= nil) then
-- domoticz.devices('Luftdaten PM2.5').updateCustomSensor(SDS_P2)
-- end
if (temperature ~= nil and humidity ~= nil) then
domoticz.devices('Luftdaten DHT22').updateTempHum(temperature,humidity,0)
end
if (BME280_temperature ~= nil and BME280_humidity ~= nil and BME280_pressure ~= nil) then
-- if (tonumber (BME280_temperature) < 100) and (tonumber (BME280_pressure) < 1050) then
domoticz.devices('Luftdaten BME280').updateTempHumBaro(BME280_temperature,BME280_humidity,0,BME280_pressure,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
}
2020.04.25: updated code section above (order of the BME sensors was changed), updated text stating which domoticz version is required
2020.04.12: updated the scripts behind the download links (order of the BME sensors was changed)
2018.06.30: added extra check on the values coming from the BME280 sensor. I'm sometimes getting erratic readings and I don't want those to be uploaded to domoticz.
2018.10.18: added download links for scripts with different sensors.