Take an action only once if a certain threshold has been reached  [SOLVED]

Moderator: leecollings

Post Reply
jefstevens
Posts: 3
Joined: Saturday 30 May 2020 18:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Take an action only once if a certain threshold has been reached

Post by jefstevens »

As a newbie I cannot figure this one out so any tips/ideas are more than welcome…

I am monitoring my Solar panel production and I would like to be notified for every step of 10 kWh my solar production increases.
Since I am planning to be informed with a Telegram message this should only happen once with every “block of 10” increase.
I am checking my Solar production (among other things) every 10 minutes with a DzVents script.

I suppose I need to keep variables with their "current" value in between multiple runs of the dzVents script, i.e. var10, var20, var30,… are initialised at 0 at the start of a new day, and when the production reaches 10 kWh var10 = 1 and a message “10 kWh reached” will be send and will, that day, not be send again. Once production reaches 20 kWh var20 = 1, a message “20 kWh reached” will be send and will, that day, not be send again, etc…. I guess you all get the idea…

I guess only 1 variable could suffice as well, where the variable value evolves from 1 to 10, to 20, etc and the variable value is the message to be send.

Any suggestions, ideas on how to tackle this?

Thanks!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Take an action only once if a certain threshold has been reached

Post by waaren »

jefstevens wrote: Saturday 30 May 2020 18:57 Any suggestions, ideas on how to tackle this?
What is the type and subtype of the Solar panel production device? (look at the devices tab)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jefstevens
Posts: 3
Joined: Saturday 30 May 2020 18:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Take an action only once if a certain threshold has been reached

Post by jefstevens »

Thanks for trying to help me!

type = General, subtype = kWh

I have no clue whether this is relevant or not but in the "Utility" tab I see the Solar block, with Log, Edit and Notifications. If I zoom in on Notifications the 2 types I can see are "Usage" and 'Last Update"
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Take an action only once if a certain threshold has been reached

Post by waaren »

jefstevens wrote: Sunday 31 May 2020 10:23 type = General, subtype = kWh
below script should do it.

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

--  solarMessages Should work in dzVents >= 2.4

--------- Your settings below this line -- 

    local solarProductionDevice = 'Enphase production'
    local messageFrequency = 1000 -- in Watt
    local resetTime = 'at 01:07' -- a time that will always be after sunset and before sunrise 

--------- No changes required below this line

return
{
    on =
    {
        timer =
        {
            'every 10 minutes at daytime',
            resetTime,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- set to domoticz.LOG_ERROR when OK
    },

    data =
    {
        messageSend = { initial = 0 },
    },

    execute = function(dz)
        local solarProductionToday = dz.devices(solarProductionDevice).WhToday

        if dz.time.matchesRule(resetTime) then
            dz.data.initialize('messageSend')
        else
            dz.log('Produced today :' .. dz.utils.round(solarProductionToday / 1000,3 ) .. ' kWh', dz.LOG_DEBUG)
            local divider = math.floor( solarProductionToday / messageFrequency )
            if dz.data.messageSend == 0 then 
                dz.data.messageSend = divider
            elseif divider > dz.data.messageSend then
                dz.notify('solar production','And another ' .. ( messageFrequency / 1000 ).. ' kWh!',dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM )
                dz.data.messageSend = divider
            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
jefstevens
Posts: 3
Joined: Saturday 30 May 2020 18:51
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Take an action only once if a certain threshold has been reached  [SOLVED]

Post by jefstevens »

Thanks, also for the tips!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest