Page 1 of 1
Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 12:22
by BakSeeDaa
The example script "check battery levels.lua" fails in dzVents 2.1 with the error message
Code: Select all
check battery levels.lua:28: attempt to concatenate upvalue 'message' (a nil value)
EDIT: Another issue, The script also reports wrong battery levels (0)
Cheers!
Re: Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 13:24
by dannybloe
Ah, indeed. However it is batteryLevel (lower-case b). But this should be the example:
Code: Select all
local BATTERY_THRESHOLD = 10
return {
active = true,
on = {
['timer'] = {
'every hour'
}
},
execute = function(domoticz)
local message = ''
-- first filter on low battery level
local lowOnBat = domoticz.devices().filter(function(device)
local level = device.batteryLevel -- level is 0-100
return (level ~= nil and -- not all devices have this attribute
level <= BATTERY_THRESHOLD)
end)
-- then loop over the results
lowOnBat.forEach(function(lowDevice)
message = message .. 'Device ' ..
lowDevice.name .. ' is low on batteries (' .. tostring(lowDevice.batteryLevel) .. '), '
end)
if (message) then
domoticz.notify('Low battery warning', message, domoticz.PRIORITY_NORMAL)
domoticz.log('Low battery warning: ' .. message, domoticz.LOG_ERROR)
end
end
}
I have fixed this in 2.2.0.
If you have some time then please can you test this 2.2.0 version (see my other post in the this forum).
Danny
Re: Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 13:48
by BakSeeDaa
Thanks!
I'm trying your script.
It reports low battery levels (0) for a couple of devices who has plenty of juice left. For example this device:
Code: Select all
{
"ActTime" : 1501069616,
"ServerTime" : "2017-07-26 13:46:56",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 0.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 85,
"CustomImage" : 0,
"Data" : "Off",
"Description" : "",
"Favorite" : 0,
"HardwareID" : 5,
"HardwareName" : "MySensors",
"HardwareType" : "MySensors Gateway USB",
"HardwareTypeVal" : 41,
"HaveDimmer" : false,
"HaveGroupCmd" : false,
"HaveTimeout" : false,
"ID" : "00000006",
"Image" : "Light",
"IsSubDevice" : false,
"LastUpdate" : "2017-07-26 13:30:03",
"Level" : 100,
"LevelInt" : 100,
"MaxDimLevel" : 100,
"Name" : "A580 IP",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"Status" : "Off",
"StrParam1" : "",
"StrParam2" : "",
"SubType" : "AC",
"SwitchType" : "On/Off",
"SwitchTypeVal" : 0,
"Timers" : "false",
"Type" : "Light/Switch",
"TypeImg" : "lightbulb",
"Unit" : 5,
"Used" : 1,
"UsedByCamera" : false,
"XOffset" : "0",
"YOffset" : "0",
"idx" : "596"
}
],
"status" : "OK",
"title" : "Devices"
}
Re: Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 13:57
by dannybloe
Can you put dzVents in debug mode logging and then check domoticzData.lua in /path/to/domoticz/scripts/dzVents?
Re: Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 15:57
by BakSeeDaa
At first I had some MySensors nodes that I needed to recreate because they were inaccessible due to that their type changed.
After replacing them I ran your script and it reported the old devices (that I already deleted), not the new ones that I created.
After setting debug mode the domoticzData.lua was updated with fresh data and the battery levels reported seems OK now.
Maybe you'd need to change this
to
Thanks!
Re: Example script "check battery levels.lua" fails
Posted: Wednesday 26 July 2017 16:08
by dannybloe
Indeed!
Re: Example script "check battery levels.lua" fails
Posted: Thursday 27 July 2017 8:12
by BakSeeDaa
dannybloe wrote:If you have some time then please can you test this 2.2.0 version (see my other post in the this forum).
Danny
Sure thing! I'm still struggling though to migrate all my scripts from 1.0. I will give it a try soon.
Cheers!