A lot of push notifications
Posted: Saturday 18 February 2017 16:51
Hello,
The script below send me an push notification when my garage is open for more then 4 minuten.
unfortunately i get a lot of push notifications (about 30-60 in one minute).
How can i change the script so that i only get one push notification?
Thanx for the reactions.
Greetz Richard,
The script below send me an push notification when my garage is open for more then 4 minuten.
unfortunately i get a lot of push notifications (about 30-60 in one minute).
How can i change the script so that i only get one push notification?
Code: Select all
sensors = {'Garagedeur'}
-- All times in minutes
firstWarningTimeMinutes = 4
-- Then repeat every .. minutes
repeatTimeMinutes = 5
-- First %s is the sensor name, the second one the time in minutes
firstWarningMessage = 'Info#Let op, "%s" staat al meer dan %s minuten open!'
repeatWarningMessage = 'Waarschuwing#LET OP, "%s" nog steeds open! Tijd open: %s minuten!!'
-- Don't edit below this line
firstWarningTime = firstWarningTimeMinutes * 60
repeatTime = repeatTimeMinutes * 60
timeNow = os.time()
commandArray = {}
for index,sensor in pairs(sensors) do
s = otherdevices_lastupdate[sensor]
-- 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)
timeLastOpened = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (timeNow, timeLastOpened))
if (otherdevices[sensor] ~= 'Open' or difference < firstWarningTime) then
-- Door closed or within margin
return commandArray
end
if (difference <= (firstWarningTime + 60)) then
-- First warning
commandArray['SendNotification'] = string.format(firstWarningMessage, sensor, tostring(firstWarningTimeMinutes))
else
offset = (difference - firstWarningTime) % repeatTime
if offset > 0 and offset <= 60 then
commandArray['SendNotification'] = string.format(repeatWarningMessage, sensor, tostring(math.floor(difference / 60)))
end
end
end
return commandArray
Greetz Richard,