Page 1 of 1
feature request: SwitchOnifOff/SwitchOffifOn
Posted: Sunday 20 August 2017 12:06
by SweetPants
Hi,
Sometimes you only want to switch states if the switch has the opposite state, is this possible to implement?
like:
if (domoticz.devices('Camera Woonkamer').state == 'Off') then
domoticz.devices('Camera Woonkamer').switchOn()
end
When using 'timed' scripts, this prevents unnecessary triggering if switch already has the right state
Or is there another way to do this?
Regards, Harry
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Sunday 20 August 2017 14:45
by candrea77
Hi
SweetPants, you've read in my mind ... I'm searching in the forum for the same functinality!!!!!
Due to the fact that sometimes I I need to switch off a very amount of devices , and I don't want to fill the zwave queue with a lot of unnecessary command, I need to use this code :
Code: Select all
if domoticz.devices(DISPOSITIVO).state ~= 'Off' then domoticz.devices(DISPOSITIVO).switchOff();end
As you, I wonder if there is a function that send zwave On / Off commands only if they are needed!!!
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Sunday 20 August 2017 21:08
by dannybloe
How about
Perhaps read the doc?

Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Sunday 20 August 2017 21:14
by candrea77
I'm on mobile phone and can't read the docs right now.... but this function ( due to the naming convention) seems a fuction to turn switch on if is off and viceversa ( this night I promise to read the docs) .... I need a function that when you ask for turn a device off , before call zwave stack check if the device is already off ( and in that case do nothig).
Inviato dal mio SM-G920F utilizzando Tapatalk
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Sunday 20 August 2017 21:34
by dannybloe
Ah okay. Guess I didn't read it well myself
It's not that hard to add this I just want it to be elegant. Perhaps something like this:
Code: Select all
mywitch.switchOff().forMin(5).check()
Will only switch it off for 5 minutes when it is not already Off.
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Monday 21 August 2017 22:01
by SweetPants
Or just mywitch.switchOff().check() or a mix
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Monday 21 August 2017 22:28
by dannybloe
That's what I was saying actually.
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Monday 21 August 2017 22:36
by candrea77
I've tried to find out the documentation about the .check() instruction but I was not able to find it.
Also, I've tried to put this code in my dzVents script :
Code: Select all
domoticz.devices('DEVICE NAME').switchOn().check()
But it give me this error :
Code: Select all
Error: dzVents: Error: ...domoticz/scripts/dzVents/generated_scripts/AAA_CHECK.lua:32: attempt to call field 'check' (a nil value)
Can someone help me ?
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Tuesday 22 August 2017 7:26
by dannybloe
Dude.. it was only a suggestion for implementation

Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Tuesday 22 August 2017 13:36
by candrea77
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Thursday 07 September 2017 20:33
by wizzard72
Is it possible that dzVents checks the state of a device before it send a switchOn(), switchOff(), dimTo(), etc. command? Now I have to check the state of a device before I send a command.
Example:
Code: Select all
if (domoticz.devices("Switch A").state == "On" and domoticz.devices("Switch B").state == "On") then
-- Armed Home
if (domoticz.devices("Switch A").lastUpdate.minutesAgo <= 5) then
domoticz.devices("Security Panel").disarm()
else
domoticz.devices("Security Panel").armHome()
end
end
This script runs every minute. And every minute the Security Panel gets the command Armed Home.
It could be nice if dzVents checks the state, in this example, the Security Panel and if it has already has the state "Armed Home", it does nothing and if it has another state, it will send the command.
Is this possible?
Re: feature request: SwitchOnifOff/SwitchOffifOn
Posted: Thursday 09 November 2017 8:18
by candrea77
Maybe you want something like this :
Code: Select all
if domoticz.devices('Domoticz Security Panel').state == 'Armed Away' then
or
Code: Select all
if domoticz.devices('Domoticz Security Panel').state == 'Armed Home' then
It is ok ?