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?
Battery status of Kerui D026 [Solved]
Moderator: leecollings
- 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
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%gschmidt wrote: Monday 20 April 2020 23:01 Is it possible to create a send a "low battery" notification to Telegram script with dzVents?
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
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
Thanx!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%
Is this a double foreach method, like foreach device do foreach function?
Code: Select all
dz.devices().forEach(function(dv)- 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
Ehhhmm ?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)
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 dvDebian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
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
Okay got it, thanx!waaren wrote: Tuesday 21 April 2020 23:41Ehhhmm ?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)
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
-
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]
Hi,
I adapted the script @waaren created for more general use.
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.
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
}Notify can be used for push messages, mail and other.
Bugs bug me.
Who is online
Users browsing this forum: Google [Bot] and 1 guest