basic lua script not working

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

basic lua script not working

Post 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.
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: basic lua script not working

Post by DanM »

You need ' round your 'On' and 'Off'
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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)".
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: basic lua script not working

Post by DanM »

Sorry.. I should have been clearer. I mean you need 'Off' instead of Off.

Any clearer?
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: basic lua script not working

Post 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

easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: basic lua script not working

Post 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
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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).
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: basic lua script not working

Post by Westcott »

Check the reported state of the device in Events -> Show current states
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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.
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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 !
jmleglise
Posts: 192
Joined: Monday 12 January 2015 23:27
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: FRANCE
Contact:

Re: basic lua script not working

Post by jmleglise »

If this is proven, you should write this in the wiki.
My script : https://github.com/jmleglise
RFXTRX433E: Blind Somfy RTS, Portal Somfy Evolvia, chacon IO, Oregon, PIR sensor PT2262
My Last project : Location de vacances a Ouistreham vue mer
KMTronic USB relay
Chinese Z-WAVE: Neo CoolCam
SweetPants

Re: basic lua script not working

Post 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'
easyherve
Posts: 8
Joined: Saturday 24 January 2015 13:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: France
Contact:

Re: basic lua script not working

Post 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 ;)
niceandeasy
Posts: 102
Joined: Thursday 28 January 2016 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: NL
Contact:

Re: basic lua script not working

Post 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?
DanM
Posts: 79
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: basic lua script not working

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest