Lua script not sensing state change
Posted: Wednesday 25 March 2020 16:11
Hi. First Lua script as functionality too complex for Blockly.
I'm running this on a Rasp Pi 4 under Buster and within a Docker container. Domoticz V4.10364 (c)2012-2019 GizMoCuz and Build Hash: 1cacdddf, Date: 2019-01-25 10:01:48. GPIO pins defined using sys/gpio exports.
The script is activated by push button (gpio6) going low (it is normally high). In the Switch definition the off state triggers this script (part shown).
The script needs to sense if the button is released (goes high) while the loop iterates for 10 seconds. The log (shown below) shows the code looping and shows the button going high but the script continues to loop. I tried lower case 'On' but no difference.
Log
My first version of the script was activated by the state change and the if statement in the first line being
but this behaved the same.
Is Lua meant to pickup on state changes happening while the script is running? Is there another way to note a state change? or is there a error in my code?
Help appreciated. Thanks for reading.
Alan
I'm running this on a Rasp Pi 4 under Buster and within a Docker container. Domoticz V4.10364 (c)2012-2019 GizMoCuz and Build Hash: 1cacdddf, Date: 2019-01-25 10:01:48. GPIO pins defined using sys/gpio exports.
The script is activated by push button (gpio6) going low (it is normally high). In the Switch definition the off state triggers this script (part shown).
The script needs to sense if the button is released (goes high) while the loop iterates for 10 seconds. The log (shown below) shows the code looping and shows the button going high but the script continues to loop. I tried lower case 'On' but no difference.
Code: Select all
if (otherdevices['ShutDownButton'] == 'Off') then
local pressed = 1
for i = 1, 10 do -- check button is held down for 10 secs
print('in loop')
print(otherdevices['ShutDownButton'])
if (otherdevices['ShutDownButton'] == 'On') then -- it's been released so quit
pressed = 0
print('break loop')
break
end
os.execute("sleep " .. tonumber(1))
end
if (pressed == 1) then
print('pressed is = 1')
shutDown('ShutDownLED', 10, 0.5) -- blink 10 times with 0.5sec gap
end
end
Code: Select all
2020-03-25 13:12:14.831 (Raspberry Pi 4 HMS) Lighting 2 (ShutDownButton)
2020-03-25 13:12:14.826 Status: Sysfs GPIO: gpio6 new state = off
2020-03-25 13:12:14.833 Status: LUA: in loop
2020-03-25 13:12:14.833 Status: LUA: Off
2020-03-25 13:12:15.309 (Raspberry Pi 4 HMS) Lighting 2 (ShutDownButton)
2020-03-25 13:12:15.304 Status: Sysfs GPIO: gpio6 new state = on
2020-03-25 13:12:15.847 Status: LUA: in loop
2020-03-25 13:12:15.847 Status: LUA: Off
2020-03-25 13:12:16.861 Status: LUA: in loop
2020-03-25 13:12:16.861 Status: LUA: Off
2020-03-25 13:12:17.875 Status: LUA: in loop
+ 6 more loops
Code: Select all
if (devicechanged['ShutDownButton'] == 'Off') then
Is Lua meant to pickup on state changes happening while the script is running? Is there another way to note a state change? or is there a error in my code?
Help appreciated. Thanks for reading.
Alan