Page 1 of 1

Battery status of Kerui D026

Posted: Monday 20 April 2020 23:01
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?

Re: Battery status of Kerui D026

Posted: Monday 20 April 2020 23:57
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
}

Re: Battery status of Kerui D026

Posted: Tuesday 21 April 2020 23:28
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)

Re: Battery status of Kerui D026

Posted: Tuesday 21 April 2020 23:41
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

Re: Battery status of Kerui D026

Posted: Wednesday 22 April 2020 0:44
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!

Re: Battery status of Kerui D026  [Solved]

Posted: Wednesday 29 April 2020 18:46
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.