Script limit notifications  [Solved]

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

Moderator: leecollings

Post Reply
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script limit notifications

Post by Nefsolive »

Hello,

the script I send below, verifies an energy value and sends a message by pushover.
The problem is that if the value is always above, every minute sends a notification! Is there any way to send in this script for example, 3 notifications max ? And not minute by minute.

Ty

Code: Select all

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

    execute = function(domoticz)
        local floatFormat =  '%d*%.*%d*'
        local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
        local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))
        
    
        if EnergiaConsumida >= 3200 then
            local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
                    domoticz.notify("⚡ VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
        end
    end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script limit notifications

Post by waaren »

Nefsolive wrote: Friday 15 January 2021 19:22 the script I send below, verifies an energy value and sends a message by pushover.
One way to solve that is in below example

Code: Select all

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

    data =
    {
        notificationCounter =
        {
            initial = 0,
        },
        lastNotification =
        {
            initial = 0,
        },
    },

    execute = function(domoticz)
        local floatFormat =  '%d*%.*%d*'
        local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
        local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))

       if EnergiaConsumida >= 3200 and ( domoticz.data.lastNotification < ( os.time() + 900 )) then -- max once per 15 minutes
            local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
            domoticz.notify("⚡  VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
            domoticz.data.lastNotification = os.time()
            domoticz.data.notificationCounter = domoticz.data.notificationCounter + 1
            if domoticz.data.notificationCounter > 3 then
                domoticz.data.lastNotification = os.time() + 3600 * 12 -- Delay next message for 12 hours
                domoticz.data.notificationCounter = 0
            end
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script limit notifications

Post by Nefsolive »

waaren wrote: Friday 15 January 2021 20:46
Nefsolive wrote: Friday 15 January 2021 19:22 the script I send below, verifies an energy value and sends a message by pushover.
One way to solve that is in below example

Code: Select all

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

    data =
    {
        notificationCounter =
        {
            initial = 0,
        },
        lastNotification =
        {
            initial = 0,
        },
    },

    execute = function(domoticz)
        local floatFormat =  '%d*%.*%d*'
        local rawEnergiaConsumida = domoticz.devices('Energia Consumida').rawData[1]
        local EnergiaConsumida = tonumber(string.match(rawEnergiaConsumida, floatFormat))

       if EnergiaConsumida >= 3200 and ( domoticz.data.lastNotification < ( os.time() + 900 )) then -- max once per 15 minutes
            local textmensagem = "A voltagem " .. EnergiaConsumida .. " Watt, está muito ALTA! O disjuntor pode disparar!"
            domoticz.notify("⚡  VOLTAGEM ELECTRICA", textmensagem , domoticz.PRIORITY_HIGH, domoticz.SOUND_COSMIC, "" , domoticz.NSS_PUSHOVER)
            domoticz.data.lastNotification = os.time()
            domoticz.data.notificationCounter = domoticz.data.notificationCounter + 1
            if domoticz.data.notificationCounter > 3 then
                domoticz.data.lastNotification = os.time() + 3600 * 12 -- Delay next message for 12 hours
                domoticz.data.notificationCounter = 0
            end
        end
    end
}
Hello Waaren,
thanks for your reply!

I try and i have this error on log;

Code: Select all

scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script limit notifications

Post by waaren »

Nefsolive wrote: Friday 15 January 2021 22:00 I try and i have this error on log;

Code: Select all

scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
If you change os.time to os.time() it should work.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script limit notifications  [Solved]

Post by Nefsolive »

waaren wrote: Friday 15 January 2021 22:03
Nefsolive wrote: Friday 15 January 2021 22:00 I try and i have this error on log;

Code: Select all

scripts/dzVents/generated_scripts/Msg Potência Watt.lua:27: attempt to perform arithmetic on a function value (field 'time')
If you change os.time to os.time() it should work.
Waaren thanks,

os.time() Works!
And script, works like a charm!

Ty for always helping.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest