Page 1 of 1

dz addMinutes issue (solved)

Posted: Sunday 12 January 2020 23:09
by hestia
When I use addMinutes the minutes are not added to the "time used" by to the "time of now"

Code: Select all

local DOMAIN = 'AddTime'
local TIME_INTERVAL = 'every minute between 06:45-23-55 on mon, tue, wed, thu, fri, sat, sun'
local TIME_W1 = "6:45"


return {
    active = true,
    logging = {
	level = domoticz.LOG_DEBUG,
	marker = DOMAIN
	},
    on = {
         timer = {TIME_INTERVAL},
	},

    execute = function(dz, the_timmer)
    local LOG_LEVEL = dz.LOG_DEBUG
    
    dz.log('Timer event was triggered by ' .. the_timmer.trigger, LOG_LEVEL)
                
    local Time = require('Time')
    local now = Time()
    local wakeUpTime1 = Time(now.year .. "-" .. now.month .."-" .. now.day  .. " " ..  TIME_W1 .. ':00')
    local wakeUpTime2 = wakeUpTime1.addMinutes(15)
    dz.log('wakeUpTime1 ' .. wakeUpTime1.raw ..  ' wakeUpTime2 ' .. wakeUpTime2.raw, LOG_LEVEL) 
    
end
} 
Log
Spoiler: show
2020-01-12 23:03:00.290 Status: dzVents: Info: AddTime: ------ Start internal script: AddTime:, trigger: every minute between 06:45-23-55 on mon, tue, wed, thu, fri, sat, sun
2020-01-12 23:03:00.290 Status: dzVents: Debug: AddTime: Timer event was triggered by every minute between 06:45-23-55 on mon, tue, wed, thu, fri, sat, sun
2020-01-12 23:03:00.291 Status: dzVents: Debug: AddTime: wakeUpTime1 2020-1-12 6:45:00 wakeUpTime2 2020-01-12 23:18:00
2020-01-12 23:03:00.291 Status: dzVents: Info: AddTime: ------ Finished AddTime
Version: 4.11605
Build Hash: 7de1f368f
Compile Date: 2020-01-08 23:12:15
dzVents Version: 2.5.5

Re: dz addMinutes issue?

Posted: Monday 13 January 2020 0:45
by waaren
hestia wrote: Sunday 12 January 2020 23:09 When I use addMinutes the minutes are not added to the "time used" but to the "time of now"
Indeed a bug. Thx for reporting !
Fixed in next Beta. (Domoticz V4.11606)

If you already want to test fix
change line 307 in <domoticz dir>/dzVents/runtime/Time.lua
from

Code: Select all

    return Time( os.date("%Y-%m-%d %H:%M:%S", os.time() +  factor * math.floor(seconds) ))
to

Code: Select all

    return Time( os.date("%Y-%m-%d %X", self.dDate +  factor * math.floor(seconds) )) 

Re: dz addMinutes issue?

Posted: Monday 13 January 2020 8:37
by hestia
Thanks :-)
it's ok with the fix

another question regarding between, I don't understand why the between condition reports false in the following case...

Code: Select all

local DOMAIN = 'AddTime'
local TIME_INTERVAL = 'every minute'
local TIME_W1 = "8:25"


return {
    active = true,
    logging = {
	level = domoticz.LOG_DEBUG,
	marker = DOMAIN
	},
    on = {
         timer = {TIME_INTERVAL},
	},

    execute = function(dz, the_timmer)
    local LOG_LEVEL = dz.LOG_DEBUG
    
    dz.log('Timer event was triggered by ' .. the_timmer.trigger, LOG_LEVEL)
                
    local Time = require('Time')
    local now = Time()
    local wakeUpTime1 = Time(now.year .. "-" .. now.month .."-" .. now.day  .. " " ..  TIME_W1 .. ':00')
    local wakeUpTime2 = wakeUpTime1.addMinutes(15)
    
    dz.log('wakeUpTime1 ' .. wakeUpTime1.raw, LOG_LEVEL)
    dz.log('now         ' .. now.raw, LOG_LEVEL)
    dz.log('wakeUpTime2 ' .. wakeUpTime2.raw, LOG_LEVEL) 

    local timeConditionT1ToT2 = (dz.time.matchesRule('between wakeUpTime1 and wakeUpTime2'))
    dz.log('timeConditionT1ToT2 ' .. tostring(timeConditionT1ToT2), LOG_LEVEL)
    
    
    local timeConditionT1ToT2 = (now.matchesRule('between wakeUpTime1 and wakeUpTime2'))
    dz.log('timeConditionT1ToT2 ' .. tostring(timeConditionT1ToT2), LOG_LEVEL)
    
end
} 
Spoiler: show
2020-01-13 08:33:00.290 Status: dzVents: Debug: AddTime: Timer event was triggered by every minute
2020-01-13 08:33:00.293 Status: dzVents: Debug: AddTime: wakeUpTime1 2020-1-13 8:25:00
2020-01-13 08:33:00.294 Status: dzVents: Debug: AddTime: now 2020-1-13 8:33:0.208
2020-01-13 08:33:00.295 Status: dzVents: Debug: AddTime: wakeUpTime2 2020-01-13 08:40:00
2020-01-13 08:33:00.297 Status: dzVents: Debug: AddTime: timeConditionT1ToT2 false
2020-01-13 08:33:00.299 Status: dzVents: Debug: AddTime: timeConditionT1ToT2 false

Re: dz addMinutes issue?

Posted: Monday 13 January 2020 19:54
by waaren
hestia wrote: Monday 13 January 2020 8:37 another question regarding between, I don't understand why the between condition reports false in the following case...
local timeConditionT1ToT2 = (dz.time.matchesRule('between wakeUpTime1 and wakeUpTime2'))
local timeConditionT1ToT2 = (now.matchesRule('between wakeUpTime1 and wakeUpTime2'))
A couple of observations:
  • dz.time and now are the same in your script.
  • Starting dzVents version 2.5.4 (domotic version >= V4.11593 You can also use

    Code: Select all

    local wakeUpTime1 = dz.time.makeTime(dz.time.rawdate .. " " ..  TIME_W1 ) -- No need for local Time = require('Time'), local now = Time()
    
  • On the rules you use in matchesRule(); you include wakeUpTime1 and wakeUpTime2. These are just names of the just created time objects. and entered within a string they will not influence anything. You probably want something like

    Code: Select all

    local timeRule = 'between '  .. wakeUpTime1.rawTime .. ' and ' .. wakeUpTime2.rawTime' -- not the complete object but the attribute rawTime   
    local timeConditionT1ToT2 = dz.time.matchesRule(timeRule)
Your post triggered me to check the dzVents Time module again and I identified some small glitches. They should be OK in the latest Beta
( domoticz V4.11609)

See below a small test script.

Code: Select all

return {
    on = 
    {
         timer = 
         { 
            'every minute'
         },
         
         devices = 
         { 
             'timeTrigger' 
         },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = DOMAIN
    },

    execute = function(dz, item )
    local wakeUpTime1 = '08:25'
    local wakeUpTime1Object = dz.time.makeTime(dz.time.rawDate .. " " ..  wakeUpTime1 ..':00' )  -- dzVents >= 2.5.4 
    local wakeUpTime2Object = wakeUpTime1Object.addMinutes(15)
    
    dz.log('now         : ' .. dz.time.raw, LOG_DEBUG)
    dz.log('wakeUpTime1 : ' .. wakeUpTime1Object.raw, LOG_DEBUG)
    dz.log('wakeUpTime2 : ' .. wakeUpTime2Object.raw, LOG_DEBUG) 
   
    local function checkRule(timeObject, check)
        dz.log('Does ' .. timeObject.rawTime ..  '  matchesRule('.. check .. ')  ==> ' .. tostring(timeObject.matchesRule(check)),dz.LOG_DEBUG)
    end

    timeObjects = 
    {
        dz.time, 
        wakeUpTime1Object, 
        wakeUpTime2Object, 
    }
    
    RulesToCheck = 
    {
        'at 08:25-8:40' , 
        'at 08:40-08:25' , 
        'at 08:40-7:25' , 
        'at 19:25-12:40' , 
        'at 11:25-11:45' , 
        'at 12:40-11:40' , 
        'between 8:25 and 8:40' , 
        'between 08:25, 08:40', 
        'between 8:40 and 8:20', 
        'between 08:40:00 and 08:20:00',
        'between ' .. wakeUpTime1Object.rawTime .. ' and ' .. wakeUpTime2Object.rawTime,
    }
    
    for _, timeObject in ipairs(timeObjects) do
        for _, rule in ipairs(RulesToCheck) do
            checkRule(timeObject,rule)
        end
    end
end
} 

Re: dz addMinutes issue?

Posted: Monday 13 January 2020 23:39
by hestia
Thanks a lot for your help :-)

The quotes, big mistake !

For the DzVents update, I'll wait to find it in https://www.domoticz.com/downloads/