Energy Meter and Notifications  [Solved]

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

Moderator: leecollings

Post Reply
Feybio
Posts: 7
Joined: Thursday 14 July 2016 11:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Energy Meter and Notifications

Post by Feybio »

Hi all :)

My energy supplier turns off the power if I exceed 3990 Watt for more than 2 minutes.
I created a Telegram notification to be alerted if this happens and works perfectly.
The energy meter reads the value every 5 seconds, the problem is as follows:

Values:
3512
3670
4001 (telegram notification)
3847
3798

As soon as I exceed the set value (3990) I am warned even if the subsequent values indicate that it was only a peak.
Is there a way, via script (lua, blokly ...), to receive the notification only if 2 or more consecutive values are greater than 3990 watts?

Thank you.
Raspberry Pi 3 and Pi 4 - Pi Camera - DS18B20 - HC-SR501 - FGMS-001 - Telegram Bot
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy Meter and Notifications

Post by waaren »

Feybio wrote: Monday 03 August 2020 8:55 My energy supplier turns off the power if I exceed 3990 Watt for more than 2 minutes.
I created a Telegram notification to be alerted if this happens and works perfectly.

As soon as I exceed the set value (3990) I am warned even if the subsequent values indicate that it was only a peak.
Is there a way, via script (lua, blokly ...), to receive the notification only if 2 or more consecutive values are greater than 3990 watts?
Could look like

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Power', -- Change to name of your smartmeter
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'managed notification',
    },

    data =
    {
        consecutiveHighReads =
        {
            initial = 0,
        },
    },

    execute = function(dz, item)
        local alertFence = 3990 -- change to your higfence
        local maxConsecutiveReadings = 2 -- change to max number of consecutive high reading.

        if item.usage > alertFence then
            dz.data.consecutiveHighReads = dz.data.consecutiveHighReads + 1
            if dz.data.consecutiveHighReads == maxConsecutiveReadings then
                dz.notify('Smartmeter','Power usage too high ( > ' .. alertFence .. ' ) for ' .. maxConsecutiveReadings .. ' consecutive readings.',nil,nil,nil,dz.NSS_TELEGRAM)
            end
        elseif dz.data.consecutiveHighReads > 0 then
            dz.data.consecutiveHighReads = 0
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Feybio
Posts: 7
Joined: Thursday 14 July 2016 11:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Energy Meter and Notifications

Post by Feybio »

Thank you, i got an error on line 29

if item.usage > alertFence then

2020-08-03 11:06:21.609 Error: dzVents: Error: (3.0.2) managed notification: ...Domoticz/scripts/dzVents/generated_scripts/Script #1.lua:29: attempt to compare number with nil
Raspberry Pi 3 and Pi 4 - Pi Camera - DS18B20 - HC-SR501 - FGMS-001 - Telegram Bot
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy Meter and Notifications

Post by waaren »

Feybio wrote: Monday 03 August 2020 11:06 2020-08-03 11:06:21.609 Error: dzVents: Error: (3.0.2) managed notification: ...Domoticz/scripts/dzVents/generated_scripts/Script #1.lua:29: attempt to compare number with nil
I assumed you energy meter is a smart meter. If you get this error it obviously is another type / subtype. Can you look at the devices tab to see what the device type and subtype of your energy meter is ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Feybio
Posts: 7
Joined: Thursday 14 July 2016 11:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Energy Meter and Notifications

Post by Feybio »

Raspberry Pi 3 - Buster
Domoticz 2020.2
AEON Labs ZW090 Z-Stick Gen5 EU
AEON Labs DSB28 Home Energy Meter (2nd Edition)
Attachments
Watts.png
Watts.png (36.81 KiB) Viewed 1053 times
Raspberry Pi 3 and Pi 4 - Pi Camera - DS18B20 - HC-SR501 - FGMS-001 - Telegram Bot
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy Meter and Notifications

Post by waaren »

Feybio wrote: Monday 03 August 2020 11:40 Raspberry Pi 3 - Buster
Domoticz 2020.2
AEON Labs ZW090 Z-Stick Gen5 EU
AEON Labs DSB28 Home Energy Meter (2nd Edition)
Thx. Can you try with this one?

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Watts', -- Change to name of your smartmeter
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'managed notification',
    },

    data =
    {
        consecutiveHighReads =
        {
            initial = 0,
        },
    },

    execute = function(dz, item)
        local alertFence = 3990 -- change to your higfence
        local maxConsecutiveReadings = 2 -- change to max number of consecutive high reading.

        if item.actualWatt > alertFence then
            dz.data.consecutiveHighReads = dz.data.consecutiveHighReads + 1
            if dz.data.consecutiveHighReads == maxConsecutiveReadings then
                dz.notify('Smartmeter','Power usage too high ( > ' .. alertFence .. ' ) for ' .. maxConsecutiveReadings .. ' consecutive readings.',nil,nil,nil,dz.NSS_TELEGRAM)
            end
        elseif dz.data.consecutiveHighReads > 0 then
            dz.data.consecutiveHighReads = 0
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Feybio
Posts: 7
Joined: Thursday 14 July 2016 11:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Energy Meter and Notifications  [Solved]

Post by Feybio »

Thanks a lot waaren, your script work perfectly!

Edit:
I need pls your help for the last implementation...
Its possibile to add another line after the notification is triggered that excecut a python script with a passed variable (actualWatt)?

Something like this:
- dz.notify('Smartmeter','Power usage too high ( > ' .. alertFence .. ' ) for ' .. maxConsecutiveReadings .. ' consecutive readings.',nil,nil,nil,dz.NSS_TELEGRAM)
- python /home/pi/Allarm/Script.py "item.actualWatt"

Sorry i'm very new to DzVents.
Raspberry Pi 3 and Pi 4 - Pi Camera - DS18B20 - HC-SR501 - FGMS-001 - Telegram Bot
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Energy Meter and Notifications

Post by waaren »

Feybio wrote: Tuesday 04 August 2020 7:52 I need pls your help for the last implementation...
Its possibile to add another line after the notification is triggered that excecut a python script with a passed variable (actualWatt)?
Yes, could be something like

Code: Select all

return
{
    on =
    {
        devices =
        {
            'Watts', -- Change to name of your energy meter
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all ok
        marker = 'managed notification',
    },

    data =
    {
        consecutiveHighReads =
        {
            initial = 0,
        },
    },

    execute = function(dz, item)
        local alertFence = 3990 -- change to your highfence
        local maxConsecutiveReadings = 2 -- change to max number of consecutive high reading.

        if item.actualWatt > alertFence then
            dz.data.consecutiveHighReads = dz.data.consecutiveHighReads + 1
            if dz.data.consecutiveHighReads == maxConsecutiveReadings then
                dz.notify('Smartmeter','Power usage too high ( > ' .. alertFence .. ' ) for ' .. maxConsecutiveReadings .. ' consecutive readings.',nil,nil,nil,dz.NSS_TELEGRAM)
                local cmd = 'python /home/pi/Allarm/Script.py ' .. item.actualWatt .. ' &'
                os.execute(cmd)
            end
        elseif dz.data.consecutiveHighReads > 0 then
            dz.data.consecutiveHighReads = 0
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest