Battery status of Kerui D026  [Solved]

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

Moderator: leecollings

Post Reply
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Battery status of Kerui D026

Post by gschmidt »

I have 2 Kerui D026 sensors controlled by an RFXtrx433 USB device.
In the Domoticz "Devices" list there is a battery level column which shows a battery symbol for this sensor device.

Is it possible to create a send a "low battery" notification to Telegram script with dzVents?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Battery status of Kerui D026

Post by waaren »

gschmidt wrote: Monday 20 April 2020 23:01 Is it possible to create a send a "low battery" notification to Telegram script with dzVents?
Below script check all devices with battery levels twice a day and send notification to telegram (if configured in domoticz settings) if batteryLevel is less then 20%

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 7:07',
            'at 19:07',
        },
    },

    logging =
    {
        level = domoticz.LOG_ERROR,
        marker = batteryLevels,
    },

    execute = function(dz)

        dz.devices().forEach(function(dv)
            if dv.batteryLevel and dv.batteryLevel < 20 then 
                dz.notify('Lowbatteries','Battery level of ' .. dv.name .. ' is ' .. dv.batteryLevel, dz.PRIORITY_NORMAL,'','',dz.NSS_TELEGRAM) 
            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
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Battery status of Kerui D026

Post by gschmidt »

waaren wrote: Monday 20 April 2020 23:57 Below script check all devices with battery levels twice a day and send notification to telegram (if configured in domoticz settings) if batteryLevel is less then 20%
Thanx!
Is this a double foreach method, like foreach device do foreach function?

Code: Select all

 dz.devices().forEach(function(dv)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Battery status of Kerui D026

Post by waaren »

gschmidt wrote: Tuesday 21 April 2020 23:28 Is this a double foreach method, like foreach device do foreach function?

Code: Select all

 dz.devices().forEach(function(dv)
Ehhhmm ?

Code: Select all

dz.devices() -- the collection of all devices in domoticz
foreach(function(dv) ) -- pass every device from above collection to the nameless function as parm dv
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
gschmidt
Posts: 200
Joined: Thursday 20 December 2018 11:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Battery status of Kerui D026

Post by gschmidt »

waaren wrote: Tuesday 21 April 2020 23:41
gschmidt wrote: Tuesday 21 April 2020 23:28 Is this a double foreach method, like foreach device do foreach function?

Code: Select all

 dz.devices().forEach(function(dv)
Ehhhmm ?

Code: Select all

dz.devices() -- the collection of all devices in domoticz
foreach(function(dv) ) -- pass every device from above collection to the nameless function as parm dv
Okay got it, thanx!
HvdW
Posts: 663
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Battery status of Kerui D026  [Solved]

Post by HvdW »

Hi,
I adapted the script @waaren created for more general use.

Code: Select all

local THRESHOLD = 20  -- battery level

return
{
    on =
    {
        timer =
        {
            --'every minute',
            'at sunset',
        },
    },

    execute = function(dz)

        dz.devices().forEach(function(dv)
            if dv.batteryLevel and dv.batteryLevel < THRESHOLD then 
                dz.notify('Lowbatteries','Battery level of ' .. dv.name .. ' is ' .. dv.batteryLevel, dz.PRIORITY_NORMAL) 
                dz.log('Battery level of ' .. dv.name .. ' is ' .. dv.batteryLevel, dz.LOG_INFO)
            elseif dv.batteryLevel and dv.batteryLevel >= THRESHOLD then
                dz.log('Battery level of ' .. dv.name .. ' is ' .. dv.batteryLevel, dz.LOG_INFO)
            end
        end)
    end
}
The 'every minute is for testing, just like the elseif which displays full batteries in the logs.
Notify can be used for push messages, mail and other.
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest