Page 1 of 1

new function powerCycle() maybe?

Posted: Friday 25 January 2019 17:25
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

Re: new function powerCycle() maybe?

Posted: Friday 25 January 2019 21:09
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  

Re: new function powerCycle() maybe?

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

That avoids the need of checking current state

Re: new function powerCycle() maybe?

Posted: Saturday 26 January 2019 15:56
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

Re: new function powerCycle() maybe?

Posted: Saturday 26 January 2019 16:27
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

Re: new function powerCycle() maybe?

Posted: Saturday 26 January 2019 16:29
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: