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

Moderator: leecollings

Post Reply
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

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

Post 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
User avatar
jvdz
Posts: 2287
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

The time between 2 script runs is 60 seconds so it has a high chance of being true twice.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

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

Post 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
User avatar
jvdz
Posts: 2287
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

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

Post by jvdz »

Yes correct, a test for 60 seconds should normally do it.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
SoerenBM
Posts: 34
Joined: Tuesday 22 March 2016 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5169
Location: Denmark
Contact:

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

Post by SoerenBM »

I'll try that. Thank you


BR Søren

Sent using Tapatalk
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest