Page 1 of 1
passed time after switchOff().afterMin(180)
Posted: Saturday 28 December 2019 15:24
by pgas37
Hello,
I have a dzventz-script with the command "domoticz.devices('xxx').switchOff().afterMin(180)".
I want to know how many minutes have been passed after the device is called for switchOff.
Can anyone help me with a piece of script?
Thanks
Paul
Re: passed time after switchOff().afterMin(180)
Posted: Sunday 29 December 2019 0:41
by waaren
pgas37 wrote: ↑Saturday 28 December 2019 15:24
I have a dzventz-script with the command "domoticz.devices('xxx').switchOff().afterMin(180)".
I want to know how many minutes have been passed after the device is called for switchOff.
Where do you want to show this countdown value ? In the log, a variable or in another device ?
If you can share the script as it is now I might be able to help
Re: passed time after switchOff().afterMin(180)
Posted: Sunday 29 December 2019 11:31
by pgas37
Waaren,
see code below.
The first intention was to show it in the log-file, but may be a 'variable' or in 'another device' opens some new possibilities.
thanks
Paul
Code: Select all
return {
active = true, -- set to false to disable this script
on = {
devices = {
110, --ADC1 schakelaar afzuiginstallatie
5560, -- Motion MotionBadk
5549, --Motion-wc-hal
5555, --Motion-wc-etage
5449 --Dummy afzuiginstallatie
}
},
execute = function(domoticz, device)
local Afzuiging = domoticz.devices('Afzuiginstallatie - ADC1')
MotionBadk = domoticz.devices('Motion-badkamer')
MotionWcHal = domoticz.devices('Motion-wc-hal')
MotionWcEtage = domoticz.devices('Motion-wc-etage')
DummyAfzuig = domoticz.devices('Dummy afzuiginstallatie')
--currentTime = domoticz.time.raw -- format 2017-12-31 22:19:15'
currentTime = domoticz.time.rawTime -- format 00:00:00
currentHours = domoticz.time.hour
currentMinutes = domoticz.time.minutes
PRINT_MODE = false --true
if PRINT_MODE == true then
print ('============================================================================================ ')
print('======currentTime==== ' ..currentTime)
print('======current Hours=== ' ..currentHours)
print('======current minutes=== ' ..currentMinutes)
if (MotionWcHal.state) == 'On' then
print ('===========Motion-wc-hal is on =========== ')
else
print ('===========Motion-wc-hal is off =========== ')
end
if (MotionBadk.state) == 'On' then
print ('===========MotionBadk is on =========== ')
else
print ('===========MotionBadk is off =========== ')
end
if (MotionWcEtage.state) == 'On' then
print ('===========Motion-wc-etage is on =========== ')
else
print ('===========Motion-wc-etage is off =========== ')
end
if (Afzuiging.state) == 'Off' then
print ('===========afzuiginstallatie uit =========== ')
else
print ('===========afzuiginstallatie aan =========== ')
end
if (DummyAfzuig.state) == 'Off' then
print ('===========DummyAfzuig is off =========== ')
else
print ('===========DummyAfzuig is on =========== ')
end
end
--if (DummyAfzuig.state) == 'On' then
-- print ('===========DummyAfzuig 2 is on =========== ')
-- return
--end
--print ('===========afzuigscript loopt door =========== ')
if
(MotionWcHal.state == 'On') and (DummyAfzuig.state == 'Off') then
domoticz.devices('Afzuiginstallatie - ADC1').switchOn().checkFirst().repeatAfterSec(10,2)
domoticz.devices('Afzuiginstallatie - ADC1').switchOff().checkFirst().afterMin(15).repeatAfterSec(10,2)
if PRINT_MODE == true then
print ('===========return motion wc-hal===== ')
end
return
end
if (MotionWcEtage.state == 'On') and (DummyAfzuig.state == 'Off') then --and (currentTime >= "13:14:00") and (currentTime < "13:22:00") then
domoticz.devices('Afzuiginstallatie - ADC1').switchOn().checkFirst().repeatAfterSec(10,2)
domoticz.devices('Afzuiginstallatie - ADC1').switchOff().checkFirst().afterMin(15).repeatAfterSec(10,2)
--domoticz.devices('SchakelaarSL2- zolderstelling').switchOn() --.repeatAfterSec(3,2)Afzuiging.switchOn()
if PRINT_MODE == true then
print ('===========return motion wc-etage==== ')
end
return
end
if (MotionBadk.state == 'On') and (DummyAfzuig.state == 'Off') and (currentTime >= "21:45:00") and (currentTime < "23:00:00") then
--domoticz.devices('Dummy afzuiginstallatie').switchOn().repeatAfterSec(10,2)
--domoticz.devices('Dummy afzuiginstallatie').switchOff().afterMin(120)repeatAfterSec(10,2)
if PRINT_MODE == true then
print ('===========return motion badk obv tijdslot===== ')
end
return
end
if (MotionBadk.state == 'On') and (DummyAfzuig.state == 'Off') then
domoticz.devices('Afzuiginstallatie - ADC1').switchOn().repeatAfterSec(10,2)
domoticz.devices('Dummy afzuiginstallatie').switchOn().repeatAfterSec(10,2)
domoticz.devices('Afzuiginstallatie - ADC1').switchOff().afterMin(180).repeatAfterSec(10,2)
domoticz.devices('Dummy afzuiginstallatie').switchOff().afterMin(179)repeatAfterSec(10,2)
if PRINT_MODE == true then
print ('===========return motion badk===== ')
end
return
end
end
}
Re: passed time after switchOff().afterMin(180)
Posted: Sunday 29 December 2019 15:04
by waaren
pgas37 wrote: ↑Sunday 29 December 2019 11:31
see code below.
Script could look like
Code: Select all
return
{
active = true, -- set to false to disable this script
on =
{
devices =
{
110, --ADC1 schakelaar afzuiginstallatie
5560, -- Motion MotionBadk
5549, --Motion-wc-hal
5555, --Motion-wc-etage
5449 --Dummy afzuiginstallatie
},
timer =
{
'every minute'
},
},
logging =
{
level = domoticz.LOG_DEBUG
},
data = { countdown = { initial = {} }},
execute = function(dz, item)
_G.logMarker = _G.moduleLabel
local Afzuiging = dz.devices('Afzuiginstallatie - ADC1')
local MotionBadk = dz.devices('Motion-badkamer')
local MotionWcHal = dz.devices('Motion-wc-hal')
local MotionWcEtage = dz.devices('Motion-wc-etage')
local DummyAfzuig = dz.devices('Dummy afzuiginstallatie')
local Zolder = dz.devices('SchakelaarSL2- zolderstelling')
local countdownVar = dz.variables('countdown') -- define this variable as type string
local function managedSwitchOff(device, delay, repeatDelay, repeatTimes)
delay = delay or 0
device.cancelQueuedCommands() -- remove previous scheduled commands for this device
if delay > 0 then dz.data.countdown[device.name] = delay end
repeatDelay = repeatDelay or 10
repeatTimes = repeatTimes or 2
device.switchOff().afterMin(delay).repeatAfterSec(repeatDelay, repeatTimes)
end
local function managedSwitchOn(device, delay, repeatDelay, repeatTimes)
delay = delay or 0
repeatDelay = repeatDelay or 10
repeatTimes = repeatTimes or 2
device.switchOn().checkFirst().afterMin(delay).repeatAfterSec(repeatDelay, repeatTimes)
end
if item.isTimer then
local countdownString, countdownLogString = ''
for name, countdown in pairs(dz.data.countdown) do
if countdown > 0 then
dz.data.countdown[name] = countdown - 1
countdownLogString = 'Remaining on time for ' .. name .. ': ' .. countdown .. ' minutes.'
dz.log('Remaining on time for ' .. name .. ': ' .. countdown .. ' minutes.', dz.LOG_DEBUG)
countdownString = countdownString .. countdownLogString .. '\n'
end
end
if countdownVar.value ~= countdownString then countdownVar.set(countdownString) end
else
dz.log ('============================================================================================ ',dz.LOG_DEBUG)
dz.log('======currentTime==== ' .. dz.time.raw,dz.LOG_DEBUG)
dz.log('======current Hours=== ' .. dz.time.hour,dz.LOG_DEBUG)
dz.log('======current minutes=== ' ..dz.time,minutes,dz.LOG_DEBUG)
dz.log('===========MotionWcHal is ' .. MotionWcHal.state ..' =========== ',dz.LOG_DEBUG)
dz.log('===========MotionBadk is ' .. MotionBadk.state ..' =========== ',dz.LOG_DEBUG)
dz.log('===========MotionWcEtage is ' .. MotionWcEtage.state ..' =========== ',dz.LOG_DEBUG)
dz.log('===========Afzuiging is ' .. Afzuiging.state ..' =========== ',dz.LOG_DEBUG)
dz.log('===========DummyAfzuig is ' .. DummyAfzuig.state ..' =========== ',dz.LOG_DEBUG)
--dz.log ('===========afzuigscript loopt door =========== ',dz.LOG_DEBUG)
if MotionWcHal.state == 'On' and DummyAfzuig.state == 'Off' then
managedSwitchOn(Afzuiging)
managedSwitchOff(Afzuiging, 15)
dz.log ('===========return motion wc-hal===== ' ,dz.LOG_DEBUG)
elseif MotionWcEtage.state == 'On' and DummyAfzuig.state == 'Off' then --and (currentTime >= "13:14:00") and (currentTime < "13:22:00") then
managedSwitchOn(Afzuiging)
managedSwitchOff(Afzuiging, 15)
-- zolder.switchOn() --.repeatAfterSec(3,2)Afzuiging.switchOn()
dz.log ('===========return motion wc-etage==== ',dz.LOG_DEBUG)
elseif MotionBadk.state == 'On' and DummyAfzuig.state == 'Off' and dz.time.matchesRule('at 22:45-23:00') then
-- managedSwitchOn(DummyAfzuig)
-- managedSwitchOff(DummyAfzuig, 120)
dz.log ('===========return motion badk obv tijdslot===== ',dz.LOG_DEBUG)
elseif MotionBadk.state == 'On' and DummyAfzuig.state == 'Off' then
managedSwitchOn(Afzuiging)
managedSwitchOn(DummyAfzuig)
managedSwitchOff(Afzuiging, 180)
managedSwitchOff(DummyAfzuig, 179)
dz.log ('===========return motion badk===== ',dz.LOG_DEBUG)
end
end
end
}
Re: passed time after switchOff().afterMin(180)
Posted: Monday 30 December 2019 17:16
by pgas37
Waaren,
Quite some additions and changes. I never could create this myself!
Thanks, in the next comming days i will try your script and let you know.
Thanks again.
Regards
Paul
Re: passed time after switchOff().afterMin(180)
Posted: Tuesday 31 December 2019 13:31
by pgas37
Hi Waaren,
regret to say, but the script does not work:
a motion:
does not switch on the device "afzuiging"
in de debug logfile the result of the lines "the dz.time.raw and hour" .
Also a manual switch(On) of the "DummyAfzuig"-switch does not result in debug-output.
I also replaced the managedSwitch(on) with the orginal command
"domoticz.devices('Afzuiginstallatie - ADC1').switchOn().checkFirst().repeatAfterSec(10,2)", but no Switch(On) of "Afzuiging" anymore.
I cannot find the operation of command managedSwitch(On) and (Off) c.q. the difference with Switch(On) or (Off). I looked for it in Domoticz-wiki.
Hope you can help once more?
regards
Paul
Re: passed time after switchOff().afterMin(180)
Posted: Tuesday 31 December 2019 13:44
by waaren
pgas37 wrote: ↑Tuesday 31 December 2019 13:31
I cannot find the operation of command managedSwitch(On) and (Off) c.q. the difference with Switch(On) or (Off). I looked for it in Domoticz-wiki.
These are local functions. Constructed for use in this script and not available for other scripts.
Hope you can help once more?
Sure, did you define the domoticz uservariable countdown as string ?
Can you please share the log ? Via DM is OK