Page 2 of 2

Re: How to set a device on for 5 minutes and then off for 5 minutes

Posted: Thursday 08 December 2022 17:33
by Dave21w
look at the topic I posted above, thats done in blockly and as soon as the virtual switch is off the toggled device switches off as well

Re: How to set a device on for 5 minutes and then off for 5 minutes

Posted: Thursday 08 December 2022 18:25
by willemd
hemant5400z wrote: Thursday 08 December 2022 14:54
waltervl wrote: Thursday 08 December 2022 14:23 Please post your working script else it will be difficult to advise.
return
{
on ={ timer = {'every 1 minutes',}
},

execute = function(dz,item)
if item.isTimer and dz.devices('Virtual').active then
dz.devices('Sonoff').toggleSwitch()
end
end
}



Above is working and toggles on/off, what I want is a failsafe so if Virtual is Off, while the Sonoff is still on (triggered), it should go Off, currently it stays on infinite.

So indeed need an Else statement with: if item.isTimer and dz.devices('Virtual').active-not-active then

Hemant
yes, the "else" part will be executed whenever item is not a timer (never happens in this script) or when the virtual device is inactive, or both.
By the way: I always find it much easier on the mind to use switchOn() and switchOff() instead of toggleSwitch().

Re: How to set a device on for 5 minutes and then off for 5 minutes

Posted: Thursday 08 December 2022 18:30
by waltervl
This will switch Sonoff on/off until switch Virtual is switched off. Then Sonoff will be switched off. The checkFirst is to prevent a switch log entry and other triggers every minute.

Code: Select all

{
on ={ timer = {'every 1 minutes',}
},

execute = function(dz,item)
  if dz.devices('Virtual').active then
       dz.devices('Sonoff').toggleSwitch()
    else
       dz.devices('Sonoff').switchOff().checkFirst()
  end
end
}

Re: How to set a device on for 5 minutes and then off for 5 minutes

Posted: Friday 16 December 2022 12:26
by hemant5400z
thanx!