Need some help with basic LUA

Moderator: leecollings

Post Reply
tullgren
Posts: 4
Joined: Monday 13 June 2016 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Need some help with basic LUA

Post by tullgren »

Hi,

I'm trying to get started with LUA.
Grateful if anyone can help me in the right direction.

The script runs and lights the lamp when the temperature is above 20 degrees.
But I get an error message in the log. I suspect that 20 is a string value. But do not understand how to convert the value.

The script:

Code: Select all

commandArray = {}

if devicechanged['Sovrum_Temperature'] > 20 then
    commandArray['Skrivbord']='On'
end

return commandArray
Error message:
Error: EventSystem: in SovrumTermostat: [string "--..."]:7: attempt to compare number with nil

Best regards, Mikael
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Need some help with basic LUA

Post by cyberclwn »

I don't think the state of the device changes when it's data changes, when it is a thermo-device.

You better use it combined with a switch or other action. so you can use the "otherdevices"-array with data

Code: Select all

if ((tonumber(otherdevices_temperature['Thermo']) < tonumber(20) then
Maybe on the wiki is more information to help you further:
https://www.domoticz.com/wiki/Events
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
jannl
Posts: 666
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Need some help with basic LUA

Post by jannl »

Or use a time based script
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Need some help with basic LUA

Post by georgesattali »

Hello,
I think that the Sovrum is a Thermostat (is that true ?), therefore 'Sovrum_Temperature' does not exists and is valued to nil.
When you compare nil > 20 you get the message "attempt to compare number with nil".
Adding tonumber(xxx), although correct in principle, is useless (and ugly from my point of view), Lua perfectly understands you want to compare numbers.
I don't how to get rid of this nil. some more research needed...
See U, GD.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Need some help with basic LUA

Post by dannybloe »

I'd suggest to look at dzVents. It makes Lua scripting for Domoticz almost trivial. No more juggling with all those tables.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
jjdom
Posts: 12
Joined: Tuesday 26 July 2016 13:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: France
Contact:

Re: Need some help with basic LUA

Post by jjdom »

hello,

I don't speak english very well, so I'am not sure to understand what you realy whant to do.
But if the problem is only du Nil value, why don't make like this:

Code: Select all

commandArray = {}

if devicechanged['Sovrum_Temperature'] ~= nil and
   devicechanged['Sovrum_Temperature'] > 20 then
    commandArray['Skrivbord']='On'
end

return commandArray
José
Domoticz raspberry pi
Version 3.4834
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest