Code: Select all
check battery levels.lua:28: attempt to concatenate upvalue 'message' (a nil value)
Cheers!
Moderator: leecollings
Code: Select all
check battery levels.lua:28: attempt to concatenate upvalue 'message' (a nil value)
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
}
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"
}
Code: Select all
if (message) then
Code: Select all
if (message ~= '') then
Sure thing! I'm still struggling though to migrate all my scripts from 1.0. I will give it a try soon.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
Users browsing this forum: No registered users and 1 guest