OK thanks, here we go.
The timer is used to work out the duration of the pool filtration (another script, totally independent at this time, sets filtration at specific times and duration according to temperature - no variable is passed to and from though).
- Pool-filtration.png (18.23 KiB) Viewed 2973 times
- Untitled-1.png (15.94 KiB) Viewed 2973 times
I've done a manual calculation, every minute now increments 344 hours on the counter. (Why 344? Can't find any obvious link - it's divisible by 8, which gives 43, a prime number)
This is what the log comes up with, when filtration is not running (counter not incrementing) :
2020-03-27 14:45:00.537 Status: dzVents: Info: Filtration_timer: ------ Start internal script: Filtration_timer:, trigger: "every 1 minutes"
2020-03-27 14:45:00.549 Status: dzVents: Debug: Filtration_timer: Processing device-adapter for Pool Filtration: Switch device adapter
2020-03-27 14:45:00.550 Status: dzVents: Debug: Filtration_timer: Processing device-adapter for Pool filtration timer: Counter device adapter
2020-03-27 14:45:00.550 Status: dzVents: Debug: Filtration_timer: State ==>> Off; Date Time ==>> 2020-03-27 14:45:00; hours On today ===>> 19590
2020-03-27 14:45:00.551 Status: dzVents: Info: Filtration_timer: ------ Finished Filtration_timer
When filtration is running :
2020-03-27 14:57:00.165 Status: dzVents: Info: Filtration_timer: ------ Start internal script: Filtration_timer:, trigger: "every 1 minutes"
2020-03-27 14:57:00.176 Status: dzVents: Debug: Filtration_timer: Processing device-adapter for Pool Filtration: Switch device adapter
2020-03-27 14:57:00.177 Status: dzVents: Debug: Filtration_timer: Processing device-adapter for Pool filtration timer: Counter device adapter
2020-03-27 14:57:00.177 Status: dzVents: Debug: Filtration_timer: State ==>> On; Date Time ==>> 2020-03-27 14:57:00; hours On today ===>> 23030
2020-03-27 14:57:00.178 Status: dzVents: Info: Filtration_timer: ------ Finished Filtration_timer
2020-03-27 14:57:00.178 Status: EventSystem: Script event triggered: /usr/local/domoticz/dzVents/runtime/dzVents.lua
This the code ; I usually note modifications in comments.
Code: Select all
--getUptime.lua, or now "Filtration_timer.lua"
--143 = P1 smart meter
local frequency = 1 -- set to desired frequency (1,2,3,4,5,6,10,12,15,20,30) -- lower number ==>> more accurate reporting
local mySwitch = 109 --'Pool Filtration'
local timeKeeper = 151 --'Pool filtration timer' -- set to name of created virtual counter incremental
local myTimeUnit = 'hour' -- set to unit preference (second, minute or hour)
-- = os.time(domoticz.time)
local Time = require('Time')
local now = Time() -- current time
--currentTime = now.rawTime --no longer needed : this is for resetting counter.
--[[ also adjust device settings of timeKeeper counter to chosen timeUnit Press [edit] on the device (on the utility tab)
Type: Counter
Divider: 0
Meter Offset: 0
Value Quantity (e.g. Weight): Count
Value Units (e.g. Kg): choose seconds, hours or minutes
]]--
return
{
on =
{
timer = {'every '.. frequency .. ' minutes'}, -- this will ensure updates to counter is done every <frequency> minutes the device is switched ON
devices = { mySwitch },
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = "Filtration_timer" },
data =
{
state = { initial = "-" },
secondsOn = { initial = 0 },
base = { initial = 0 },
},
execute = function(dz, item)
local mySwitch = dz.devices(mySwitch)
local timeKeeper = dz.devices(timeKeeper)
local timeUnits = {
minute = 60,
hour = 3600,
second = 1,
}
local function updateCounter()
dz.data.secondsOn = dz.data.secondsOn + ( dz.time.dDate - dz.data.base )
if timeKeeper.count ~= dz.data.secondsOn / timeUnits[myTimeUnit] then
timeKeeper.updateCounter(dz.utils.round(dz.data.secondsOn / timeUnits[myTimeUnit]) )
end
end
--[[
if currentTime == '00:00:00' then
dz.log('time is ' .. currentTime .. ', and the daily filtration timer has been reset.')
timeKeeper.updateCounter('0')
end
]]--
if item.isTimer and mySwitch.active and dz.data.base ~= 0 then
updateCounter()
dz.data.base = dz.time.dDate
dz.data.state = mySwitch.state
elseif item.isDevice and mySwitch.active and dz.data.state ~= 'On' then
dz.data.base = dz.time.dDate
dz.data.state = 'On'
elseif item.isDevice and dz.data.state == 'On' then
updateCounter()
dz.data.state = 'Off'
elseif item.isTimer and dz.data.base == 0 then
dz.data.base = dz.time.dDate
dz.data.state = mySwitch.state
end
dz.log("State ==>> " .. mySwitch.state .. "; Date Time ==>> " .. dz.time.rawDate .." " ..
dz.time.rawTime .. "; " .. myTimeUnit .. "s On today ===>> " .. timeKeeper.counterToday ,dz.LOG_DEBUG)
end
}
Now, apart from the update, I have also very recently added a device, renamed a couple : but the script points to device numbers and those have not changed as far as I can tell... What on earth could be going wrong? If I am not alone, maybe then this is update related? I'm on 2020.1 (but strangely still get the notification to update to latest version). NAS is a DS415+ running on DSM 6.2.2-24922 Update 4 : is up to date, but no recent update.
Many thanks for your input.