Page 1 of 1

A lot of push notifications

Posted: Saturday 18 February 2017 16:51
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,

Re: A lot of push notifications

Posted: Saturday 18 February 2017 17:05
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

Re: A lot of push notifications

Posted: Saturday 18 February 2017 18:00
by richardvd
I want to receive 1 notification after 4 minutes and then a reminder every 5 minutes, until the door is closed.

Re: A lot of push notifications

Posted: Saturday 18 February 2017 18:15
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

Re: A lot of push notifications

Posted: Saturday 18 February 2017 18:24
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 :-).

Re: A lot of push notifications

Posted: Saturday 18 February 2017 18:28
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!