Luftdaten  [SOLVED]

Moderator: leecollings

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

Luftdaten

Post by svde »

dzVents script to retrieve sensor data from my https://luftdaten.info sensor. This script works with 2020.1 release, or later beta's. The script doesn't support multiple lufdaten sensors.

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.06.21: updated code section above, the script will now pick the value_types and values from the json output. One script should work with different sensor combinations.
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.
Last edited by svde on Monday 22 June 2020 9:21, edited 11 times in total.
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

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.
Synology with Domoticz build (V2024.7) in Docker
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Luftdaten

Post by dannybloe »

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.
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

Didn't know that. :roll: Thanks for info. Wil try a beta on my other Syno. :D
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

Installed Domoticz Beta V3.9390. dzVents is enabled.

got error:
2018-05-30 17:12:23.749 Error: EventSystem: in /usr/local/domoticz/var/dzVents/runtime/dzVents.lua: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua:19: attempt to concatenate local 'runtimePath' (a nil value)

Maybe because dzVents is in another path on my Synology DS-718. It is located in

Image

Any solution? Thanks
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

It looks like you have a mismatch between dzVents and domoticz. It look similar to this problem reported on GIT and solved by a Domoticz restart.
Did you upgrade using a @jumbotroll package ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

Thnx Waaren,
I use the Jumbotroll package... Restart did not help..
What's wrong with that?

The problem to which you refer is the Github-version. :cry:
That has a different map-structure..
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

Nothing wrong with the jumbotroll package but based on the error message it looks like the dzVents version is not in line with the domoticz version and I did experience a similar problem on my domoticz installation on my Synology (916+ ; DSM 6.2) with an earlier version but cannot remember with what version. I now have domoticz V3.9483 running on that system without dzVents problems

Could you try installing a later Beta ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

Followed your suggestions:

Upgraded to DSM 6.2 on my DS718+
Did an uninstall of Domoticz.
Upgraded to Domoticz V3.9483 from Jadahl.com (Domoticz Beta for DSM 6.2 with Python)
Did a restore of the database. Most features seems to work. Lost some stuff as icons...
FYI: my sensor is at 192.168.1.41.

Got different results in logfile:

Code: Select all

2018-05-31 13:35:00.349 dzVents: Debug: OpenURL: headers = nil
2018-05-31 13:35:00.350 dzVents: Debug: OpenURL: callback = luftdatenRetrieved
2018-05-31 13:35:00.350 dzVents: Info: ------ Finished Luftdaten
2018-05-31 13:35:00.350 dzVents: Debug: Commands sent to Domoticz:
2018-05-31 13:35:00.350 dzVents: Debug: - OpenURL = {["URL"]="http://192.168.1.41/data.json", ["_trigger"]="luftdatenRetrieved", ["method"]="GET"}
2018-05-31 13:35:00.350 dzVents: Debug: =====================================================
2018-05-31 13:35:00.422 EventSystem: Script event triggered: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua
2018-05-31 13:35:00.464 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 13:35:00.476 dzVents: Debug: dzVents version: 2.4.5
2018-05-31 13:35:00.476 dzVents: Debug: Event triggers:
2018-05-31 13:35:00.476 dzVents: Debug: - HTTPResponse: luftdatenRetrieved
2018-05-31 13:35:00.549 dzVents: Info: Handling httpResponse-events for: "luftdatenRetrieved
2018-05-31 13:35:00.549 dzVents: Info: ------ Start internal script: Luftdaten: HTTPResponse: "luftdatenRetrieved"
2018-05-31 13:35:00.552 dzVents: Info: ------ Finished Luftdaten
There is no output to Domoticz.. The path to dzVents.lua seems to be not correct
Any suggestions?
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

@PieterS

from what I see in your log dzVents is working and also get a response from your sensor.
Can you add some extra domoticz.log("now at line xx") in your code and show us your results ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

Thanks waaren for quick reply!
Do not understand what you mean with "now at line xx" but have more info.
Seems there is some trouble.
2018-05-31 14:15:00.334 dzVents: Error (2.4.5): 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.
and:
Yes, there is no BME280 available.
2018-05-31 14:14:54.342 dzVents: Debug: - Device: Temperatuur garage
2018-05-31 14:15:00.041 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 14:15:00.053 dzVents: Debug: Event triggers:
2018-05-31 14:15:00.053 dzVents: Debug: - Timer
2018-05-31 14:15:00.072 dzVents: Info: ------ Start internal script: Luftdaten:, trigger: every minute
2018-05-31 14:15:00.072 dzVents: Debug: OpenURL: url = http://192.168.1.41/data.json
2018-05-31 14:15:00.072 dzVents: Debug: OpenURL: method = GET
2018-05-31 14:15:00.072 dzVents: Debug: OpenURL: post data = nil
2018-05-31 14:15:00.072 dzVents: Debug: OpenURL: headers = nil
2018-05-31 14:15:00.072 dzVents: Debug: OpenURL: callback = luftdatenRetrieved
2018-05-31 14:15:00.072 dzVents: Info: ------ Finished Luftdaten
2018-05-31 14:15:00.072 dzVents: Debug: Commands sent to Domoticz:
2018-05-31 14:15:00.073 dzVents: Debug: - OpenURL = {["method"]="GET", ["URL"]="http://192.168.1.41/data.json", ["_trigger"]="luftdatenRetrieved"}
2018-05-31 14:15:00.073 dzVents: Debug: =====================================================
2018-05-31 14:15:00.145 EventSystem: Script event triggered: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua
2018-05-31 14:15:00.148 EventSystem: Event triggered: Screen zijgevel omlaag_1
2018-05-31 14:15:00.237 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 14:15:00.249 dzVents: Debug: dzVents version: 2.4.5
2018-05-31 14:15:00.249 dzVents: Debug: Event triggers:
2018-05-31 14:15:00.249 dzVents: Debug: - HTTPResponse: luftdatenRetrieved
2018-05-31 14:15:00.323 dzVents: Info: Handling httpResponse-events for: "luftdatenRetrieved
2018-05-31 14:15:00.323 dzVents: Info: ------ Start internal script: Luftdaten: HTTPResponse: "luftdatenRetrieved"
2018-05-31 14:15:00.333 dzVents: Debug: Processing device-adapter for Luftdaten PM10: Air quality device
2018-05-31 14:15:00.334 dzVents: Error (2.4.5): 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.
2018-05-31 14:15:00.334 dzVents: Debug: Processing device-adapter for Luftdaten PM2.5: Air quality device
2018-05-31 14:15:00.334 dzVents: Error (2.4.5): Method updateCustomSensor is not available for device "Luftdaten PM2.5" (deviceType=Air Quality, deviceSubType=Voltcraft CO-20). If you believe this is not correct, please report.
2018-05-31 14:15:00.335 dzVents: Debug: Processing device-adapter for Luftdaten DHT22: Temperature device adapter
2018-05-31 14:15:00.335 dzVents: Error (2.4.5): Method updateTempHum is not available for device "Luftdaten DHT22" (deviceType=Temp, deviceSubType=LaCrosse TX3). If you believe this is not correct, please report.
2018-05-31 14:15:00.335 dzVents: Error (2.4.5): There is no device with that name or id: Luftdaten BME280
2018-05-31 14:15:00.335 dzVents: Error (2.4.5): An error occured when calling event handler Luftdaten
2018-05-31 14:15:00.335 dzVents: Error (2.4.5): ...ticz/var/scripts/dzVents/generated_scripts/Luftdaten.lua:25: attempt to index a nil value
2018-05-31 14:15:00.335 dzVents: Info: ------ Finished Luftdaten
2018-05-31 14:15:00.338 EventSystem: Event triggered: Buitenlamp poort aan_1
2018-05-31 14:15:00.338 EventSystem: Event triggered: Screen zijgevel omlaag_1
2018-05-31 14:15:00.338 EventSystem: Event triggered: Screen zijgevel omhoog_1
2018-05-31 14:15:00.345 (RFXcom) Lighting 1 (Buitenlamp poort)
2018-05-31 14:15:00.360 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 14:15:00.379 dzVents: Debug: Processing device-adapter for Buitenlamp poort: Switch device adapter
2018-05-31 14:15:00.380 dzVents: Debug: dzVents version: 2.4.5
And this is the code:

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
}
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

@PieterS

it seems that you defined different types of virtual sensors than the script expect. dzVents uses specific device-adapter code per deviceType
/ deviceSubType.

Look at the first post of this topic to see which deviceTypes must be defined.

If you copy / paste this code you can see that the json is handled by domoticz / dzVents. It only cannot update your virtual sensors because of th e unexpected types

Code: Select all

local FQDN = 'luftdaten.xxxx.xx'

return {
        active = true,
        on = {
                timer = { 'every minute' },
                httpResponses = { 'luftdatenRetrieved' } -- matches callback string below
        },
        
            logging =   {   level     =   domoticz.LOG_DEBUG,
                            marker    =   "luftdaten"    },        
        
        execute = function(dz, item)

            if (item.isTimer) then
                 dz.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
]]--
                        
                        dz.log("sensordatavalues[1].value: " .. item.json.sensordatavalues[1].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[2].value: " .. item.json.sensordatavalues[2].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[3].value: " .. item.json.sensordatavalues[3].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[4].value: " .. item.json.sensordatavalues[4].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[5].value: " .. item.json.sensordatavalues[5].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[6].value: " .. item.json.sensordatavalues[6].value, dz.LOG_DEBUG )
                        dz.log("sensordatavalues[7].value: " .. item.json.sensordatavalues[7].value, dz.LOG_DEBUG )
                        
--[[                    -- dz.devices('Luftdaten PM10').updateCustomSensor(item.json.sensordatavalues[1].value)
                        -- dz.devices('Luftdaten PM2.5').updateCustomSensor(item.json.sensordatavalues[2].value)
                        -- dz.devices('Luftdaten DHT22').updateTempHum(item.json.sensordatavalues[3].value,item.json.sensordatavalues[4].value,0)
                        -- dz.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
                    dz.log('Error fetching Luftdaten data', dz.LOG_ERROR)
                    dz.log(item.data, dz.LOG_ERROR)
                end
            end
        end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

@waaren: Thanks for your effort!
I am a bit suprised... I use in my sensor a SDS011 and DHT22. That is recommended at the site https://luftdaten.info . I suppose that svde made a typo
This is config
Image

This is output from my device:
Image

This are the names in Domoticz:

Image

Wondering about FQDN in line 1 of the lua-script.

Code: Select all

local FQDN = 'luftdaten.xxxx.xx'
I did not know what to fill in. Maybe that makes sense? Any idea?
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

Sent you a PM.

FQDN = Full Qualified Domain Name // Not needed here as you use an IP address of your sensor on your local network.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

@waaren:
I copy/pasted your code in a new script in Domoticz and saved that as Waaren.lua

After a short time it was executed and logged in Domoticz!
But not dumped in the file that is written in the log of Domoticz! Very strange because other events are clearly logged in the file with the same name and path. Only these entries about Luftdaten...

This is part of the Domoticz-log:
2018-05-31 17:44:00.312 dzVents: Debug: Event triggers:
2018-05-31 17:44:00.312 dzVents: Debug: - Timer
2018-05-31 17:44:00.331 dzVents: Info: ------ Start internal script: Luftdaten:, trigger: every minute
2018-05-31 17:44:00.331 dzVents: Debug: OpenURL: url = http://192.168.1.41/data.json
2018-05-31 17:44:00.331 dzVents: Debug: OpenURL: method = GET
2018-05-31 17:44:00.331 dzVents: Debug: OpenURL: post data = nil
2018-05-31 17:44:00.331 dzVents: Debug: OpenURL: headers = nil
2018-05-31 17:44:00.331 dzVents: Debug: OpenURL: callback = luftdatenRetrieved
2018-05-31 17:44:00.331 dzVents: Info: ------ Finished Luftdaten
2018-05-31 17:44:00.331 dzVents: Info: luftdaten: ------ Start internal script: Waaren:, trigger: every minute
2018-05-31 17:44:00.331 dzVents: Debug: luftdaten: OpenURL: url = http://192.168.1.41/data.json
2018-05-31 17:44:00.331 dzVents: Debug: luftdaten: OpenURL: method = GET
2018-05-31 17:44:00.331 dzVents: Debug: luftdaten: OpenURL: post data = nil
2018-05-31 17:44:00.332 dzVents: Debug: luftdaten: OpenURL: headers = nil
2018-05-31 17:44:00.332 dzVents: Debug: luftdaten: OpenURL: callback = luftdatenRetrieved
2018-05-31 17:44:00.332 dzVents: Info: luftdaten: ------ Finished Waaren
2018-05-31 17:44:00.332 dzVents: Debug: Commands sent to Domoticz:
2018-05-31 17:44:00.332 dzVents: Debug: - OpenURL = {["URL"]="http://192.168.1.41/data.json", ["_trigger"]="luftdatenRetrieved", ["method"]="GET"}
2018-05-31 17:44:00.332 dzVents: Debug: - OpenURL = {["URL"]="http://192.168.1.41/data.json", ["_trigger"]="luftdatenRetrieved", ["method"]="GET"}
2018-05-31 17:44:00.332 dzVents: Debug: =====================================================
2018-05-31 17:44:00.405 EventSystem: Script event triggered: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua
2018-05-31 17:44:00.454 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 17:44:00.466 dzVents: Debug: dzVents version: 2.4.5
2018-05-31 17:44:00.466 dzVents: Debug: Event triggers:
2018-05-31 17:44:00.466 dzVents: Debug: - HTTPResponse: luftdatenRetrieved
Below is the top of the logfile "domoticzData.lua". As you can see: timestamp of some sensors are very recent. But when I search in this file there is no entry of "luftdaten"...
-- Persistent Data
local multiRefObjects = {

} -- multiRefObjects
local obj1 = {
[1] = {
["baseType"] = "device";
["deviceType"] = "General";
["lastLevel"] = 0;
["description"] = "";
["subType"] = "Percentage";
["timedOut"] = false;
["lastUpdate"] = "2018-05-31 17:58:09";
["signalLevel"] = 12;
["rawData"] = {
[1] = "23.91";
};
["data"] = {
["hardwareType"] = "Motherboard sensors";
["_nValue"] = 0;
["icon"] = "hardware";
["unit"] = 1;
["hardwareID"] = 2;
["hardwareName"] = "Syno";
["protected"] = false;
["hardwareTypeValue"] = 23;
["_state"] = "23.91";
};
["id"] = 1;
["changed"] = false;
["switchTypeValue"] = 0;
["switchType"] = "On/Off";
["deviceID"] = "0000044C";
["batteryLevel"] = 255;
["name"] = "Geheugengebruik";
};
[2] = {
["baseType"] = "device";
["deviceType"] = "General";
["lastLevel"] = 0;
["description"] = "";
["subType"] = "Percentage";
["timedOut"] = false;
["lastUpdate"] = "2018-05-31 17:58:19";
["signalLevel"] = 12;
["rawData"] = {
[1] = "42.91";
};
I was reading the file mentioned in Domoticz-log, about the EventSystem: Script event triggered: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua

But I don't understand every line...
This is the code:

Code: Select all

local TESTMODE = false
globalvariables['testmode'] = false
--globalvariables['dzVents_log_level'] = 4 --debug

if (_G.TESTMODE) then
	TESTMODE = false
	globalvariables['testmode'] = false

end

local currentPath = globalvariables['script_path'] -- should be path/to/domoticz/scripts/dzVents

_G.scriptsFolderPath = currentPath .. 'scripts' -- global
_G.generatedScriptsFolderPath = currentPath .. 'generated_scripts' -- global
_G.dataFolderPath = currentPath .. 'data' -- global

package.path = package.path .. ';' .. currentPath .. '?.lua'
package.path = package.path .. ';' .. currentPath .. '../../dzVents/runtime/?.lua'
package.path = package.path .. ';' .. currentPath .. '../../dzVents/runtime/device-adapters/?.lua'
package.path = package.path .. ';' .. currentPath .. 'dzVents/?.lua'
package.path = package.path .. ';' .. currentPath .. 'scripts/?.lua'
package.path = package.path .. ';' .. currentPath .. '../lua/?.lua'
package.path = package.path .. ';' .. currentPath .. 'scripts/modules/?.lua'
package.path = package.path .. ';' .. currentPath .. 'generated_scripts/?.lua'
package.path = package.path .. ';' .. currentPath .. 'data/?.lua'
package.path = package.path .. ';' .. currentPath .. 'modules/?.lua'

local EventHelpers = require('EventHelpers')
local helpers = EventHelpers()
local utils = require('Utils')


if (tonumber(globalvariables['dzVents_log_level']) == utils.LOG_DEBUG or TESTMODE) then
	print('Debug: Dumping domoticz data to ' .. currentPath .. 'domoticzData.lua')
	local persistence = require('persistence')
	persistence.store(currentPath .. 'domoticzData.lua', domoticzData)

	local events, length = helpers.getEventSummary()
	if (length > 0) then
		print('Debug: dzVents version: 2.4.5')

		print('Debug: Event triggers:')
		for i, event in pairs(events) do
			print('Debug: ' .. event)
		end
	end

	if (globalvariables['isTimeEvent']) then
		print('Debug: Event triggers:')
		print('Debug: - Timer')
	end

end

commandArray = {}

local isTimeEvent = globalvariables['isTimeEvent']

if (isTimeEvent) then
	commandArray = helpers.dispatchTimerEventsToScripts()
end

helpers.dispatchDeviceEventsToScripts()
helpers.dispatchVariableEventsToScripts()
helpers.dispatchSecurityEventsToScripts()
helpers.dispatchSceneGroupEventsToScripts()
helpers.dispatchHTTPResponseEventsToScripts()
commandArray = helpers.domoticz.commandArray

return commandArray
Maybe an error in the local currentPath or globalvariables :?
Or error with permissions on filerights?
Synology with Domoticz build (V2024.7) in Docker
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Luftdaten

Post by waaren »

You need to be a bit patiënt and wait a couple of seconds until the script is triggered a second time by the return of the http call.
That's the async nature of these type of scripts. That part will also produce the interresting part of the logging.

Verstuurd vanaf mijn ONEPLUS A3003 met Tapatalk

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

waaren wrote: Thursday 31 May 2018 17:11 Sent you a PM.

FQDN = Full Qualified Domain Name // Not needed here as you use an IP address of your sensor on your local network.
Up till now no PM in my Inbox. :?
Synology with Domoticz build (V2024.7) in Docker
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

@waaren:
Made some progress; the results of your script in my Domoticz log:
2018-05-31 22:47:00.453 dzVents: Info: ------ Start internal script: Luftdaten:, trigger: every minute
2018-05-31 22:47:00.453 dzVents: Debug: OpenURL: url = http://192.168.1.41/data.json
2018-05-31 22:47:00.453 dzVents: Debug: OpenURL: method = GET
2018-05-31 22:47:00.453 dzVents: Debug: OpenURL: post data = nil
2018-05-31 22:47:00.453 dzVents: Debug: OpenURL: headers = nil
2018-05-31 22:47:00.453 dzVents: Debug: OpenURL: callback = luftdatenRetrieved
2018-05-31 22:47:00.453 dzVents: Info: ------ Finished Luftdaten
2018-05-31 22:47:00.453 dzVents: Info: luftdaten: ------ Start internal script: Waaren:, trigger: every minute
2018-05-31 22:47:00.453 dzVents: Debug: luftdaten: OpenURL: url = http://192.168.1.41/data.json
2018-05-31 22:47:00.453 dzVents: Debug: luftdaten: OpenURL: method = GET
2018-05-31 22:47:00.453 dzVents: Debug: luftdaten: OpenURL: post data = nil
2018-05-31 22:47:00.453 dzVents: Debug: luftdaten: OpenURL: headers = nil
2018-05-31 22:47:00.453 dzVents: Debug: luftdaten: OpenURL: callback = luftdatenRetrieved
2018-05-31 22:47:00.453 dzVents: Info: luftdaten: ------ Finished Waaren
2018-05-31 22:47:00.453 dzVents: Debug: Commands sent to Domoticz:
2018-05-31 22:47:00.453 dzVents: Debug: - OpenURL = {["_trigger"]="luftdatenRetrieved", ["URL"]="http://192.168.1.41/data.json", ["method"]="GET"}
2018-05-31 22:47:00.454 dzVents: Debug: - OpenURL = {["_trigger"]="luftdatenRetrieved", ["URL"]="http://192.168.1.41/data.json", ["method"]="GET"}
2018-05-31 22:47:00.454 dzVents: Debug: =====================================================
2018-05-31 22:47:00.527 EventSystem: Script event triggered: /usr/local/domoticz/var/dzVents/runtime/dzVents.lua
2018-05-31 22:47:00.617 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 22:47:00.628 dzVents: Debug: dzVents version: 2.4.5
2018-05-31 22:47:00.628 dzVents: Debug: Event triggers:
2018-05-31 22:47:00.628 dzVents: Debug: - HTTPResponse: luftdatenRetrieved
2018-05-31 22:47:00.702 dzVents: Info: Handling httpResponse-events for: "luftdatenRetrieved
2018-05-31 22:47:00.702 dzVents: Info: ------ Start internal script: Luftdaten: HTTPResponse: "luftdatenRetrieved"
2018-05-31 22:47:00.713 dzVents: Debug: Processing device-adapter for Luftdaten PM10: Air quality device
2018-05-31 22:47:00.713 dzVents: Error (2.4.5): 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.
2018-05-31 22:47:00.713 dzVents: Debug: Processing device-adapter for Luftdaten PM2.5: Air quality device
2018-05-31 22:47:00.713 dzVents: Error (2.4.5): Method updateCustomSensor is not available for device "Luftdaten PM2.5" (deviceType=Air Quality, deviceSubType=Voltcraft CO-20). If you believe this is not correct, please report.
2018-05-31 22:47:00.714 dzVents: Debug: Processing device-adapter for Luftdaten DHT22: Temperature device adapter
2018-05-31 22:47:00.714 dzVents: Error (2.4.5): Method updateTempHum is not available for device "Luftdaten DHT22" (deviceType=Temp, deviceSubType=LaCrosse TX3). If you believe this is not correct, please report.
2018-05-31 22:47:00.714 dzVents: Info: ------ Finished Luftdaten
2018-05-31 22:47:00.714 dzVents: Info: luftdaten: ------ Start internal script: Waaren: HTTPResponse: "luftdatenRetrieved"
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[1].value: 56.70
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[2].value: 48.83
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[3].value: 20.90
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[4].value: 99.90
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[5].value: 578996
2018-05-31 22:47:00.714 dzVents: Debug: luftdaten: sensordatavalues[6].value: 244
2018-05-31 22:47:00.715 dzVents: Debug: luftdaten: sensordatavalues[7].value: 26578
2018-05-31 22:47:00.715 dzVents: Info: luftdaten: ------ Finished Waaren
2018-05-31 22:47:00.732 dzVents: Debug: Dumping domoticz data to /usr/local/domoticz/var/scripts/dzVents/domoticzData.lua
2018-05-31 22:47:00.743 dzVents: Debug: dzVents version: 2.4.5
2018-05-31 22:47:00.743 dzVents: Debug: Event triggers:
2018-05-31 22:47:00.743 dzVents: Debug: - HTTPResponse: luftdatenRetrieved
2018-05-31 22:47:00.817 dzVents: Info: Handling httpResponse-events for: "luftdatenRetrieved
2018-05-31 22:47:00.817 dzVents: Info: ------ Start internal script: Luftdaten: HTTPResponse: "luftdatenRetrieved"
2018-05-31 22:47:00.828 dzVents: Debug: Processing device-adapter for Luftdaten PM10: Air quality device
2018-05-31 22:47:00.828 dzVents: Error (2.4.5): 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.
2018-05-31 22:47:00.828 dzVents: Debug: Processing device-adapter for Luftdaten PM2.5: Air quality device
2018-05-31 22:47:00.828 dzVents: Error (2.4.5): Method updateCustomSensor is not available for device "Luftdaten PM2.5" (deviceType=Air Quality, deviceSubType=Voltcraft CO-20). If you believe this is not correct, please report.
2018-05-31 22:47:00.829 dzVents: Debug: Processing device-adapter for Luftdaten DHT22: Temperature device adapter
2018-05-31 22:47:00.829 dzVents: Error (2.4.5): Method updateTempHum is not available for device "Luftdaten DHT22" (deviceType=Temp, deviceSubType=LaCrosse TX3). If you believe this is not correct, please report.
2018-05-31 22:47:00.829 dzVents: Info: ------ Finished Luftdaten
2018-05-31 22:47:00.829 dzVents: Info: luftdaten: ------ Start internal script: Waaren: HTTPResponse: "luftdatenRetrieved"
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[1].value: 56.70
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[2].value: 48.83
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[3].value: 20.90
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[4].value: 99.90
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[5].value: 578996
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[6].value: 244
2018-05-31 22:47:00.829 dzVents: Debug: luftdaten: sensordatavalues[7].value: 26578
2018-05-31 22:47:00.829 dzVents: Info: luftdaten: ------ Finished Waaren
Yes, sensor is read.
But how to act with the error? Where to report
Synology with Domoticz build (V2024.7) in Docker
svde
Posts: 28
Joined: Sunday 17 April 2016 10:36
Target OS: Linux
Domoticz version:
Contact:

Re: Luftdaten

Post by svde »

Code: Select all

2018-05-31 22:47:00.713 dzVents: Error (2.4.5): 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.
You've configured the incorrect device type. It needs to be a custom device type.
PieterS
Posts: 196
Joined: Wednesday 31 May 2017 16:06
Target OS: NAS (Synology & others)
Domoticz version: 2024.7
Location: NL
Contact:

Re: Luftdaten

Post by PieterS »

YES! Your suggestion made the difference! Sorry about my bad reading...

Only one small point: The name in your first post when you declare a virtual dummy device in Domoticz has to start with: Luftdaten...
So name is Luftdaten PM10, Luftdaten PM2.5 and Luftdaten DHT22

Thanks a lot. Solved another problem and learned a bit about reading info and the script.. :oops:

Image
Synology with Domoticz build (V2024.7) in Docker
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest