Lua, Read data from device
Moderator: leecollings
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Lua, Read data from device
Maybe a stupid question but I don't get the temperature value read to use the number in a lue script.
the protocoll says "attempt to compare number with nil"
Edit Waltervl: Moved from mqttmapper topic as this is a Lua question.
if the command = tonumber(otherdevices['Lightsensor_Ost']) >= 107the protocoll says "attempt to compare number with nil"
Edit Waltervl: Moved from mqttmapper topic as this is a Lua question.
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
Would it be possible to get the full script (or at least lines around the command)?
As written, syntax seems to be strange...
As written, syntax seems to be strange...
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
For better explanation. The LUA script was used with a fibaro smart implant device. I got the values from 3 DS18B20 sensors. The system with Fibaro was not stable enough and lost from time to time the sensors. Luckily there is MqttMapper and the Shelly Plus with Addon is providing the data. After adding the device via MqttMapper to Domoticz I only changed the device name to the same names the Fibaro device had.
Here is line 29 of the script. "Lightsensor_Ost" is exactly the same name from Zwave and MqttMapper
if tonumber(otherdevices['Lightsensor_Ost']) >= 107 and tonumber(otherdevices['Wetter Clouds %']) < 41 and uservariables['Shutter_Loop_Ost'] == 0 and otherdevices['Solar_Timer_Ost'] == 'Off' and otherdevices['Sonnensensor_Ost An/Aus'] == 'On' then
commandArray['Solar_Timer_Ost'] = 'On'
commandArray['Variable:Shutter_Loop_Ost'] = '1'
print('Solar_Timer_Ost = AN')
protocoll error
Error: EventSystem: in script_shutter_sun.lua: [string "-- script_shutter_sun.lua ..."]:29: attempt to compare number with nil
Here is line 29 of the script. "Lightsensor_Ost" is exactly the same name from Zwave and MqttMapper
if tonumber(otherdevices['Lightsensor_Ost']) >= 107 and tonumber(otherdevices['Wetter Clouds %']) < 41 and uservariables['Shutter_Loop_Ost'] == 0 and otherdevices['Solar_Timer_Ost'] == 'Off' and otherdevices['Sonnensensor_Ost An/Aus'] == 'On' then
commandArray['Solar_Timer_Ost'] = 'On'
commandArray['Variable:Shutter_Loop_Ost'] = '1'
print('Solar_Timer_Ost = AN')
protocoll error
Error: EventSystem: in script_shutter_sun.lua: [string "-- script_shutter_sun.lua ..."]:29: attempt to compare number with nil
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
Could you insert this code just before line 29, in order to see which variable is nil?
Getting new error line, you'll be able to tell which is the first valiable set to nil.
Code: Select all
print(otherdevices['Lightsensor_Ost'])
print(otherdevices['Wetter Clouds %'])
print(uservariables['Shutter_Loop_Ost'])
print(otherdevices['Solar_Timer_Ost'])
print(otherdevices['Sonnensensor_Ost An/Aus'])
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
here we have the result
2024-08-13 17:20:00.278 Status: LUA: 0.00
2024-08-13 17:20:00.278 Status: LUA: 0
2024-08-13 17:20:00.278 Status: LUA: Off
2024-08-13 17:20:00.278 Status: LUA: On
seems to be the Lightsensor_Ost which generate the problem. No idea why
2024-08-13 17:20:00.278 Status: LUA: 0.00
2024-08-13 17:20:00.278 Status: LUA: 0
2024-08-13 17:20:00.278 Status: LUA: Off
2024-08-13 17:20:00.278 Status: LUA: On
seems to be the Lightsensor_Ost which generate the problem. No idea why
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
here we have the device list from MqttMapper
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
Strange...
What's Domoticz version? MqttMapper version? OS version?
Is it possible to get (part of) MqttMapper json configuration file, I'd like making test here.
What's Domoticz version? MqttMapper version? OS version?
Is it possible to get (part of) MqttMapper json configuration file, I'd like making test here.
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
And a stupid question: why making a light sensor (normally lux) as a temp one?
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
There are no stupid questions. The Sensor Module I am using is a tiny PCB Board with a lightsensor. The Output is simulating a Ds18B20. So the equivalent Lux value is a temperture. Lux value is calculated Ev=e(temp/10). But this is not the problem. Fibaro smart implant also could only handle DS18B20 temperature Sensors. There is no Lux Sensor on the market which messures up to 100000 lux
I am on Domoticz 2024.4 on a RPI 3 with Bullseye.
part of the Json file
"Lightsensors Ost":{
"topic": "Lightsensors/status/temperature:100",
"type": "80", "subtype":"5",
"mapping":{"item":"tC"}
Mqtt Explorer topic : Lightsensors/status/temperature:100
status = {"id": 100,"tC":85.1, "tF":185.1}
tC is the value in Celsius and tF in Fahrenheit
I am on Domoticz 2024.4 on a RPI 3 with Bullseye.
part of the Json file
"Lightsensors Ost":{
"topic": "Lightsensors/status/temperature:100",
"type": "80", "subtype":"5",
"mapping":{"item":"tC"}
Mqtt Explorer topic : Lightsensors/status/temperature:100
status = {"id": 100,"tC":85.1, "tF":185.1}
tC is the value in Celsius and tF in Fahrenheit
Last edited by thaui on Wednesday 14 August 2024 10:46, edited 1 time in total.
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Lua, Read data from device
Yes but in Domoticz you can just define it as a Lux sensor with MQTT mapper and send the correct value. So then it looks like a lux sensor in Domoticz instead of a temperature sensor which it is not.
Device Type: 246 Subtype: 1 Lux Illumination (sValue: "float")
Device Type: 246 Subtype: 1 Lux Illumination (sValue: "float")
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
@waltervl Temperature is fine for me. If I have 93°C I know thats 10200lx .
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Lua, Read data from device
I dont see a reason why Lua would not be able to read the "Lightsensor_Ost" value.
Are there multiple devices with this name "Lightsensor_Ost" ?
Are there multiple devices with this name "Lightsensor_Ost" ?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
Are you sure about topic content?thaui wrote: ↑Wednesday 14 August 2024 10:23 I am on Domoticz 2024.4 on a RPI 3 with Bullseye.
part of the Json file
"Lightsensors Ost":{
"topic": "Lightsensors/status/temperature:100",
"type": "80", "subtype":"5",
"mapping":{"item":"tC"}
Mqtt Explorer topic : Lightsensors/status/temperature:100
status = {"id": 100,"tC":85.1, "tF":185.1}
tC is the value in Celsius and tF in Fahrenheit
Code: Select all
status = {"id": 100,"tC":85.1, "tF":185.1}
To be seen as json, topic should be:
Code: Select all
{"status": {"id": 100,"tC":85.1, "tF":185.1}}
Unless payload content is only
Code: Select all
{"id": 100,"tC":85.1, "tF":185.1}
Using the following LUA script
Code: Select all
commandArray = {}
-- loop through all the changed devices
for deviceName,deviceValue in pairs(devicechanged) do
if (deviceName=='Test MQTT - Lightsensors Ost') then
print ("Device event fired on '"..deviceName.."', value '"..tostring(deviceValue).."', otherDevices '"..tostring(otherdevices['Test MQTT - Lightsensors Ost']).."'")
end
end
return commandArray
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
Many thanks for your continues work to find the problem. Sorry I was not clear on the topic content. Maybe the picture gives you the correct response.
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
I was imagining that, crossing with other parts of answer, but just wanted to be sure.
So, part to be taken in account is:
So, part to be taken in account is:
FlyingDomotic wrote: ↑Wednesday 14 August 2024 11:38 Unless payload content is onlyIn this case, with a 2024.7, on RPi 4 with Buster and MqttMapper 1.0.42, sending payload "{"id": 100,"tC":85.1, "tF":185.1}" to "Lightsensors/status/temperature:100" properly loads data into Domoticz.Code: Select all
{"id": 100,"tC":85.1, "tF":185.1}
Using the following LUA script... I got : So, if payload is just {"id": 100,"tC":85.1, "tF":185.1}, we have to found what are the differences between your configuration. If otherdevices is correctly spelled, check for exact device name match (including leading/trailing spaces).Code: Select all
commandArray = {} -- loop through all the changed devices for deviceName,deviceValue in pairs(devicechanged) do if (deviceName=='Test MQTT - Lightsensors Ost') then print ("Device event fired on '"..deviceName.."', value '"..tostring(deviceValue).."', otherDevices '"..tostring(otherdevices['Test MQTT - Lightsensors Ost']).."'") end end return commandArray
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
your test script will generate the follwing error. : EventSystem: in Test.lua: [string "commandArray = {} ..."]:4: bad argument #1 to 'pairs' (table expected, got nil)
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
Could you confirm you're using "simple" LUA, not dzVents? And if "simple" LUA, with "device" type?
I just cut and pasted code properly running in Domoticz to forum.
I just cut and pasted code properly running in Domoticz to forum.
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
I updated Domoticz to version 2024.7 and updated MQttMapper to the latest version like in your system. It's running well now. No idea what the reason was. Thanks for your help
-
- Posts: 303
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Lua, Read data from device
I made few changes last days and weeks, it was probably MqttMapper the faulty part
-
- Posts: 58
- Joined: Sunday 15 March 2015 19:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Hamburg
- Contact:
Re: Lua, Read data from device
Anyhow, great support from your side and a very helpfull tool. Without it it's difficult to get Shelly Mqtt data to Domoticz.
Who is online
Users browsing this forum: No registered users and 1 guest