How to set a device on for 5 minutes and then off for 5 minutes
Moderator: leecollings
-
- 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
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
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
-
- 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
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?
viewtopic.php?p=225141#p225141
Maybe that causes your problem?
-
- 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
Dive into dzvents.
Time spent studying dzvents is time well spent.
Time spent studying dzvents is time well spent.
Bugs bug me.
-
- 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
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
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
- 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
Use in dzvents something like
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 item.isTimer and domoticz.devices('your_Switch').active then
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
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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
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
-
- 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
item is not defined
try:
execute = function(dz,item)
try:
execute = function(dz,item)
-
- 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
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
{
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
-
- 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
You need to use either dz or domoticz, not a mix.
Try this:
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
}
-
- 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
Hi Willem,
I get:
lua:14: syntax error near 'end'
Hemant
I get:
lua:14: syntax error near 'end'
Hemant
-
- 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
Thanks,
I copied an pasted from diferents scripts, now have a working version, slightly different but does the trick.
Hemant
I copied an pasted from diferents scripts, now have a working version, slightly different but does the trick.
Hemant
-
- 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
The first thing to do when you get an error is look at the line indicated, in this case 14.hemant5400z wrote: ↑Thursday 08 December 2022 12:51 Hi Willem,
I get:
lua:14: syntax error near 'end'
Hemant
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?
-
- 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
Thanks Willemd,
That was indeed the issue, the toggleSwitch() did the trick and now it is working as it should.
Hemant
That was indeed the issue, the toggleSwitch() did the trick and now it is working as it should.
Hemant
- 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
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
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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
Let's say, i switch of the virtual device, while the triggered device was On, will it go off? Or stay on forever?
Hemant
- 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
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.
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
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
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
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
- 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
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
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- 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
I have this for DZ but don't have an external control switch as I don't need one
Or you could use blockly and look at this post
viewtopic.php?p=290984
Or you could use blockly and look at this post
viewtopic.php?p=290984
-
- 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
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
Who is online
Users browsing this forum: No registered users and 0 guests