A lot of push notifications

Moderator: leecollings

Post Reply
richardvd
Posts: 5
Joined: Saturday 18 February 2017 16:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

A lot of push notifications

Post by richardvd »

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?

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
Thanx for the reactions.

Greetz Richard,
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: A lot of push notifications

Post by jvdz »

richardvd wrote: How can i change the script so that i only get one push notification?
Not sure I understand as your code shows you have 2 type of notifications, one initial one and one as reminder.
How exactly and how often would you want these to be send?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
richardvd
Posts: 5
Joined: Saturday 18 February 2017 16:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: A lot of push notifications

Post by richardvd »

I want to receive 1 notification after 4 minutes and then a reminder every 5 minutes, until the door is closed.
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: A lot of push notifications

Post by jvdz »

Understood, so you want to make this a Time script. Have you set it to that in the internal editor?
That way it will only run one time per minute on the minute.
Guess it is now set to All which caused it to run with each change of a registered device.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
richardvd
Posts: 5
Joined: Saturday 18 February 2017 16:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: A lot of push notifications

Post by richardvd »

The LUA script is been written in the internal LUA editor of Domoticz.

Do you mean that i have to put the script to a file and than schedule it with a cron every minute?
Or do you mean something else?

I'm a newbie with LUA scripting, so excuse me if i ask stupid questions :-).
richardvd
Posts: 5
Joined: Saturday 18 February 2017 16:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: A lot of push notifications

Post by richardvd »

Now i understand, i have to change the event type from 'All' to 'Time'

I think it is working right now.., thank a lot Jos!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest