Page 1 of 1

Timer scripts don't work if no devices change

Posted: Tuesday 12 December 2017 19:30
by Kasvand
I'm having an issue. It seems Domoticz only runs scripts when something changes somewhere. This means LUA scripts with timer functions don't work!

I created a LUA script that gives an alarm if a door remains open for more then a minute. The script itself works fine! However - the alarm doesn't sound if no device in my Domoticz set-up changes after this minute is reached.
It does work again when a device changes status, doesn't matter which device - can be a totally different device used in an entirely different script. But if nothing changes in my set-up it seems Domoticz falls asleep and timer functions alone won't wake Domoticz up...

Anyone know why this is? Is there a way to solve this? Been browsing through the settings, but found nothing that makes Domoticz fall asleep almost immediately from the moment no device changes no more.

Re: Timer scripts don't work if no devices change

Posted: Tuesday 12 December 2017 19:34
by jvdz
Is this an internal script created with the internal editor or a file in the script/lua directory?

Internal: What are the settings for the script at the right side of the window?
External file: What is the name of the script file?

Maybe you can show the script as well?

Jos

Re: Timer scripts don't work if no devices change

Posted: Tuesday 12 December 2017 19:36
by febalci
Did you by any chance leave 'All' or 'Device' in your script settings? I believe it should be 'Time' in Events settings page in order to execute time scripts.

Re: Timer scripts don't work if no devices change

Posted: Tuesday 12 December 2017 19:44
by Kasvand

Code: Select all

t1 = os.time()
s = otherdevices_lastupdate['Koelkast']
-- returns a date time like 2013-07-11 17:23:12

year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)

commandArray = {}

print (s)
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices['Koelkast'] == 'Open' and difference > 60 ) then
    print ("Koelkast open!")
    commandArray['MP3']='Set Level: 16'
end 
 
return commandArray
It's a script in Domoticz (no external file). I tried setting Device and Time and All.
With the setting 'All' it sortof works, except that the alarm triggers every millisecond and thus plays no sound at all.... :/

Update: With setting Time it does seem to work a bit - however this polls every minute. This means the alarm can have a delay of max. a minute.... Not really practical. But it does work. A bit....

Re: Timer scripts don't work if no devices change

Posted: Tuesday 12 December 2017 20:01
by jvdz
Kasvand wrote: Tuesday 12 December 2017 19:44 Update: With setting Time it does seem to work a bit - however this polls every minute. This means the alarm can have a delay of max. a minute.... Not really practical. But it does work. A bit....
That is the idea for the Time scripts, which are run every minute on the minute. :)

Jos