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

Moderator: leecollings

hemant5400z
Posts: 80
Joined: Monday 05 November 2018 17:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by hemant5400z »

Hi,

I'm trying to make a blocky work based on a virtual switch.

If the virtual switch is on then
device x needs to on for 5 min
device x not to go off for 5 min

Until virtual switch is turned off.

I cannot make it work in blockly either device quickly goes on/off or stays off.
I tried to use on for 300 seconds
and also tried for 5 minutes

with both block If ..Do and using If then Else, is it even possible with Blockly?

Thanks, looking for some expertise.


Cheers,
Hemant
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 »

In blockly the else part is not only executed when the if condition is false (like in most programming languages) but is always executed sequentially after the if part has finished, so if you don't want that you have to add another if-condition to the else part.

viewtopic.php?p=225141#p225141

Maybe that causes your problem?
HvdW
Posts: 525
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

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

Post by HvdW »

Dive into dzvents.
Time spent studying dzvents is time well spent.
Bugs bug me.
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 »

Hi,

Yes working on dzevents to get this done my only issues is i want the trigger the event when mu virtual device is on then it should trigger the other device every 5 minutes.

I used device and timer but it fires de on off every 5 minutes or if virtual device changes state while i only want to do this when the virtual device state is on.

I think i need to get state of virtual device as a local read out and than if local is on do the timer every 5 min switch the target device. But not familiar that much with dzevents so looking for an example with a trigger on time only when a specific switch is set on.

Hemant
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 »

Use in dzvents something like

Code: Select all

if item.isTimer and domoticz.devices('your_Switch').active then
Edit:
If you have only timer trigger (every 5 minutes) in your script you can also only use the the .active check. Following will switch on/off (=toggle) the device your_light every 5 minutes.

Code: Select all

if domoticz.devices('your_Switch').active then
   domoticz.devices('your_light').toggle
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 »

Hi Thanks for the response.

I tried as a tes:

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

execute = function(dz)

if item.isTimer and domoticz.devices('Virtual').active then
domoticz.devices('Sonoff').toggle
end
end
}


But getting the following error:

/config/scripts/dzVents/generated_scripts/CV_regeling.lua:15: syntax error near 'end' which seems to be this part:
if item.isTimer and domoticz.devices('Virtual').active then
domoticz.devices('Sonoff').toggle
end

Getting the eact same error with:

if domoticz.devices('your_Switch').active then
domoticz.devices('your_light').toggle
end

Hemant
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 »

item is not defined
try:
execute = function(dz,item)
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 »

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

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


Still the same error
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 »

You need to use either dz or domoticz, not a mix.

Try this:

Code: Select all

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

execute = function(dz,item)
if item.isTimer and dz.devices('Virtual').active then
dz.devices('Sonoff').toggle
end
end
}
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 »

Hi Willem,

I get:

lua:14: syntax error near 'end'

Hemant
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 »

Thanks,

I copied an pasted from diferents scripts, now have a working version, slightly different but does the trick.

Hemant
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 12:51 Hi Willem,

I get:

lua:14: syntax error near 'end'

Hemant
The first thing to do when you get an error is look at the line indicated, in this case 14.
There is only "end" so probably it is the line before.
There it states dz.devices('Sonoff').toggle
And then you check documentation of dzvents and you find there is no "toggle", only "toggleSwitch()"

So what happens it you try that change?
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 »

Thanks Willemd,

That was indeed the issue, the toggleSwitch() did the trick and now it is working as it should.

Hemant
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 »

Ah, sorry for that toggle thing.... But glad it works.
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 »

One more question.

Let's say, i switch of the virtual device, while the triggered device was On, will it go off? Or stay on forever?

Hemant
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 »

With this script it will stay in the status it was in.
You can add else statement to the if then to switch off Sonoff when Virtual is Off.
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 »

Yes,

but not sure of what the counter part is of this line if item.isTimer and dz.devices('Virtual').active as it is a boolean.

dz.devices('Virtual').active.true vs dz.devices('Virtual').active.false?

Hemant
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 »

Please post your working script else it will be difficult to advise.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
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 »

I have this for DZ but don't have an external control switch as I don't need one
dz toggle.jpg
dz toggle.jpg (13.84 KiB) Viewed 2089 times
Or you could use blockly and look at this post

viewtopic.php?p=290984
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 »

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
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests