Stop Lua script when switch is operated manually

Moderator: leecollings

Post Reply
jdbrouwer
Posts: 5
Joined: Tuesday 08 March 2016 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Stop Lua script when switch is operated manually

Post 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?
Last edited by jdbrouwer on Thursday 10 March 2016 13:41, edited 1 time in total.
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Stop Lua script when switch is operated manually

Post 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?
jdbrouwer
Posts: 5
Joined: Tuesday 08 March 2016 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Stop Lua script when switch is operated manually

Post 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.
tlpeter
Posts: 191
Joined: Wednesday 26 November 2014 18:43
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Stop Lua script when switch is operated manually

Post 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:
::end::

The goto command will skip everything between the goto command and the ::end::
Now you can manually switch whenever you want or automate it by turning the switch off so it follows the script.
jdbrouwer
Posts: 5
Joined: Tuesday 08 March 2016 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Stop Lua script when switch is operated manually

Post 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.)
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Stop Lua script when switch is operated manually

Post by jannl »

You can add a http json call to the on/of action of a switch and switch another switch like this.
jdbrouwer
Posts: 5
Joined: Tuesday 08 March 2016 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Stop Lua script when switch is operated manually

Post by jdbrouwer »

Won't this call be executed when the script changes the value of this same device?
jannl
Posts: 673
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Stop Lua script when switch is operated manually

Post 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)
jdbrouwer
Posts: 5
Joined: Tuesday 08 March 2016 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Stop Lua script when switch is operated manually

Post by jdbrouwer »

Thanks Jannl,

Using the lastupdated time, solved my issue!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest