swith on/off with cycling
Moderator: leecollings
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
swith on/off with cycling
Hi, i have a dummy switch (on/off) named “circulation pump” and I need:
from 6:01 to 23:59 and from 00:00 to 1:30 to switch it ON for 10min then turn OFF for 30min, again ON for 10min, again OFF for 30min and so on…
during others hours in the day ( from 1:31 to 6:00) always OFF
During the weekend (Saturday and Sunday) same cycle activation but:
totally OFF from 1:31 to 9:00
and cycling on/off from 9:01 to 23:59 and from 00:00 to 1:30
how I can do this?
Thanks so much
from 6:01 to 23:59 and from 00:00 to 1:30 to switch it ON for 10min then turn OFF for 30min, again ON for 10min, again OFF for 30min and so on…
during others hours in the day ( from 1:31 to 6:00) always OFF
During the weekend (Saturday and Sunday) same cycle activation but:
totally OFF from 1:31 to 9:00
and cycling on/off from 9:01 to 23:59 and from 00:00 to 1:30
how I can do this?
Thanks so much
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
Using dzVents:megamarco83 wrote: ↑Friday 21 September 2018 16:17 Hi, i have a dummy switch (on/off) named “circulation pump” and I need:
from 6:01 to 23:59 and from 00:00 to 1:30 to switch it ON for 10min then turn OFF for 30min, again ON for 10min, again OFF for 30min and so on…
during others hours in the day ( from 1:31 to 6:00) always OFF
During the weekend (Saturday and Sunday) same cycle activation but:
totally OFF from 1:31 to 9:00
and cycling on/off from 9:01 to 23:59 and from 00:00 to 1:30
how I can do this?
Thanks so much
Code: Select all
--cycle circulation pump
return {
on = { timer = { "every 10 minutes at 06:00-01:30 on mon,tue,wed,thu,fri",
"every 10 minutes at 09:00-01:30 on sat,sun",
"at 01:31" }},
-- logging = { level = domoticz.LOG_DEBUG,
-- marker = "cycling" },
execute = function(dz,trigger)
local pump = dz.devices("circulation pump")
dz.log("Trigger: ".. trigger.trigger,dz.LOG_DEBUG)
if dz.time.matchesRule("at 01:3*") then
pump.switchOff().checkFirst()
return -- Stops execution of this script
end
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 28 then
pump.switchOn()
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
thanks so mutch for helping first of all!
i'm not so confident with dzvents, it's the first time for me (i just read the wiki)
could you help me commenting your code?
why you put:
and:
what is 01:3* ?
and why you put: what's 28?
anyway i rite it, just to test:
i put 21:16 otherwise the script not started (the current time was 21:15 when i save it, and at 21:16 the script started on cycling) but... if there was written 01:31 the script should put the pump off !
(VCM_Sonoff is the name that i substiture tu circulation pump creating a dummy switch just to test, and i decrease the on/off timer to test quickly)
this is the log of VCM_Sonoff:
2018-09-21 21:27:01 Off
2018-09-21 21:26:00 On
2018-09-21 21:23:00 Off
2018-09-21 21:22:00 On
2018-09-21 21:19:00 Off
2018-09-21 21:18:00 On
As you can see it stats to cycling after 21:16 (that i put in the script...why? if it was written 1:31 they should always off untill 6:00)
thanks
i'm not so confident with dzvents, it's the first time for me (i just read the wiki)
could you help me commenting your code?
why you put:
Code: Select all
"at 01:31"
Code: Select all
if dz.time.matchesRule("at 01:3*") then
and why you put:
Code: Select all
elseif pump.lastUpdate.minutesAgo > 28 then
anyway i rite it, just to test:
Code: Select all
--cycle circulation pump
return {
on = { timer = { "every 1 minutes at 06:00-01:30 on mon,tue,wed,thu,fri",
"every 1 minutes at 09:00-01:30 on sat,sun",
"at 21:16" }},
-- logging = { level = domoticz.LOG_DEBUG,
-- marker = "cycling" },
execute = function(dz,trigger)
local pump = dz.devices("VCM_Sonoff")
dz.log("Trigger: ".. trigger.trigger,dz.LOG_DEBUG)
if dz.time.matchesRule("at 21:1*") then
pump.switchOff().checkFirst()
return -- Stops execution of this script
end
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 2 then
pump.switchOn()
end
end
}
(VCM_Sonoff is the name that i substiture tu circulation pump creating a dummy switch just to test, and i decrease the on/off timer to test quickly)
this is the log of VCM_Sonoff:
2018-09-21 21:27:01 Off
2018-09-21 21:26:00 On
2018-09-21 21:23:00 Off
2018-09-21 21:22:00 On
2018-09-21 21:19:00 Off
2018-09-21 21:18:00 On
As you can see it stats to cycling after 21:16 (that i put in the script...why? if it was written 1:31 they should always off untill 6:00)
thanks
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
Please note that the on = timer section is evaluated as AND
So every 10 minutes at 06:00-01:30 on mon,tue,wed,thu,fri AND every 10 minutes at 09:00-01:30 on sat,sun AND at 01:31 (every day)
"at 01:31" this will start the script at 01:31 and in the script code the lines
Code: Select all
if dz.time.matchesRule("at 01:3*") then
pump.switchOff().checkFirst()
end
The code
Code: Select all
elseif pump.lastUpdate.minutesAgo > 28 then
pump.switchOn()
Hope this clarifies.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
ok thanks so much now is a little bit clear

i have modify the script just to learn (4min for ON during mon,tue,wed,thu,fri from 06:30-01:00 // 4min for ON during sat,sun from 09:00-01:30 // OFF time = 15min) :
Code: Select all
--cycle circulation pump
return {
on = { timer = { "every 4 minutes at 06:30-01:00 on mon,tue,wed,thu,fri", -- tempo di accensione e fasce
"every 4 minutes at 09:00-01:30 on sat,sun",
"at 01:01" }}, -- orario da cui deve spegnersi
-- logging = { level = domoticz.LOG_DEBUG,
-- marker = "cycling" },
execute = function(dz,trigger)
local pump = dz.devices("VCM_Sonoff")
dz.log("Trigger: ".. trigger.trigger,dz.LOG_DEBUG)
if dz.time.matchesRule("at 01:0*") then
pump.switchOff().checkFirst()
return -- Stops execution of this script
end
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 13 then -- fime for off
pump.switchOn()
end
end
}
Code: Select all
2018-09-22 01:28:00 On
2018-09-22 01:12:00 Off
2018-09-22 01:08:00 On
2018-09-22 00:52:01 Off
2018-09-22 00:48:01 On
2018-09-22 00:30:06 Off
2018-09-22 00:28:00 On
2018-09-22 00:12:00 Off
2018-09-22 00:08:00 On
2018-09-21 23:52:00 Off
2018-09-21 23:48:00 On
2018-09-21 23:32:00 Off
2018-09-21 23:28:00 On
if i modify the script like this:
Code: Select all
--cycle circulation pump
return {
on = { timer = { "every 4 minutes at 06:30-01:00 on mon,tue,wed,thu,fri", -- tempo di accensione e fasce
"every 4 minutes at 09:00-01:30 on sat,sun",
"at 01:01" }}, -- orario da cui deve spegnersi
-- logging = { level = domoticz.LOG_DEBUG,
-- marker = "cycling" },
execute = function(dz,trigger)
local pump = dz.devices("VCM_Sonoff")
dz.log("Trigger: ".. trigger.trigger,dz.LOG_DEBUG)
if dz.time.matchesRule("at 01:0* on mon,tue,wed,thu,fri") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on mon,tue,wed,thu,fri
end
if dz.time.matchesRule("at 01:3* on sat,sun") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on sat,sun
end
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 13 then -- time for OFF
pump.switchOn()
end
end
}
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
You get the picture

Good to see that you are not afraid to experiment. That's is the way to learn !
One small comment:
Code: Select all
if dz.time.matchesRule("at 01:0* on mon,tue,wed,thu,fri") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on mon,tue,wed,thu,fri
end
if dz.time.matchesRule("at 01:3* on sat,sun") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on sat,sun
end
Code: Select all
if dz.time.matchesRule("at 01:0* on mon,tue,wed,thu,fri") or dz.time.matchesRule("at 01:3* on sat,sun") then
pump.switchOff().checkFirst()
return -- Stops execution of this script at set stoptime
end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
another help, sorry...
if i would like to create a scenario that:
turn on the pump for 18min and turn on for 30min another switch (heater) how i can menage without being in conflict with the dzvents?
because i create the scenario, it works, but, when the script run (every 4min) it turn the pump off if it's on.
so i can "suspend" the script for a while (18min for the pump always on and for heater for 30min always on) when i need it ?
thanks
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
I would use a type string uservar to control the initial script for the circulation pump. Something like "suspendScriptActions" when you want to suspend the script set it to "true" and set it to "false" when the script need to execute in a standard way. This can be done manually or in a scriptanother help, sorry...
if i would like to create a scenario that:
turn on the pump for 18min and turn on for 30min another switch (heater) how i can menage without being in conflict with the dzvents?
because i create the scenario, it works, but, when the script run (every 4min) it turn the pump off if it's on.
so i can "suspend" the script for a while (18min for the pump always on and for heater for 30min always on) when i need it ?
thanks
Then add an extra if around the timed actions like
Code: Select all
if dz.variables("suspendScriptActions").value == "false" then
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 13 then -- time for OFF
pump.switchOn()
end
end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
waaren wrote: ↑Sunday 23 September 2018 21:38
I would use a type string uservar to control the initial script for the circulation pump. Something like "suspendScriptActions" when you want to suspend the script set it to "true" and set it to "false" when the script need to execute in a standard way. This can be done manually or in a script
Then add an extra if around the timed actions like
Code: Select all
if dz.variables("suspendScriptActions").value == "false" then if pump.state == "On" then pump.switchOff() elseif pump.lastUpdate.minutesAgo > 13 then -- time for OFF pump.switchOn() end end
ok that is a very good idea! thanks
but when i would like to put my user variable as "true" (so the if check in the dzvents doesn't match and i can turn on my pumps for the time that i want) i have to change the variable manully going to: settings->more options->user var
and then change the variable??
otherwise i put off the dzvents for a while and then i use the pump...it's quite the same from the point of view of "automatism"
i would like to create a scenario that when is acrive:
1)put the variable to true
2) put on the pump for 30min
3)set back the variable to false
but inside the scenario created on domoticz there aren't user variable, but only switches
how i can do this?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
megamarco83 wrote: ↑Monday 24 September 2018 2:17Assuming you mean a domoticz scene; What about ?waaren wrote: ↑Sunday 23 September 2018 21:38 ....
but when i would like to put my user variable as "true" (so the if check in the dzVents doesn't match and i can turn on my pumps for the time that i want) i have to change the variable manually going to: settings->more options->user var
and then change the variable??
i would like to create a scenario that when is active:
1)put the variable to true
2) put on the pump for 30 minutes
3)set back the variable to false
but inside the scenario created on domoticz there aren't user variable, but only switches
how i can do this?
- create dummy hardware (if you do not already have created already)
- create a virtual switch called "suspendScriptActions"
- add this switch to your scene and set it to "On" when you want to the suspend the execution of your dzVents code and vice versa
change the code snippet to:Code: Select all
[code]if dz.devices("suspendScriptActions").state == "Off" then if pump.state == "On" then pump.switchOff() elseif pump.lastUpdate.minutesAgo > 13 then -- time for OFF pump.switchOn() end end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
correct, but if create a scene with inside the dummy switch with delay on action = 600sec (10min)waaren wrote: ↑Monday 24 September 2018 7:28
Assuming you mean a domoticz scene; What about ?
- create dummy hardware (if you do not already have created already)
- create a virtual switch called "suspendScriptActions"
- add this switch to your scene and set it to "On" when you want to the suspend the execution of your dzVents code and vice versa
change the code snippet to:Code: Select all
[code]if dz.devices("suspendScriptActions").state == "Off" then if pump.state == "On" then pump.switchOff() elseif pump.lastUpdate.minutesAgo > 13 then -- time for OFF pump.switchOn() end end
when i press the scene -> the dummy switch goes on
but the dummy switch of pump not turn on because the dzvent script run only every 4minutes....so the pump will be on only when the script will run, correct?
that's my dzvent:
Code: Select all
--cycle circulation pump
return {
on = { timer = { "every 4 minutes at 06:30-01:00 on mon,tue,wed,thu,fri", -- tempo di accensione e fasce
"every 4 minutes at 09:00-01:30 on sat,sun",
"at 01:01" }}, -- orario da cui deve spegnersi
logging = { level = domoticz.LOG_DEBUG,
marker = "cycling" },
execute = function(dz,trigger)
local pump = dz.devices("VCM_Sonoff")
dz.log("Trigger: ".. trigger.trigger,dz.LOG_DEBUG)
if dz.time.matchesRule("at 01:0* on mon,tue,wed,thu,fri") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on mon,tue,wed,thu,fri
end
if dz.time.matchesRule("at 01:3* on sat,sun") then
pump.switchOff().checkFirst()
return -- Stops execution of this script on sat,sun
end
if dz.devices("sospendi_dzvent_pompa").state == "Off" then -- aggiunto controllo su dummy switch chiamato "sospendi_dzvent_pompa" se Off=cicla se On=stop
if pump.state == "On" then
pump.switchOff()
elseif pump.lastUpdate.minutesAgo > 13 then -- tempo di OFF = valore scritto +2 (esempio spento x 15min)
pump.switchOn()
end
end
end
}
ps. if i create a uservar as number
and i want to modify it using http command, what's the correct command?
for example:
user var name = test
user var type = number
text = 0
now using http command i would like to change the value to 1
how i can do?
thanks
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
This is more a question about code logic than Lua / dzVents. Should al be possible to do exactly what you intend with some additional if clauses and maybe trigger the dzVents script also on a device / scene / variables event like.megamarco83 wrote: ↑Monday 24 September 2018 13:08 correct, but if create a scene with inside the dummy switch with delay on action = 600sec (10min)
when i press the scene -> the dummy switch goes on
but the dummy switch of pump not turn on because the dzvent script run only every 4minutes....so the pump will be on only when the script will run, correct?
Code: Select all
on = { timer = { "every 10 minutes at 06:00-01:30 on mon,tue,wed,thu,fri",
"every 10 minutes at 09:00-01:30 on sat,sun",
"at 01:31" },
devices = { ... },
variables = { ... },
scenes = { ... },
},
ps. if i create a uservar as number and i want to modify it using http command, what's the correct command?
for example:
user var name = test
user var type = number
text = 0
now using http command i would like to change the value to 1
how i can do?
[/quote]
Please have a look at this page . You will find there that
http://DOMOTICZ_IP:DOMOTICZ_PORT/json.htm?type=command¶m=updateuservariable&vname=test&vtype=0&vvalue=0
Will update your integer type var "test" to 0
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 108
- Joined: Friday 21 September 2018 15:07
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: swith on/off with cycling
thanks!! it works!
last question...i do not find it: how i can change the status of a switch without triggering the switch?
example: i have a switch
idx=31
and it's status is = ON
now i want to put OFF but without triggering the switch, using a JSON command
is it possible?
how?
thanks
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: swith on/off with cycling
This was answered at this post and described on Domoticz API/JSON URL wikimegamarco83 wrote: ↑Tuesday 25 September 2018 18:44thanks!! it works!
last question...i do not find it: how i can change the status of a switch without triggering the switch?
example: i have a switch
idx=31
and it's status is = ON
now i want to put OFF but without triggering the switch, using a JSON command
is it possible?
how?
thanks
for your case it would translate to: http://DOMOTICZ_IP:DOMOTICZ_PORT/json.htm?type=command¶m=udevice&idx=31&nvalue=0
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 132
- Joined: Monday 07 August 2017 17:17
- Target OS: Linux
- Domoticz version: Latest β
- Location: Near London (Saaarf!)
- Contact:
Re: swith on/off with cycling
As a matter of interest if you want to change the status of a device without triggering the action of the device but also not trigger any script associated with that device you can use this will switch the device on.
This is mainly useful to update dummy devices, like thermostats for example without triggering an associated script.
Code: Select all
commandArray[#commandArray+1] = {['UpdateDevice'] = '<deviceIDX>|1|1'}
This is mainly useful to update dummy devices, like thermostats for example without triggering an associated script.
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Who is online
Users browsing this forum: No registered users and 1 guest