Page 1 of 1
basic lua script not working
Posted: Tuesday 23 August 2016 12:18
by easyherve
Hello,
I really need help to understand why my BASIC LUA script is not working well.
commandArray = {}
if (otherdevices['BTN_Test'] == Off) then
print('OFF')
end
if (otherdevices['BTN_Test'] == On) then
print('ON')
end
return commandArray
I see on the LOG that the 2 tests are true !!! not understandable !
Thank you in advance for your help.
Regards.
Re: basic lua script not working
Posted: Tuesday 23 August 2016 12:41
by DanM
You need ' round your 'On' and 'Off'
Re: basic lua script not working
Posted: Tuesday 23 August 2016 13:09
by easyherve
do you mean round(off) instead of off ?
If yes, I got an error message on the log "attempt to call global 'round' (a nil value)".
Re: basic lua script not working
Posted: Tuesday 23 August 2016 13:12
by DanM
Sorry.. I should have been clearer. I mean you need 'Off' instead of Off.
Any clearer?
Re: basic lua script not working
Posted: Tuesday 23 August 2016 13:15
by DanM
Code: Select all
commandArray = {}
if (otherdevices['BTN_Test'] == 'Off') then
print('OFF')
end
if (otherdevices['BTN_Test'] == 'On') then
print('ON')
end
return commandArray
Re: basic lua script not working
Posted: Tuesday 23 August 2016 14:34
by easyherve
Hum, now both test are false .. then nothing recorded into the log except LUA:script 1!
It makes me crazy because SW_Prise_Free is a real plug device (means a boolean data) !
it is exactly what I wrote :
Code: Select all
commandArray = {}
print('script 1')
if (otherdevices['SW_Prise_Free'] == 'Off') then
print('OFF')
end
if (otherdevices['SW_Prise_Free'] == 'On') then
print('ON')
end
return commandArray
Re: basic lua script not working
Posted: Tuesday 23 August 2016 14:42
by DanM
hmm, Im struggling to see what else is wrong (although Im sure someone else will spot it and I'll kick myself).
Just to be sure - this is a switch device? Its not a group or a scene?
EDIT: also try removing the brackets. I dont imagine this will be the cause, but you never know!
Code: Select all
commandArray = {}
print('script 1')
if otherdevices['SW_Prise_Free'] == 'Off' then
print('OFF')
end
if otherdevices['SW_Prise_Free'] == 'On' then
print('ON')
end
return commandArray
Re: basic lua script not working
Posted: Tuesday 23 August 2016 15:05
by easyherve
I just checked without bracket and got the same result.
It is a real switch device (everspring AN157) that works perfectly. Moreover, this device is not used into blocky or whatever, it is my "free" device.
By the way, I checked with a virtual switch and got the same result !
This is a script I program directly from EVENTS menu by choosing LUA option (means through the domoticz interface).
Re: basic lua script not working
Posted: Tuesday 23 August 2016 15:20
by Westcott
Check the reported state of the device in Events -> Show current states
Re: basic lua script not working
Posted: Tuesday 23 August 2016 15:28
by easyherve
Actually, state of the device is off :
Code: Select all
Idx Name Current state Last updated sValues
1 SW-Lampe-Salle Off 2016-08-22 21:59:29 99
2 SW-Prise-Free Off 2016-08-23 15:24:16 0
3 SW-Leds-Cuisine Off 2016-08-22 21:59:29 99
4 SW-Leds-Salon Off 2016-08-22 21:59:29 99
5 SW-Portail Off 2016-08-22 21:08:04 0
but when I switch on, it shows on in te current status but nothing change in the log.
Re: basic lua script not working
Posted: Tuesday 23 August 2016 16:13
by easyherve
I finally found the issue ! it can be consider like a bug !
Unfortunatly, all my devices are named with a dash to separate names like BTN-Test. And caracter dash into the function otherdevices['BTN-Test'] doesn't work !
so I renamed
BTN-Test by
BTN_Test and everything goes fine !
I am glad I found coz it starts to make me crazy

Thanks everybody !
Re: basic lua script not working
Posted: Tuesday 23 August 2016 18:09
by jmleglise
If this is proven, you should write this in the wiki.
Re: basic lua script not working
Posted: Tuesday 23 August 2016 19:19
by SweetPants
easyherve wrote:so I renamed BTN-Test by BTN_Test and everything goes fine !
You don't need to concatenate words to form a string using "_", you can also use 'BTN Test'
Re: basic lua script not working
Posted: Wednesday 24 August 2016 17:27
by easyherve
Sure, when you know it, it is not even a topic ! but I didn't know that dash was not working into device name !
Thanks anyway for the advice

Re: basic lua script not working
Posted: Thursday 25 August 2016 13:40
by niceandeasy
I have devices in use with a dash in their names and they are working properly. I'm also using them in LUA scripts in ./scripts/lua. So your statement is not valid.
My devices are dummies. Yours are ZWave devices.
So the notion that dashes are not working in device names might be valid for ZWave devices, maybe it's even valid for other kinds of devices. But it's not valid for devices in general.
Another possible cause for your dash issue can be the location of your LUA scripts. They can be kept in the database / GUI, same as Blocklys. My scripts are text files in the ./scripts/lua folder of Domoticz. So where do you keep your LUA scripts?
Re: basic lua script not working
Posted: Thursday 25 August 2016 16:55
by DanM
I think he mentioned that he was using the web interface to create the Lua, could be something in the way the web-gui works that means the - gets translated incorrectly (particularily as -- comments out LUA code) ? Ive also used dashes succesfully by creating lua files directly.