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

Moderator: leecollings

Dave21w
Posts: 369
Joined: Sunday 29 November 2015 21:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: UK
Contact:

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

Post 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
willemd
Posts: 628
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

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

Post 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().
User avatar
waltervl
Posts: 5362
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

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

Post 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
}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by hemant5400z »

thanx!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest