Prevent loop with screen
Posted: Sunday 30 April 2017 11:03
Guys,
Being a rather newbie to Domoticz/LUA I am risking being flamed with RTFM but I have searched but still not find a simple answer...
I have a screen (blind) that I would like to automate. However, the screen does not stop by itself - there is no brake/block on it.
So I need to activate the 'On' switch to start closing the screen and then after 30 seconds I need to switch 'On' again and it will stop.
Now I tried with simple LUA script script_device_screen.lua (with time set to 5 seconds for testing) but this ends in an infinite loop where the screen starts closing, then after 5 seconds it stops (fine!). However, after yet another 5 seconds it starts further closing again and 5 seconds later it stops again... and so on and so on. It obviously keeps generating events which is logical now...
The initial state of the screen is 'Open'.
When I push the 'On' switch the state will change to 'Closed'.
However, when I push the 'On' switch again after 30 seconds the state will remain 'Closed'.
So simple testing if the state changed to 'Closed' is not enough and will result in looping.
I assume I need to test and compare to the previous state the screen was in so I only need to send 'On' again when it changed from 'Open' to 'Closed', not when it 'changed' from 'Closed' to 'Closed'...
Reading to some of the posts it looks to me I need to use uservariables to keep the old state but I am not sure if there are even simpler solutions that I might be missing here...
I am assuming this is a common pattern and I am looking for some guidance/example here.
Thanks, Rene.
Being a rather newbie to Domoticz/LUA I am risking being flamed with RTFM but I have searched but still not find a simple answer...
I have a screen (blind) that I would like to automate. However, the screen does not stop by itself - there is no brake/block on it.
So I need to activate the 'On' switch to start closing the screen and then after 30 seconds I need to switch 'On' again and it will stop.
Now I tried with simple LUA script script_device_screen.lua (with time set to 5 seconds for testing) but this ends in an infinite loop where the screen starts closing, then after 5 seconds it stops (fine!). However, after yet another 5 seconds it starts further closing again and 5 seconds later it stops again... and so on and so on. It obviously keeps generating events which is logical now...
The initial state of the screen is 'Open'.
When I push the 'On' switch the state will change to 'Closed'.
However, when I push the 'On' switch again after 30 seconds the state will remain 'Closed'.
So simple testing if the state changed to 'Closed' is not enough and will result in looping.
I assume I need to test and compare to the previous state the screen was in so I only need to send 'On' again when it changed from 'Open' to 'Closed', not when it 'changed' from 'Closed' to 'Closed'...
Reading to some of the posts it looks to me I need to use uservariables to keep the old state but I am not sure if there are even simpler solutions that I might be missing here...
I am assuming this is a common pattern and I am looking for some guidance/example here.
Thanks, Rene.