Proper way to limit notifications in DzVents?  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Proper way to limit notifications in DzVents?

Post by Jumper3126 »

Hi all

I have a script to control my greenhouse, which runs every minute. If the humidity or temp is critical, it should take action and inform me. But i dont want to get a message every minute till it is solved.

I now have this line to limit the number of notifications send to 1 in 15 minutes.

Code: Select all

if (domoticz.time.matchesRule('every 15 minutes')) then domoticz.notify('Too dry! Serre humidity <50%', domoticz.PRIORITY_HIGH) end
Is this a proper way to do so in DzVents, or is there a better solution to only receive the first notification and then stop sending for 15 minutes. What is the impact if I use this line for multiple, independent conditions that may happen the same time (like humidity is too low, but also temp is too high). Will the 15 minute limit apply to each line independently?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Proper way to limit notifications in DzVents?

Post by waaren »

Jumper3126 wrote: Friday 26 June 2020 9:39 Is this a proper way to do so in DzVents, or is there a better solution to only receive the first notification and then stop sending for 15 minutes.
You could do it like below

Code: Select all

 return
 {
    on =
    {
        timer =
        {
            'every minute',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
    },

     data =
     {
        notifications =
        {
             initial = {},
        },
    },

   execute = function( dz )

        local function managedNotification(id, message,interval,priority)
            local interval = interval or 15
            local priority = priority or dz.PRIORITY_HIGH
            if dz.data.notifications[id] == nil or dz.data.notifications[id] < dz.time.dDate then
                dz.notify('managedNotification -- [' .. id ..']', message, priority)
                dz.data.notifications[id] = dz.time.dDate + interval * 60
            end
        end

        managedNotification('greenhouse','Too dry! Serre humidity <50%')  -- using default interval and default priority
        managedNotification('living Room','Cold', 30 , dz.PRIORITY_LOW)   -- overriding defaults

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Proper way to limit notifications in DzVents?

Post by Jumper3126 »

Thanks waaren,
Do I understand correctly, that the interval counts per id? So in the example above, the timer for greenhouse and livingroom are independent. But if

Code: Select all

managedNotification
would have the same id, the second line would base its timer on the first line?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Proper way to limit notifications in DzVents?

Post by waaren »

Jumper3126 wrote: Sunday 28 June 2020 21:24 Thanks waaren,
Do I understand correctly, that the interval counts per id? So in the example above, the timer for greenhouse and livingroom are independent.
Yes

But if

Code: Select all

managedNotification
would have the same id, the second line would base its timer on the first line?
I don't understand this question. Please elaborate
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Proper way to limit notifications in DzVents?  [Solved]

Post by Jumper3126 »

Basically you already answered it with your YES :)

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest