Page 1 of 1
Switch on for 1 minute and off for 10 minutes
Posted: Wednesday 17 January 2024 17:05
by daPeda
Hello everyone,
how can I realise it in dzvents that a switch, which when a temperature of a sensor has < 20 degrees, is switched on via dzvents for one minute, then is switched off but only checks again in 10 minutes what the temperature is and then switches the switch on again for one minute and then again from the beginning?
All my attempts showed that either the switch was permanently switched on, or it was switched on and then switched off again after 2 seconds.
I would be pleased if someone could give me a tip.
Thank you very much!
Peter
Re: Switch on for 1 minute and off for 10 minutes
Posted: Wednesday 17 January 2024 18:48
by waltervl
Run the dZvents script every 10 minutes (using timer) and use switchOn().forMin(1) to switch on for 1 minute
Re: Switch on for 1 minute and off for 10 minutes
Posted: Wednesday 17 January 2024 23:38
by daPeda
Thanks a lot!
I thougt, that 'every ten Minutes' set in quotes was a synonyme for an function, i have to write by myself...
got it work now..
Thanks!
Peter
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 13:18
by PierreT
Why use a dzVents script for that? You can set this behaviour (on/off after X seconds) on the switch property page.
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 14:04
by jvdz
You would have to change that to 'every 11 minutes' to make it go On for 1 and Off for 10 minutes!
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 16:16
by habahabahaba
You can not set timer for 11 minutes
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 16:24
by Kedi
Yes, you can.
In dzVents set the timer to every minute and do calculation of the number of minutes from midnight, and then do a mod 11 on that number.
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 16:52
by habahabahaba
Kedi wrote: ↑Thursday 18 January 2024 16:24
Yes, you can.
In dzVents set the timer to every minute and do calculation of the number of minutes from midnight, and then do a mod 11 on that number.
That is not "every 11 minutes".
I'm calling your method "dancing with a tambourine"/
Sorry for offtop.
Re: Switch on for 1 minute and off for 10 minutes
Posted: Thursday 18 January 2024 19:06
by madpatrick
You can maybe use the "retrigger" function in dzventz
this is an part of a script i use and you can customize
Code: Select all
local scriptVar = '-=# PIR Woonkamer #=-'
local light = 'Woonkamer' -- change to name of your light/group
local Screens = 'Screens'
local retrigger = 'Retrigger using customEvent'
local minutesBeforeSunset = 120 -- xxx min before sunset
return
{
on =
{
timer =
{
function(domoticz)
return
domoticz.time.matchesRule('at ' .. domoticz.variables('UV_Sleep').value) or
domoticz.time.matchesRule('at ' .. minutesBeforeSunset .. ' minutes before sunset')
end,
},
--devices = { Test, },
customEvents =
{
retrigger,
}
},
logging = { level = domoticz.LOG_ERROR, -- change to domoticz.LOG_ERROR when all OK
marker = scriptVar
},
execute = function(dz)
local Sleep = dz.variables('UV_Sleep').value
local light = dz.groups(light) -- groups instead of device
local Screens_WNK = dz.devices(492)
local Screens_BLOK1 = dz.devices(493)
local Erker_gr = dz.devices(603)
local Erker_kl = dz.devices(612)
local Screens_Deur = dz.devices(605)
local PIR = dz.devices(451)
local lux = dz.devices(454).lux
dz.log('LUX = ' .. lux .. ' en verlichting ' .. light.name .. ' is ' .. light.state,dz.LOG_FORCE)
if dz.time.matchesRule('between ' .. minutesBeforeSunset .. ' minutes before sunset and ' .. Sleep) and not(dz.time.matchesRule('at ' .. Sleep)) then
if lux <= 10 and (Erker_gr.level < 50 or Erker_kl.level < 50 ) and Screens_BLOK1.state ~= "Open" and Screens_BLOK2.state ~= "Open" then
Screens_BLOK1.switchSelector('Open')
dz.log('Screens Blok 1 OPEN voor lichtsensor Lux <10',dz.LOG_FORCE)
dz.log('Script wordt opnieuw gestart in 5 minuten (regel 60)',dz.LOG_FORCE)
dz.emitEvent(retrigger).afterSec(300) -- try again
elseif light.state ~= 'On' then
dz.log('Script wordt opnieuw gestart in 3 minuten (regel 90)',dz.LOG_FORCE)
dz.emitEvent(retrigger).afterSec(180) -- try again
end
end
}
Re: Switch on for 1 minute and off for 10 minutes
Posted: Sunday 21 January 2024 11:37
by bitzy
did u solve your problem? if u use a 10 min trigger u will miss every 1 min that the switch is on, like previously said, so the time between On cycles will only be 9 min. if u necessarily need a 10 min cycle, here's the simplest idea i can came up with:
Code: Select all
return {
on = {
timer = { 'every 1 minutes' },
},
execute = function(dz, devices)
local mySwitch = dz.devices('yourSwitch') -- replace yourSwitch with the name of your switch
local temp = dz.devices('tempSensor').temperature -- replace tempSensor with your temperature sensore.
local time = os.time() -- the time when the script is triggered
local switchOffTime = 600 -- the time that switch need to be off in seconds (600 seconds = 10 min)
local desiredTemp = 20 -- the desired temperature
local lastSeen = mySwitch.lastUpdate.secondsAgo --time the switch was operated last time
local checkTime = time - (time - lastSeen) -- calculate when the switch was last operated
if (temp < desiredTemp and checkTime >= switchOffTime ) then --check if the temperature is under 20 and if 10 min have passed since the switch is last operated
mySwitch.switchOn().forSec(60).checkFirst() -- switch is On for 60 seconds
end
end
}
this script trigger every 1 minute and check the temperature and if 10 min have passed since the switch was last time actioned. if the temperature is strictly under 20 degrees and the time last update is 10 minutes then the switch is turned on for 1 minute.
u can also use as the trigger for the script the temperature sensor not the time trigger. but if u need the exact time between on state and the pause then u will need to think about how often the sensore is read and how is this affecting the time u check for the switch being off.
u should probably be a little more specific and clear with what u wanna accomplish. from how u formulated the problem in the first post, i kinda doubt that this is really what u want.
keep in mind that i'm just a beginner in this just like u so maybe a second opinion on this is a good idea