Fibaro weekelijkse batterij status e-mail

Because of the Fibaro bug in the battery email (that sends an e-mail every 30 minutes) We have made a virtual device that sends an e-mail with all the low battery devices and dead nodes. Now you only have to put the code in a virtual device and make a scene push the button once a week and you got your weekly battery summary mail :)

[code lang=”c”] —User settings——

–user id to send the e-mail to.
UserId = 50;
–battery percentage for it to show up as low battery.
lowBat = 35;

–end of settings—
–DO NOT CHANGE THE CODE BELOW

——————–Debugging Functions—————————–

function Debug( color, message )
fibaro:debug(string.format(‘<%s style="color:%s;">%s</%s>’, "span", color, message, "span"));
end

function StandardDebug( debugMessage )
if ( showStandardDebugInfo ) then
Debug( "white", debugMessage);
end
end

function ExtraDebug( debugMessage )
if ( showExtraDebugInfo ) then
Debug( "orange", debugMessage);
end
end

function ErrorDebug( debugMessage )
Debug( "red", "Error: " .. debugMessage);
end

function TestDebug(debugMessage )
Debug( "blue", "Testing: " .. debugMessage );
end
———————— Connection code ——————————

local response;
connection = Net.FHttp("127.0.0.1", 11111);

dataType = {
device = {get ="/api/devices/", put ="api/devices/" };
devices = {get ="/api/devices/", put ="api/devices/" };
heatingPanel = {get = "/api/panels/heating"};
heatingRoom = {get = "/api/panels/heating/", put ="/api/panels/heating/" };
room = {get = "/api/rooms/", put = ""};
notification = {get = "/api/panels/notifications/", put = "/api/panels/notifications/" };
}

getData = function( dataType, id )
getString = dataType.get .. id;
StandardDebug(getString);
response ,status, errorCode = connection:GET( getString );
fibaro:sleep(100)
ExtraDebug("status = " .. status);
ExtraDebug("errorCode = " .. errorCode);
local jsonTable = nill;
if (tonumber(status) == 200) then
jsonTable = json.decode(response);
end
return jsonTable;
end

function sendEmail(subject, content)
–first parameter is the user.
fibaro:call(UserId,"sendEmail", subject,content);
end

dev = getData(dataType.devices,"");
strlines = "";
lowBattDevices = "";
deadDevices = "";
emptyDevices = "";
fullDevices = "";

for i = 1, #dev do
batLevel = tonumber(dev[i].properties.batteryLevel);
deadValue = dev[i].properties.dead;
deviceName = tostring(dev[i].name);
if (dev[i].visible == true and ( batLevel == 0 or batLevel == 255 or batLevel ~= nil)) then
fibaro:debug("___: " .. deviceName .. "[" .. dev[i].id .. "]" .. batLevel);

if (deviceName ~= "Main_Zwave_Device" and deviceName ~= "Zwave Node: " .. dev[i].properties.nodeId ) then
prestr = "Device: " .. deviceName .. "[" .. dev[i].id .. "]";
if (deadValue == "true") then
strline = "Bat level: " .. batLevel .. " " .. prestr .. "\n";
deadDevices = deadDevices .. strline;
fibaro:debug(strline );
elseif (batLevel < lowBat) then
— below is low battery
strline = "Bat level: " .. batLevel .. "% " .. prestr .. "\n";
lowBattDevices = lowBattDevices .. strline;
fibaro:debug(strline );
elseif (deadValue ~= "true" and batLevel == 255 ) then
batLevel = 0;
prestr = "Device: " .. deviceName .. "[" .. dev[i].id .. "]";
strline = prestr .. "\n";
emptyDevices = emptyDevices .. strline;
fibaro:debug(strline);
end
–Devices that are empty (batt = 255) but not dead are not shown.
end
end
end

emailContent = "–Weekly summary– \n \n";

emailContent = emailContent .. "-Battery Status- \n";
emailContent = emailContent .. "Low Battery: \n";
emailContent = emailContent .. lowBattDevices .. " \n";
emailContent = emailContent .. "Empty Battery: \n";
emailContent = emailContent .. emptyDevices .. " \n";
emailContent = emailContent .. "Dead Nodes: \n";
emailContent = emailContent .. deadDevices .. "\n \n";

–emailContent = emailContent .. "Home Usage: \n";
–emailContent = emailContent .. "Not yet implemented ;)";

sendEmail("Weekly Home Summary",emailContent);

[/code]

De waardering van www.controlliving.nl bij Webwinkel Keurmerk Klantbeoordelingen is 9.4/10 gebaseerd op 22 reviews.