Page 1 of 1

Time-triggered scripts stop working after 2 days

Posted: Thursday 03 June 2021 12:42
by Maikel76
Hi everyone,

I'm trying to solve this issue for few weeks now and really need your help and expertise
I'm running Domoticz version:
Version: 2020.2
Build Hash: b63341bc0
Compile Date: 2020-04-26 18:47:55
dzVents Version: 3.0.2
Python Version: 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]

Some background:
I have a Holiday-switch, a sleep-scene that triggers a sleep-switch and according to those states the script should execute certain things different. This seems to work for all device-triggered events. Then according to e.g. holiday mode the script needs to execute a command with the

Code: Select all

at('10:00 on mon-fri')
for instance. That time-based event doesn't seem to work always.
Also i have a seperate script for daytime hours (defined by myself) and nighttime hours (also defined myself) with the rule:

Code: Select all

(domoticz.time.matchesRule('at 09:00-22:00 on mon-fri')
When i save the script this seems to work like a charm, at least for one or two days, then suddenly it doesn't work anymore
I then programmed a small script to clear all queued commands for all those devices but this also doesn't seem to make any difference.
I reprogrammed the 2 scripts (Day and Night) with seperate if-statements for device and time-triggered events, this does makes sure that the right script executes at the right time, but the timed commands still only execute the first two days

I'm probably doing something wrong or these funtionalties only work with the newer dzVents version (I'm still running the old version, not ready to update to newest stable yet)

Here the Day script (the night-script works in the same way but different times);

Code: Select all

return {
	on = {
		devices = {'Home',
		           'Music',
		           'Holiday',
		           'Sleep'
		          },
		timer = {'at 9:00-22:00 on mon-fri',
		         'at 10:00-22:00 on sat-sun'
		        },
		variables = {},
		scenes = {},
		groups = {},
		security = {},
		httpResponses = {},
		customEvents = {},
		system = {},
	},
	data = {},
	logging = {},
	execute = function(domoticz, item)
      local someone=domoticz.devices('Home')      -- some one home
      local holiday=domoticz.devices('Holiday')   -- holiday 
      local sleep=domoticz.devices('Sleep')       -- helpswitch gotosleep scene 
      local catdoor=domoticz.devices('CatDoor')   -- Catdoor
      local fountain=domoticz.devices('Fountain') -- Fountain
      local music=domoticz.devices('Music')       -- Music player
      local mtext=domoticz.devices('MusicInfo')   -- Music player info text        
      local salt=domoticz.devices('Salt')         -- Salt light
      -- TIME TRIGGER
      if (item.isTimer) then    -- or (item.name == 'Holiday') or (item.isTimer and item.name == 'Home') or (item.isTimer and item.name == 'Sleep') or (item.isTimer and item.name == 'Music')) then
        -- holiday fountain 
        if (holiday.state == 'Off' and fountain.state == 'Off') then
            fountain.switchOn().at('10:00') --.withinMin(20)
        end   
        --domoticz.log('color VALUE: '..someone.color)
        --domoticz.log('nValue VALUE: '..someone.nValue)
        --domoticz.log('holiday VALUE: '..holiday.state)
        --domoticz.log('music VALUE: '..music.levelName)
        --domoticz.log('catdoor VALUE: '..catdoor.state)
        -- holiday music allways
        if (holiday.state == 'On') then
            music.switchSelector('START').at('10:00 on mon-fri') --.withinMin(20)
            music.switchSelector('START').at('12:00 on sat-sun') --.withinMin(20)
        end  
        -- holiday salt        
        if (holiday.state == 'Off' and salt.state == 'Off') then
            salt.switchOn().at('13:57')
        end
      end
      -- DEVICE TRIGGER    
      if (item.isDevice and (domoticz.time.matchesRule('at 09:00-22:00 on mon-fri') or domoticz.time.matchesRule('at 10:00-22:00 on sat-sun'))) then
        -- holiday catdoor 
        if (item.name == 'Home' or item.name == 'Holiday') then
          if (holiday.state == 'Off' and catdoor.state == 'Off' and someone.color == 1) then 
            catdoor.switchOn()                       --someone.lastUpdate.minutesAgo >= delay and
          end
        end  
        if (item.name == 'Sleep' or item.name == 'Holiday') then
          if ((holiday.state == 'On' or sleep.state == 'On') and catdoor.state == 'On') then
            catdoor.switchOff()
          end    
        end 
        -- holiday music allways
        if (item.name == 'Home') then
          if (holiday.state == 'Off' and music.levelName == 'STOP' and someone.color == 1) then --someone.lastUpdate.secondsAgo <= 60 and
            music.switchSelector('START')
          end
        end
        -- holiday salt
        if (item.name == 'Holiday') then
          if (holiday.state == 'On' and salt.state == 'On') then
            salt.switchOff()
          end
        end        
        -- update music info
        if (item.name == 'Music') then
          local command = '/home/pi/domoticz/scripts/bashscrips/readmusic.sh info'
	      local handle = io.popen(command)
          local resultinfo = handle:read("*a")
          handle:close()
          mtext.updateText(resultinfo)          
        end  
      end      
  end  
}
I also see some message in the Debug log about a CONSTRUCTED TIME-based command where it seems to count down until the time that switch needs to trigger, that's why i thought about cancelling any queued commands. This script is doing that at 3:00 am every day;

Code: Select all

return {
	on = {
		devices = {},
		timer = {'at 3:00'},
		variables = {},
		scenes = {},
		groups = {},
		security = {},
		httpResponses = {},
		customEvents = {},
		system = {},
	},
	data = {},
	logging = {},
	execute = function(domoticz, item)
	    local someone=domoticz.devices('Home')      -- some one home
            local music=domoticz.devices('Music')       -- Music player
            local holiday=domoticz.devices('Holiday')   -- holiday 
            local sleep=domoticz.devices('Sleep')       -- helpswitch gotosleep scene 
            local catdoor=domoticz.devices('CatDoor')   -- Catdoor
            local fountain=domoticz.devices('Fountain') -- Fountain
            local tv=domoticz.devices('TV')             -- TV light
            local salt=domoticz.devices('Salt')         -- Salt light         
            local maikel=domoticz.devices('Maikel')     -- Maikel home switch      
            local earn=domoticz.devices('Earn')         -- Earn home switch    
            someone.cancelQueuedCommands()              -- cancel all queued commands
            music.cancelQueuedCommands()  
            holiday.cancelQueuedCommands()  
            sleep.cancelQueuedCommands()  
            catdoor.cancelQueuedCommands()  
            fountain.cancelQueuedCommands()  
            tv.cancelQueuedCommands()  
            salt.cancelQueuedCommands()  
            maikel.cancelQueuedCommands()  
            earn.cancelQueuedCommands()  
	end
}
Really hope someone can help me with this, it's driving me insane :shock:

Re: Time-triggered scripts stop working after 2 days

Posted: Tuesday 08 June 2021 10:43
by Maikel76
Nobody any clue or direction ?

I found out that what I save another/any script, Domoticz log mentions "Status: EventSystem: reset all events.."
Is there a way to reset events with a command (dzVents, Lua or bash - level)?

Re: Time-triggered scripts stop working after 2 days

Posted: Thursday 10 June 2021 10:54
by Maikel76
I saw in the examples the method to first cancelQueuedCommands() right before sending a afterMin(10) request so I changed the Day- and Night script with this and disabled the general cancelQueuedCommands-script. I'll update here later. Hopeflully this does the trick, I'm going on holiday and otherwise I have to schedule timers in the devices themself which makes no sense when it should be possible with some cool scripts :D

Re: Time-triggered scripts stop working after 2 days

Posted: Sunday 18 July 2021 10:10
by Maikel76
Just updated to 2021.1
Hope problems resolved now 8-)

Re: Time-triggered scripts stop working after 2 days

Posted: Saturday 14 August 2021 6:44
by Maikel76
Update didn't solve the issue
What DID solve the issue was this
change this:

Code: Select all

on mon-fri
to this:

Code: Select all

on mon, tue, wed, thu, fri
For anyone having the same issue (took me 5 months to find out)