new function powerCycle() maybe?

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

Moderator: leecollings

Post Reply
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

new function powerCycle() maybe?

Post by emme »

uhm...
I quite often have to switch off and back on a device or light for any reason...

now I'm wondering if it could be possible to include a new function in dzVents...

basically I was thinking a something like:

domoticz.devices('myDevice').powerCycle(<value in seconds>)
that perform:
domoticz.devices('myDevice').switchOff()
domoticz.devices('myDevice').switchOn().afterSec(<vale in seconds>)
or...
domoticz.devices('myDevice').switchOnOff(<value in seconds>)
and of course
domoticz.devices('myDevice').switchOffOn(<value in seconds>)

...what do you think? :P :P :P
The most dangerous phrase in any language is:
"We always done this way"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: new function powerCycle() maybe?

Post by waaren »

emme wrote: Friday 25 January 2019 17:25 I quite often have to switch off and back on a device or light for any reason...
now I'm wondering if it could be possible to include a new function in dzVents...
basically I was thinking a something like:
domoticz.devices('myDevice').powerCycle(<value in seconds>)
...what do you think? :P :P :P
I think it is a lot of work to implement as native dzVents command :D and easy to code in a script. :idea:

Code: Select all

local function powerCycle(device,delay)
  if device.state == "On" then 
     device.switchOff() device.switchOn().afterSec(delay)
  else
    device.switchOn() device.switchOff().afterSec(delay)
  end    
end    
an call the function with something like

Code: Select all

powerCycle(domoticz.devices("powerSwitch"),12) -- delay in seconds  
If you need to use it in multiple scripts, add to global_data.lua as a helper function

Code: Select all

-- global_data.lua 
 
return {
    
        data     =  {},

    helpers     =   {  
                        powerCycle = function(device,delay)
                            if device.state == "On" then 
                                device.switchOff() device.switchOn().afterSec(delay)
                            else
                                device.switchOn() device.switchOff().afterSec(delay)
                            end    
                        end,    
                    },
}
and call like

Code: Select all

domoticz.helpers.powerCycle(domoticz.devices("powerSwitch"),12) -- delay in seconds  
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
elmortero
Posts: 248
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: new function powerCycle() maybe?

Post by elmortero »

Or easier: make use of toggle switch() like
device.toggleSwitch()
device.toggleSwitch().afterSec(20)

That avoids the need of checking current state
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: new function powerCycle() maybe?

Post by emme »

uh... I think that I obviously I made a mess :P :P

there is already the .forSec() function... :(
so it would be: domoticz.device('mydevice').switchOff().forSec(10)
this should toggle off and back on after 10 secs :P :P :P
The most dangerous phrase in any language is:
"We always done this way"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: new function powerCycle() maybe?

Post by waaren »

elmortero wrote: Saturday 26 January 2019 0:41 Or easier: make use of toggle switch() like
device.toggleSwitch()
device.toggleSwitch().afterSec(20)

That avoids the need of checking current state
Try this and be amazed :D
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: new function powerCycle() maybe?

Post by waaren »

emme wrote: Saturday 26 January 2019 15:56 uh... I think that I obviously I made a mess :P :P

there is already the .forSec() function... :(
so it would be: domoticz.device('mydevice').switchOff().forSec(10)
this should toggle off and back on after 10 secs :P :P :P
Completely overlooked this one. :oops:
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest