I have a few sensors that should run on 2 x AAA batteries (alkaline) so obvisously the start voltage is 3v or a bit more. These zigbee sensors don't have a separate widget in the utility tab for battery percentage or voltage so I either need to look at the device in the device list or rely on the low batt warning set point of 20% which is fine for all my other devices. As I'm actually running these sensors on a pair of NiMh cells the initial voltage is high enough to see 100% state but quickly drops to 75%, due to the discharge curve of NiMh cells it stays here for quite a while until suddenly dropping to about 30%. I want to get a warning at this point so added a dummy battery device which I update with this script, I pull the battery state from the device IDX and put it in my dummy sensor, from there I can monitor it how I wish. This was working absolutely fine until about 3 or 4 weeks ago, I'm not sure which beta update point it was but it started to not update or update randomly. Currently the update rate is set to every 5 mins so i can try and see how long it takes before it reads a correct value.
Code: Select all
return {
on = {
timer = { 'every 5 minutes' } -- This script will periodically update the battery level
},
execute = function(domoticz)
-- Fetch the battery level of the device from its IDX
local device = domoticz.devices(1234) -- IDX Device no.
local batteryLevel = device.batteryLevel
-- Virtual device IDX to display the battery state
local virtualDevice = domoticz.devices(1301)
if virtualDevice then
virtualDevice.updateCustomSensor(batteryLevel)
else
domoticz.log('Utility device "Battery Status" not found!', domoticz.LOG_ERROR)
end
end
}
A prime example is this moring I noticed the batteries are low in this device, I replaced them with fully charged ones before 8am. Z2M says battery is 100%, the Domoticz device says it's 100% but even though my script is showing no errors and running every 5 mins my dummy device stills says the battery is at 5% and its now 8:20am, at some point today it will update but it should have done so already. When the script runs you can see the widget blink so I know its being written to, I just don't understand where it is getting the old value from.
Thanks