Page 1 of 1

swith on/off with cycling

Posted: Friday 21 September 2018 16:17
by megamarco83
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

Re: swith on/off with cycling

Posted: Friday 21 September 2018 19:37
by waaren
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
Using dzVents:

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
}

Re: swith on/off with cycling

Posted: Friday 21 September 2018 21:30
by megamarco83
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:

Code: Select all

"at 01:31" 
and:

Code: Select all

 if  dz.time.matchesRule("at 01:3*") then
what is 01:3* ?
and why you put:

Code: Select all

elseif pump.lastUpdate.minutesAgo > 28 then
what's 28?

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
}
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

Re: swith on/off with cycling

Posted: Friday 21 September 2018 22:20
by waaren
megamarco83 wrote: Friday 21 September 2018 21:30 could you help me commenting your code?
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
will cause the pump to switch off at 01:30 - 01:39 when on. Because script will only start again at 06:00 or 09:00, the pump will stay off until that time. I use the wildcarded time to stay on the safe side.
The code

Code: Select all

elseif pump.lastUpdate.minutesAgo > 28 then
            pump.switchOn()
will cause the pump to switch on when the script will be triggered for the third time after the pump was switched on (3* 10 minutes) 28 is used to stay on the safe side.

Hope this clarifies.

Re: swith on/off with cycling

Posted: Saturday 22 September 2018 8:36
by megamarco83
waaren wrote: Friday 21 September 2018 22:20 Hope this clarifies.
ok thanks so much now is a little bit clear :D
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
}
but if i look at the log:

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
the pump was on at 01:28:00 and is still on now (now is 8:30 in the morning) and i guess it still on till 9:00 when the script will run again (it's saturday today) right?

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
}

Re: swith on/off with cycling

Posted: Saturday 22 September 2018 9:19
by waaren
megamarco83 wrote: Saturday 22 September 2018 8:36
waaren wrote: Friday 21 September 2018 22:20 Hope this clarifies.
ok thanks so much now is a little bit clear :D
You get the picture :D
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
Can be coded shorter and without duplicated lines as

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

Re: swith on/off with cycling

Posted: Saturday 22 September 2018 21:36
by megamarco83
waaren wrote: Saturday 22 September 2018 9:19
You get the picture :D
Good to see that you are not afraid to experiment. That's is the way to learn !
thanks for your support and help!
anyway ....now i'm getting crazy crazy crazy cray with controlling blinds :(

Re: swith on/off with cycling

Posted: Sunday 23 September 2018 15:46
by megamarco83
waaren wrote: Friday 21 September 2018 22:20 Good to see that you are not afraid to experiment. That's is the way to learn !
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

Re: swith on/off with cycling

Posted: Sunday 23 September 2018 21:38
by waaren
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
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

Re: swith on/off with cycling

Posted: Monday 24 September 2018 2:17
by megamarco83
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?

Re: swith on/off with cycling

Posted: Monday 24 September 2018 7:28
by waaren
megamarco83 wrote: Monday 24 September 2018 2:17
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?
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

Re: swith on/off with cycling

Posted: Monday 24 September 2018 13:08
by megamarco83
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
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?

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

Re: swith on/off with cycling

Posted: Tuesday 25 September 2018 1:13
by waaren
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?
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.

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 = { ... },
   },
[/quote]
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&param=updateuservariable&vname=test&vtype=0&vvalue=0
Will update your integer type var "test" to 0

Re: swith on/off with cycling

Posted: Tuesday 25 September 2018 18:44
by megamarco83
waaren wrote: Tuesday 25 September 2018 1:13 Please have a look at this page . You will find there that
http://DOMOTICZ_IP:DOMOTICZ_PORT/json.htm?type=command&param=updateuservariable&vname=test&vtype=0&vvalue=0
Will update your integer type var "test" to 0
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

Re: swith on/off with cycling

Posted: Tuesday 25 September 2018 19:45
by waaren
megamarco83 wrote: Tuesday 25 September 2018 18:44
waaren wrote: Tuesday 25 September 2018 1:13 Please have a look at this page . You will find there that
http://DOMOTICZ_IP:DOMOTICZ_PORT/json.htm?type=command&param=updateuservariable&vname=test&vtype=0&vvalue=0
Will update your integer type var "test" to 0
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
This was answered at this post and described on Domoticz API/JSON URL wiki
for your case it would translate to: http://DOMOTICZ_IP:DOMOTICZ_PORT/json.htm?type=command&param=udevice&idx=31&nvalue=0

Re: swith on/off with cycling

Posted: Wednesday 26 September 2018 14:50
by alanlsmith
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

Code: Select all

commandArray[#commandArray+1] = {['UpdateDevice'] = '<deviceIDX>|1|1'}
this will switch the device on.
This is mainly useful to update dummy devices, like thermostats for example without triggering an associated script.