Page 1 of 1

Why do I get two notifications 1 min apart with this script?

Posted: Saturday 07 May 2016 22:58
by SoerenBM
Hi everyone,

Can somebody clarify why I'm getting send two notifications with 1 minute apart with this script.

I thought the time script run once a minute and I use a time diff. that are within 90 secs between greater than and smaller than. So it should not be triggered twice within two runs?

Is it the script that is wrong or my understanding of scripts?

Thanks,
BR Søren

Code: Select all

-- script_time_garagedooopen.lua
-- script from https://www.domoticz.com/wiki/Event_script_examples#Send_a_warning_when_the_garage_door_has_been_open_for_more_than_10_minutes

Domoticz_Devicename = 'Garage | Port 2' 

t1 = os.time()
s = otherdevices_lastupdate[''..Domoticz_Devicename..'']
-- returns a date time like 2013-07-11 17:23:12
 
token = "xxx"
chatid = xxx
message = ''..Domoticz_Devicename..' har stået åbent i mere end 30 minutter!'

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 = {}
 
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
if (otherdevices[''..Domoticz_Devicename..''] == 'Open' and difference > 1800 and difference < 1890) then
    os.execute('curl --data chat_id='..chatid..' --data-urlencode "text='..message..'"  "https://api.telegram.org/bot'..token..'/sendMessage" ')
    print('<b style="color:Blue">'..message..' Send pushnotification</b>')
end

return commandArray

Re: Why do I get two notifications 1 min apart with this script?

Posted: Saturday 07 May 2016 23:21
by jvdz
The time between 2 script runs is 60 seconds so it has a high chance of being true twice.

Jos

Re: Why do I get two notifications 1 min apart with this script?

Posted: Sunday 08 May 2016 9:59
by SoerenBM
Thanks, Jos.

So if I set the time diff. to 60 secs. would that be the optimal?

If I set the time too low, lets say 30 or 45 secs. There is a risk not getting a notification. Is that correctly understood?


BR Søren

Sent using Tapatalk

Re: Why do I get two notifications 1 min apart with this script?

Posted: Sunday 08 May 2016 10:16
by jvdz
Yes correct, a test for 60 seconds should normally do it.

Jos

Re: Why do I get two notifications 1 min apart with this script?

Posted: Sunday 08 May 2016 10:34
by SoerenBM
I'll try that. Thank you


BR Søren

Sent using Tapatalk