Page 1 of 1
Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 11:04
by jdbrouwer
Being quite new to Domoticz, and a complete beginner in scripting, I run into a difficulty.
Is it possible to stop a script whenever one of the involved devices is used manually?
In order to distinguish a scripted and manual devicechange ,I tried by setting a uservariable 'Scripting' to On and Off. Whenever 'Scripting' is Off, this would indicate a manually operated device. This is done in a timed script, like this:
Code: Select all
if ((otherdevices['Presence'] == 'On' and otherdevices['SomethingElse'] == 'On') then
commandArray['Variable:Scripting'] = 'On'
SomeValue = 10
commandArray['Device'] = 'Set Level: '..SomeValue.. ' %'
commandArray['Variable:Scripting'] = 'Off'
end
Afterwards, the following script picks up the devicechanged, but the variable 'Scripting' is already set to 'Off' so it seems.
Code: Select all
if (devicechanged['Device'] and Scripting == 'Off')then
print('Device is used without scripting')
end
Long story short: How do I distinguish a button-press from a scripted device-change?
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 12:55
by jannl
commandArray is only executed at a return.
You suggestion will never work.
You could use different variables.
You better check the status of the device you want to operate before actually operating it.
Besides that, how do you plan to stop a script that only runs a few milliseconds?
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 13:17
by jdbrouwer
Could you explain what you mean with these different variables?
Of course, the code mentioned above is not the actual script. The idea is to let a script set dimmer values during half an hour (one setting per minute) before sunset till sunset.
When a button is pressed during this period, I would like to stop the script from running.
Well, stopping the script might not be the right definition. Preventing it from running suits better.
If a device is manually switched on/off, I would like to prevent the script from running anymore.
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 13:29
by tlpeter
Make a virtual switch and add that in to the lua script.
If ManaulOverride (name of the virtual switch) is "On" then
goto end
In the script add:
:

:
The goto command will skip everything between the goto command and the :

:
Now you can manually switch whenever you want or automate it by turning the switch off so it follows the script.
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 13:46
by jdbrouwer
I already have a virtual switch that makes the script run, or prevent it from running.
The only question is, how do I toggle this virtual switch using a button that is connected to one of the dimmers that is adjusted within the script?
In other terms, how do I see whether a script, or a button-press changed the state of a device?
(I just found out I mistyped something in my code. The second part of the code is triggered on the same device that is controlled in the first script.)
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 14:01
by jannl
You can add a http json call to the on/of action of a switch and switch another switch like this.
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 14:23
by jdbrouwer
Won't this call be executed when the script changes the value of this same device?
Re: Stop Lua script when switch is operated manually
Posted: Thursday 10 March 2016 14:28
by jannl
The idea is to switch a additional virtual switch which can be checked when the other script is running.
I think it would even be better to also check the lastupdated times of both switches (the actual and the virtual)
Re: Stop Lua script when switch is operated manually
Posted: Sunday 13 March 2016 12:16
by jdbrouwer
Thanks Jannl,
Using the lastupdated time, solved my issue!