AfterMin problem  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

AfterMin problem

Post by ronaldbro »

Hi,

I have a few scripts using afterMin to dim some lights after a period of inactivity. I noticed that one of the scripts stopped working. I did some tests and found that it depends on the number of minutes. 1, 2, 3 and 4 minutes work as expected but 5 and 10 minutes does nothing.

There’s nothing wrong with the scripts. I tried multiple scripts using “device.dimTo(level).afterMin(delay)” using a ‘constant’ variable for level and delay and I only changed the value of delay in the scripts.
I also see in the log that a timed command is created with the correct number of seconds.

I’m using the latest beta and I think the problem started about 1 or 2 weeks ago.

Anyone else have a problem with this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: AfterMin problem

Post by waaren »

ronaldbro wrote: Wednesday 06 November 2019 22:31 I have a few scripts using afterMin to dim some lights after a period of inactivity. I noticed that one of the scripts stopped working. I did some tests and found that it depends on the number of minutes. 1, 2, 3 and 4 minutes work as expected but 5 and 10 minutes does nothing.
Can you please share ( an example of) the script to test if this behavior can be replicated ?
And please include the hardware, type and subtype of the light.

In my tests with Hue and Yeelight connected dimmable lights I don't see this (domoticz 4.11462)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem

Post by ronaldbro »

Sure, no problem.

Here's the script:

Code: Select all

local DIMLEVEL_IDLE = 1
local DIMLEVEL_ACTIVITY = 50
local MINUTES_ACTIVITY_LEVEL = 4

return {
	on = {
		devices = {
		    idx_bijkeuken_achterdeur,
		    idx_garage_deur,
		    idx_garage_garagedeur,
		    idx_achtertuin_beweging
		},

		timer = {
			'at sunset',
			'at sunrise'
		}
	},

	logging = {
        level = domoticz.LOG_DEBUG,
--        level = domoticz.LOG_INFO,
--        level = domoticz.LOG_Error,
        marker = "Achtertuin - Zithoek"
    },

	execute = function(dz, triggeredItem, info)

        local lamp = dz.devices(idx_achtertuin_zithoek)
   
        if triggeredItem.isTimer then
            if triggeredItem.trigger == 'at sunset' and lamp.active == false then
                dz.log('Sunset: Set lvl to ' .. DIMLEVEL_IDLE)
                lamp.dimTo(DIMLEVEL_IDLE)
            elseif triggeredItem.trigger == 'at sunrise' and lamp.active then
                dz.log('Sunrise: switch lamp off.')
                lamp.cancelQueuedCommands()
                lamp.switchOff()
            end
        elseif triggeredItem.isDevice and dz.security == dz.SECURITY_DISARMED and lamp.active then
            dz.log('Set lvl to ' .. DIMLEVEL_ACTIVITY .. ' for ' .. MINUTES_ACTIVITY_LEVEL .. ' minutes.')
            lamp.cancelQueuedCommands()
            lamp.dimTo(DIMLEVEL_ACTIVITY)
            lamp.dimTo(DIMLEVEL_IDLE).afterMin(MINUTES_ACTIVITY_LEVEL)
        end
	end
}

The bulbs are Tradfri (only dimmable) connected to zigate.

Thanks for your help.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: AfterMin problem

Post by waaren »

ronaldbro wrote: Wednesday 06 November 2019 23:41 idx_bijkeuken_achterdeur,
idx_garage_deur,
idx_garage_garagedeur,
idx_achtertuin_beweging
Thx but I don't see any declarations for these vars. Where are they set ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem

Post by ronaldbro »

They are in global_data so I use them in every script.

Top 3 are xiaomi doorsensors on Zigate and the last one is a Z-wave Fibaro PIR
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: AfterMin problem

Post by waaren »

ronaldbro wrote: Wednesday 06 November 2019 23:50 They are in global_data so I use them in every script.

Top 3 are xiaomi doorsensors on Zigate and the last one is a Z-wave Fibaro PIR
Can you please share your global_data.lua as well to get a complete picture ? If you don't want to share it here you can send it via PM.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem

Post by ronaldbro »

No problem, here it is

Code: Select all

idx_test_deursensor                 = 191
idx_test_switch                     = 428

idx_achtertuin_beweging             = 364
idx_achtertuin_zithoek	            = 427 
idx_achtertuin_lux                  = 366

idx_aanwezig_iemand                 = 172
idx_aanwezig_eline                  = 154
idx_aanwezig_ronald                 = 153

idx_alarm_knop                      = 301
idx_alarm_securityPanel             = 70
idx_alarm_toggleAlarmAway           = 122
idx_alarm_sirene                    = 135 
idx_alarm_sireneSound               = 75
idx_alarm_sireneVolume              = 79

idx_badkamer_relVocht               = 239
idx_badkamer_ventilator             = 4
idx_badkamer_ventilator_PowerUsage  = 9

idx_bijkeuken_achterdeur            = 202

idx_floris_dimmer                   = 281
idx_floris_plafond                  = 280
idx_floris_relVocht                 = 234

idx_garage_deur                     = 200
idx_garage_garagedeur               = 201

idx_kantoor_raam                    = 208
idx_kantoor_relVocht                = 250
idx_kantoor_rolluik                 = 273
idx_kantoor_rolluik_switch          = 272

idx_keuken_aanrechtverlichting      = 403
idx_keuken_beweging                 = 356
idx_keuken_lux                      = 357

idx_slaapkamer_bewegingLinks        = 217
idx_slaapkamer_bewegingLinks_lux    = 218
idx_slaapkamer_bewegingRechts       = 213
idx_slaapkamer_bewegingRechts_lux   = 216
idx_slaapkamer_bedlamp              = 118
idx_slaapkamer_raam                 = 207
idx_slaapkamer_relVocht             = 245
idx_slaapkamer_rolluik              = 276
idx_slaapkamer_rolluikManualMode    = 279

idx_olivier_lamp                    = 267

idx_woonkamer_rolluikManualMode     = 43
idx_woonkamer_rolluik               = 38
idx_woonkamer_spotsUitbouw		    = 422
idx_woonkamer_dressoir 		        = 254
idx_woonkamer_eettafel		        = 174
idx_woonkamer_zithoek		        = 175
idx_woonkamer_leeslampKnop          = 269
idx_woonkamer_leeslamp              = 402


idx_sceneswitch_avond               = 149
idx_sceneswitch_avondAlleenAan      = 300
idx_sceneswitch_welterusten         = 150
idx_sceneswitch_goedemorgen         = 151
idx_sceneswitch_checkScenes         = 430

var_idx_dagNacht                    = 5

CONST_DAGNACHT_DAG                  = 'DAG'
CONST_DAGNACHT_NACHT                = 'NACHT'

return {
	-- global persistent data
--	data = {
--		myGlobalVar = { initial = 12 }
--	},

	-- global helper functions
	helpers = {
        ------------------------------------------------------------------------
        -- isHoliday
        -- Is het vandaag een feestdag?
        -- return true/false
        ------------------------------------------------------------------------
        isHoliday = function(domoticz)
		    local year = domoticz.time.year
		    local month = domoticz.time.month
		    local day = domoticz.time.day
		    local result = false
		    
		    if (month==1 and day==1)    --Nieuwjaar
            or (month==4 and day==27)   --Koningsdag
            or (month==12 and day==25)  --Eerste kerstdag
            or (month==12 and day==26)  --Tweede kerstdag
            then
                result = true

            elseif year==2019 then
    		    if (month==4 and day==21)   --Eerste paasdag
                or (month==4 and day==22)   --Tweede paasdag
                or (month==5 and day==30)   --Hemelvaart
                or (month==6 and day==9)    --1e pinksterdag
                or (month==6 and day==10)   --2e pinksterdag
                then
                    result = true
                end

            elseif year==2020 then
    		    if (month==4 and day==12)   --Eerste paasdag
                or (month==4 and day==13)   --Tweede paasdag
                or (month==5 and day==5)    --bevrijdingsdag
                or (month==5 and day==21)   --Hemelvaart
                or (month==5 and day==31)   --1e pinksterdag
                or (month==6 and day==1)    --2e pinksterdag
                then
                    result = true
                end

            elseif year==2021 then
    		    if (month==4 and day==4)    --Eerste paasdag
                or (month==4 and day==5)    --Tweede paasdag
                or (month==5 and day==13)   --Hemelvaart
                or (month==5 and day==23)   --1e pinksterdag
                or (month==5 and day==24)   --2e pinksterdag
                then
                    result = true
                end
                    
            elseif year==2022 then
    		    if (month==4 and day==17)   --Eerste paasdag
                or (month==4 and day==18)   --Tweede paasdag
                or (month==5 and day==26)   --Hemelvaart
                or (month==6 and day==5)    --1e pinksterdag
                or (month==6 and day==6)    --2e pinksterdag
                then
                    result = true
                end
                
            elseif year==2023 then
    		    if (month==4 and day==9)    --Eerste paasdag
                or (month==4 and day==10)   --Tweede paasdag
                or (month==5 and day==18)   --Hemelvaart
                or (month==5 and day==28)   --1e pinksterdag
                or (month==5 and day==29)   --2e pinksterdag
                then
                    result = true
                end

            elseif year==2024 then
    		    if (month==3 and day==31)   --Eerste paasdag
                or (month==4 and day==1)    --Tweede paasdag
                or (month==5 and day==9)    --Hemelvaart
                or (month==5 and day==19)   --1e pinksterdag
                or (month==5 and day==20)   --2e pinksterdag
                then
                    result = true
                end
            end

			return result
		end,

        ------------------------------------------------------------------------
        -- isSunOrHoliday
        -- Is het vandaag een zondag of een feestdag?
        -- return true/false
        ------------------------------------------------------------------------
		isSunOrHoliday = function(domoticz)
		    local result = false

            result = domoticz.time.matchesRule('on sun')

            if result == false then
                result = domoticz.helpers.isHoliday(domoticz)
            end

			return result
	    end
	    
	}
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: AfterMin problem

Post by waaren »

[
ronaldbro wrote: Wednesday 06 November 2019 22:31 I have a few scripts using afterMin to dim some lights after a period of inactivity. I noticed that one of the scripts stopped working. I did some tests and found that it depends on the number of minutes. 1, 2, 3 and 4 minutes work as expected but 5 and 10 minutes does nothing.
Tried to replicate but no luck yet.
What do you see in the logs at the ecpected time ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem

Post by ronaldbro »

Got some logs:

1 minute delay:
Spoiler: show
2019-11-07 21:16:03.891 Status: dzVents: Info: Achtertuin - Zithoek: ------ Start internal script: Achtertuin - Zithoek: Device: "Zigate - lumi.remote.b286acn01_DButton_3-00158d00031360ed-01 (Zigate)", Index: 428
2019-11-07 21:16:03.893 Status: dzVents: Debug: Achtertuin - Zithoek: Processing device-adapter for Achtertuin: Zithoek: Switch device adapter
2019-11-07 21:16:03.893 Status: dzVents: Info: Achtertuin - Zithoek: Set lvl to 50 for 1 minutes.
2019-11-07 21:16:03.893 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 50
2019-11-07 21:16:03.893 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 1
2019-11-07 21:16:03.893 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 1 AFTER 60 SECONDS
2019-11-07 21:16:03.893 Status: dzVents: Info: Achtertuin - Zithoek: ------ Finished Achtertuin - Zithoek
2019-11-07 21:16:04.088 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:16:04.235 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:16:06.266 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:16:06.584 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:16:06.519 Status: dzVents: Info: Handling events for: "Scene - Check scenes", value: "On"
2019-11-07 21:16:19.338 (Buienradar) Temp + Humidity + Baro (Buienradar: THB)
2019-11-07 21:16:19.361 (Buienradar) Temp (Ground Temperature (10 cm))
2019-11-07 21:16:19.387 (Buienradar) Temp (Feel Temperature)
2019-11-07 21:16:19.422 (Buienradar) Wind (Wind)
2019-11-07 21:16:19.457 (Buienradar) General/Visibility (Visibility)
2019-11-07 21:16:19.484 (Buienradar) General/Custom Sensor (Sun Power)
2019-11-07 21:16:19.525 (Buienradar) Rain (Rain)
2019-11-07 21:16:20.149 (Buienradar) General/Custom Sensor (Next Rainshower Leadtime)
2019-11-07 21:16:20.170 (Buienradar) General/Custom Sensor (Next Rainshower Duration)
2019-11-07 21:16:20.201 (Buienradar) General/Custom Sensor (Next Rainshower Avg Rainrate)
2019-11-07 21:16:20.235 (Buienradar) General/Custom Sensor (Next Rainshower Max Rainrate)
2019-11-07 21:16:20.258 (Buienradar) General/Percentage (Rain Intensity)
2019-11-07 21:16:20.280 (Buienradar) General/Custom Sensor (Rainfall next Hour)
2019-11-07 21:16:25.937 (Zigate) UpdateDevice - ( Olivier: THB) 0:17.1;62.7;1;996.3;4
2019-11-07 21:16:25.999 (Zigate) UpdateDevice - (Olivier: Temp + RV) 0:17.1;62.7;1
2019-11-07 21:16:26.044 (Zigate) UpdateDevice - (Olivier: Temperatuur) 17.1:17.1
2019-11-07 21:16:26.097 (Zigate) UpdateDevice - ( Olivier: THB) 0:17.1;62.5;1;996.3;4
2019-11-07 21:16:26.119 (Zigate) UpdateDevice - (Olivier: Temp + RV) 0:17.1;62.5;1
2019-11-07 21:16:26.142 (Zigate) UpdateDevice - (Olivier: Luchtvochtigheid) 62.5:1
2019-11-07 21:16:26.180 (Zigate) UpdateDevice - ( Olivier: THB) 0:17.1;62.5;1;997.1;4
2019-11-07 21:16:26.253 (Zigate) UpdateDevice - (Olivier: Barometer) 0:997.1;4
2019-11-07 21:17:01.491 (zwave) General/kWh (Badkamer: Ventilator - kWh Meter)
2019-11-07 21:17:02.485 (zwave) Usage (Badkamer: Ventilator - Usage)
2019-11-07 21:17:02.513 (zwave) General/kWh (Badkamer: Ventilator - kWh Meter)
2019-11-07 21:17:02.643 Status: dzVents: Info: Handling events for: "Badkamer: Ventilator - Usage", value: "0.0"
2019-11-07 21:17:03.464 (zwave) General/Voltage (Badkamer: Ventilator - Voltage)
2019-11-07 21:17:04.463 (zwave) Current (Badkamer: Ventilator - Unknown)
2019-11-07 21:17:04.137 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:17:05.639 (Zigate) UpdateDevice - (Achtertuin: Zithoek Links) 1:1
2019-11-07 21:17:06.177 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:17:06.402 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:17:06.355 Status: dzVents: Info: Handling events for: "Scene - Check scenes", value: "On"
10 minutes delay:
Spoiler: show
2019-11-07 21:19:00.632 (Zigate) UpdateDevice - (Bijkeuken: Achterdeur) 0:Off
2019-11-07 21:19:00.877 (Zigate) UpdateGroup - (Achtertuin: Zithoek) 1:31
2019-11-07 21:19:00.811 Status: dzVents: Info: Handling events for: "Zigate - lumi.remote.b286acn01_DButton_3-00158d00031360ed-01", value: "Left Click"
2019-11-07 21:19:00.812 Status: dzVents: Info: Achtertuin - Zithoek: ------ Start internal script: Achtertuin - Zithoek: Device: "Zigate - lumi.remote.b286acn01_DButton_3-00158d00031360ed-01 (Zigate)", Index: 428
2019-11-07 21:19:00.813 Status: dzVents: Debug: Achtertuin - Zithoek: Processing device-adapter for Achtertuin: Zithoek: Switch device adapter
2019-11-07 21:19:00.813 Status: dzVents: Info: Achtertuin - Zithoek: Set lvl to 50 for 10 minutes.
2019-11-07 21:19:00.813 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 50
2019-11-07 21:19:00.813 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 1
2019-11-07 21:19:00.813 Status: dzVents: Debug: Achtertuin - Zithoek: Constructed timed-command: Set Level 1 AFTER 600 SECONDS
2019-11-07 21:19:00.813 Status: dzVents: Info: Achtertuin - Zithoek: ------ Finished Achtertuin - Zithoek
2019-11-07 21:19:00.998 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:19:01.153 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:19:03.208 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:19:03.402 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:19:03.357 Status: dzVents: Info: Handling events for: "Scene - Check scenes", value: "On"
2019-11-07 21:19:04.419 (Zigate) UpdateDevice - (Achtertuin: Zithoek Links) 1:50
2019-11-07 21:19:08.815 (Zigate) UpdateGroup - (Achtertuin: Zithoek) 1:41
2019-11-07 21:19:09.019 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:19:11.050 (Dummy) Light/Switch (Scene - Check scenes)
2019-11-07 21:19:11.285 (Dummy) Light/Switch (Scene - Check scenes)

-------

2019-11-07 21:27:01.487 (zwave) General/kWh (Badkamer: Ventilator - kWh Meter)
2019-11-07 21:27:02.483 (zwave) Usage (Badkamer: Ventilator - Usage)
2019-11-07 21:27:02.509 (zwave) General/kWh (Badkamer: Ventilator - kWh Meter)
2019-11-07 21:27:02.672 Status: dzVents: Info: Handling events for: "Badkamer: Ventilator - Usage", value: "0.0"
2019-11-07 21:27:03.462 (zwave) General/Voltage (Badkamer: Ventilator - Voltage)
2019-11-07 21:27:04.468 (zwave) Current (Badkamer: Ventilator - Unknown)
2019-11-07 21:30:02.881 Status: setcolbrightnessvalue: ID: fe, bri: 30, color: '{m: 2, RGB: 000000, CWWW: 0000, CT: 198}'
2019-11-07 21:30:03.684 Status: setcolbrightnessvalue: ID: 1a6, bri: 30, color: '{m: 2, RGB: 000000, CWWW: 0000, CT: 198}'
2019-11-07 21:30:04.151 (Zigate) UpdateDevice - (Woonkamer: Dressoir) 1:30
2019-11-07 21:30:07.292 (zwave) Lux (Achtertuin: Lux (PIR))
2019-11-07 21:30:07.370 (zwave) Lux (Achtertuin: Lux (PIR))
2019-11-07 21:30:07.474 Status: dzVents: Info: Handling events for: "Achtertuin: Lux (PIR)", value: "0"
2019-11-07 21:30:07.622 Status: dzVents: Info: Handling events for: "Achtertuin: Lux (PIR)", value: "0"
2019-11-07 21:30:08.298 (Zigate) UpdateGroup - (Woonkamer: Spot uitbouw) 1:30
2019-11-07 21:30:08.456 Status: dzVents: Info: Handling events for: "Woonkamer: Spot uitbouw", value: "On"
2019-11-07 21:30:10.520 (Dummy) Light/Switch (Scene - Check scenes)
With 1 minute delay I see at the expected time:
2019-11-07 21:17:04.137 Status: dzVents: Info: Handling events for: "Achtertuin: Zithoek", value: "On"
2019-11-07 21:17:05.639 (Zigate) UpdateDevice - (Achtertuin: Zithoek Links) 1:1

With 10 minute delay I see nothing
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem

Post by ronaldbro »

Just thought of a possible cause. I disabled all the script containing cancelQueuedCommands and the the 10 minute delay worked fine.

Going to test a bit further with that
ronaldbro
Posts: 327
Joined: Thursday 15 November 2018 21:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: AfterMin problem  [Solved]

Post by ronaldbro »

Found it waaren, it was indeed a misplaced cancelQueuedCommands :(

I made my own 'Scene control' script which includes a function to change the color of some lights. For neutral white to warm white during the evening. This function iterates through all my defined scenes and changes the color temp and dim level when the desired setpoint is 'auto'. The misplaced cancelQueuedCommands was called for every device which is in a scene and not only for the devices which need to be updated.
The troubled lights were part of a scene and got a cancelQueuedCommand every 5 minutes.

That's why short delays worked and 5 minutes or greater didn't. (Although short commands should also have failed some times, but I was lucky in my tests I guess)

Sorry for wasting your time on this issue. But many thanks anyway :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest