Luftdaten  [SOLVED]

Moderator: leecollings

rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Luftdaten

Post by rrozema »

waltervl wrote: Monday 04 October 2021 21:51 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).
I fully disagree on this with you: a Domoticz crash doesn't always mean you lose all the contents of your sd/ssd. Db corruptions can occur for example by an update gone wrong and all sorts of other things can go wrong making you have to re-install domoticz and/or it's db. Keeping collected data in separate storage based on what its intended purpose is, is always a good idea: The domoticz.db is for use by domoticz only and a separate database should be used for your collected data. Influxdb is an easy choice for this because it's well integrated as a data-push. You can store that influxdb in the same machine with your Domoticz because that's available already. But you might just as well store it in some other machine -f.e. if you're really afraid of losing the data when your sd/ssd crashes-. You can also store data from other sources in that same influx database, for example from a second domoticz instance or from completely other sources. But still the most important point for me to have a separate storage for my collected data is that the use for the both data sets is different: A very important principle to me is to never re-use the same thing for different purposes. Re-using the same data for a secondary purpose, almost without exception leads to conflicts and limitations in the future.
User avatar
waltervl
Posts: 5376
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by waltervl »

My principle is to use what I have. Exporting data to influxdb is an extra layer that should not be used for backup purposes.
So agreed that influxdb is better in storing loads of derailed information but it has no extra function as an extra data backup possibility.

But we agree to disagree :-)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ariepapa
Posts: 1
Joined: Thursday 15 December 2022 21:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Netherlands
Contact:

Re: Luftdaten

Post by ariepapa »

Used your script but needed to adept it a little because i used different sensor BMP280 instead of BME280
Setup of the sensor:
Add hardware (dummy device)
Add devices:
> 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 BMP280", Type: Temp + Baro, (optional sensor)

Code: Select all

local FQDN = 'luftdaten.[xxx].com' -- without the []

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

		if (item.isTimer) then
			domoticz.openURL({
				url = 'http://.... local ip of the sensor.... /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 == 'BMP280_temperature') then
                            BMP280_temperature = t2.value
                        elseif (t2.value_type == 'BMP280_pressure') then
                            BMP280_pressure = t2.value/100
                        end
                    end
                    if (temperature ~= nil and humidity ~= nil) then
                        domoticz.devices('Luftdaten DHT22').updateTempHum(temperature,humidity,0)
                    end
                    if (BMP280_temperature ~= nil and BMP280_pressure ~= nil) then
                            domoticz.devices('Luftdaten BMP280').updateTempBaro(BMP280_temperature,BMP280_pressure,0)
                    end
				end
			else
				-- oops
				domoticz.log('Error fetching Luftdaten data', domoticz.LOG_ERROR)
				domoticz.log(item.data, domoticz.LOG_ERROR)
			end
		end
	end
}
updateTempBaro according to the wiki finally made it work for me.

Thanks for the great script, and all the credits for svde!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests