feature request: SwitchOnifOff/SwitchOffifOn  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
SweetPants

feature request: SwitchOnifOff/SwitchOffifOn

Post 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
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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!!!
Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn  [Solved]

Post by dannybloe »

How about

Code: Select all

mySwitch.toggleSwitch()
Perhaps read the doc? ;)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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

Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
SweetPants

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post by SweetPants »

Or just mywitch.switchOff().check() or a mix
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post by dannybloe »

That's what I was saying actually.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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 ?
Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post by dannybloe »

Dude.. it was only a suggestion for implementation :)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post by candrea77 »

dannybloe wrote: Tuesday 22 August 2017 7:26 Dude.. it was only a suggestion for implementation :)
Ops ..... as in sign .... Sorry for any spelling mistake, English is not my native language :lol: :lol: :lol: :lol: :lol: :lol:
Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
wizzard72
Posts: 116
Joined: Friday 20 December 2013 7:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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?
candrea77
Posts: 32
Joined: Saturday 25 February 2017 18:42
Target OS: Linux
Domoticz version: 2021.1
Location: Milano, Italy
Contact:

Re: feature request: SwitchOnifOff/SwitchOffifOn

Post 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 ?
Sorry for any spelling mistake, English is not my native language.

DomoticZ running on Ubuntu 20.04 LTS , dzVents Version: 3.1.7 , Python Version: 3.8.5
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest