notification script in case of rain problem  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

notification script in case of rain problem

Post by djdevil »

Hi everyone I have this script that warns me in case of rain by sending a telegram notification, but I want this notification to arrive only once every 12 hours even if the sensor returns to the on phase after 10 minutes! I don't know why but it continually sends me the notification, where am I wrong thanks

Code: Select all

local scriptVar = 'Pioggia'

return
{
    on =
    {
        devices =
        {
            'Sensore Pioggia',
            -- change to name of device to monitor
        },
        customEvents =
        {
            scriptVar,
        },
    },

    data =
    {
       
        notificationsSend =
        {
                history = true,
                maxHours = 6,         -- Only 1 notification every 4 hours change to how many you want
        },
    logging =
    {
        level = domoticz.LOG_ERROR, -- change to doomticz.LOG_DEBUG when script works without issues
    }
    },

  

    execute = function(dz, item)
        
        local Presenza = dz.devices('Presenza')
        local Sensore = dz.devices('Sensore Pioggia')
        local buonanotte = dz.devices('Buonanotte')
      
       
        if dz.time.matchesRule('at 09:00-22:00') then
       
            if (Sensore.state == "On"  ) and ( dz.data.notificationsSend.sum() < 1 ) and (Presenza.state == "On") and (buonanotte.state == "Off")then
             
               	dz.notify("Meteo", 'Fuori sta piovendo', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)
                
               dz.executeShellCommand('/home/pi/domoticz/alexa_remote_control.sh -d "Zona Giorno" -e speak:"Attenzione fuori sta piovendo"')
               
              
             end
               
             
       
          end
                
            
        end
    
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: notification script in case of rain problem  [Solved]

Post by waaren »

djdevil wrote: Monday 10 May 2021 18:58 Hi everyone I have this script that warns me in case of rain by sending a telegram notification, but I want this notification to arrive only once every 12 hours even if the sensor returns to the on phase after 10 minutes! I don't know why but it continually sends me the notification, where am I wrong thanks
Can you try below version

Code: Select all

local scriptVar = 'Pioggia'

return
{
    on =
    {
        devices =
        {
            'Sensore Pioggia', -- change to name of device to monitor
        },
    },

    data =
    {

        notificationsSend =
        {
                history = true,
                maxHours = 12,         -- Only 1 notification every 12 hours change to how many you want
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to doomticz.LOG_ERROR when script works without issues
        marker = scriptVar,
    },

    execute = function(dz, item)
        local Presenza = dz.devices('Presenza')
        local Sensore = dz.devices('Sensore Pioggia')
        local buonanotte = dz.devices('Buonanotte')


        if dz.time.matchesRule('at 09:00-22:00') then
            if (Sensore.state == "On"  ) and ( dz.data.notificationsSend.sum() < 1 ) and (Presenza.state == "On") and (buonanotte.state == "Off")then
               dz.data.notificationsSend.add(1)
               dz.notify("Meteo", 'Fuori sta piovendo', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)
               dz.executeShellCommand('/home/pi/domoticz/alexa_remote_control.sh -d "Zona Giorno" -e speak:"Attenzione fuori sta piovendo"')
            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
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: notification script in case of rain problem

Post by djdevil »

waaren wrote: Monday 10 May 2021 19:35
djdevil wrote: Monday 10 May 2021 18:58 Hi everyone I have this script that warns me in case of rain by sending a telegram notification, but I want this notification to arrive only once every 12 hours even if the sensor returns to the on phase after 10 minutes! I don't know why but it continually sends me the notification, where am I wrong thanks
Can you try below version

Code: Select all

local scriptVar = 'Pioggia'

return
{
    on =
    {
        devices =
        {
            'Sensore Pioggia', -- change to name of device to monitor
        },
    },

    data =
    {

        notificationsSend =
        {
                history = true,
                maxHours = 12,         -- Only 1 notification every 12 hours change to how many you want
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to doomticz.LOG_ERROR when script works without issues
        marker = scriptVar,
    },

    execute = function(dz, item)
        local Presenza = dz.devices('Presenza')
        local Sensore = dz.devices('Sensore Pioggia')
        local buonanotte = dz.devices('Buonanotte')


        if dz.time.matchesRule('at 09:00-22:00') then
            if (Sensore.state == "On"  ) and ( dz.data.notificationsSend.sum() < 1 ) and (Presenza.state == "On") and (buonanotte.state == "Off")then
               dz.data.notificationsSend.add(1)
               dz.notify("Meteo", 'Fuori sta piovendo', dz.PRIORITY_NORMAL,dz.SOUND_DEFAULT, "" , dz.NSS_TELEGRAM)
               dz.executeShellCommand('/home/pi/domoticz/alexa_remote_control.sh -d "Zona Giorno" -e speak:"Attenzione fuori sta piovendo"')
            end
        end
    end
}
Waaren Now it works perfectly was that the problem? Thx

Code: Select all

 dz.data.notificationsSend.add(1)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: notification script in case of rain problem

Post by waaren »

djdevil wrote: Tuesday 11 May 2021 18:04 was that the problem? Thx

Code: Select all

 dz.data.notificationsSend.add(1)
Yes, your original script logic checked the amount of entries in this historical persistent variable but it was never populated.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: notification script in case of rain problem

Post by djdevil »

waaren wrote: Tuesday 11 May 2021 19:35
djdevil wrote: Tuesday 11 May 2021 18:04 was that the problem? Thx

Code: Select all

 dz.data.notificationsSend.add(1)
Yes, your original script logic checked the amount of entries in this historical persistent variable but it was never populated.
Thanks again waaren 8-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest