dzVents calculating active time
Posted: Monday 07 October 2024 12:02
Hi,
I have this script for car battery charging. (simplified for readability)
I'd like to have some help.
I want to calculate and save the time that the switch is off, 8A, 10A etc.
Best is to start an array and add minutes that a part of the script is active.
How can this be achieved.
I have this script for car battery charging. (simplified for readability)
Code: Select all
return {
on = {
devices = {'mySwitch',},
},
data = {
'timeOff', 'time8A','time10A','time13A','time16A',
},
logging = {
-- Level can be domoticz.LOG_INFO, domoicz.LOG_MODULE_EXEC_INFO, domoticz.LOG_DEBUG, domoticz.LOG_ERROR or domoticz.LOG_FORCE
--level = domoticz.LOG_INFO,
level = domoticz.LOG_DEBUG,
marker = '---- mySwitch -----',
},
execute = function(domoticz, triggerObject)
-- domoticz.devices('mySwitch').dump()
local Level = domoticz.devices('mySwitch')
if Level.state == 'Off' then
domoticz.log('0 Level set to Off :' .. Level.state,domoticz.LOG_DEBUG)
-- execute a command
elseif Level.state == '6A' then
domoticz.log('6 Level set to 6A :' .. Level.state,domoticz.LOG_DEBUG)
elseif Level.state == '8A' then
domoticz.log('8 Level set to 8A :' .. Level.state,domoticz.LOG_DEBUG)
elseif Level.state == '10A' then
domoticz.log('10 Level set to 10A :' .. Level.state,domoticz.LOG_DEBUG)
elseif Level.state == '13A' then
domoticz.log('13 Level set to 13A :' .. Level.state,domoticz.LOG_DEBUG)
elseif Level.state == '16A' then
domoticz.log('16 Level set to 16A :' .. Level.state,domoticz.LOG_DEBUG)
end
domoticz.log('Result mySwitch set to :' .. Level.state,domoticz.LOG_DEBUG)
end
}
-- example script from @waaren
--[[
return
{
on =
{
timer =
{
'every minute',
},
},
execute = function(dz)
local myTime = '15:00:00'
local someTime = dz.time.makeTime(dz.time.rawDate .. ' ' .. myTime) -- this will create the time object someTime
-- compare require two dzVents time objects (first one here is dz.time, second one is someTime )
dz.log('Delta time between ' .. dz.time.rawTime .. ' and ' .. someTime.rawTime .. ' is ' .. dz.time.compare(someTime).minutes .. ' minutes.', dz.LOG_FORCE)
end
}
]]--
I want to calculate and save the time that the switch is off, 8A, 10A etc.
Best is to start an array and add minutes that a part of the script is active.
How can this be achieved.