Hi Guys, I have the following battery check script, which sends a weekly email with the status of the batteries. The problem is, only the first 980 characters arrive in the e-mail. The rest is cut off. I have tried to send a mail via the Notification Center, where I can send over 1200 characters per mail. I do not understand why it works here and not in the script. With more than 25 battery devices this is a problem. Perhaps an LUA specialist can look at this and find a work around for this problem.. Thank you.
--[[
%% autostart
%% properties
%% globals
--]]
-- file: Batterystatus.lua
-- version: 0.03
-- purpose: Check the batteries and email status.
-- Batteries are checked once per week (Sunday on checktime)
-- Copyleft 03-2017 {jwi}
local sourceTrigger = fibaro:getSourceTrigger();
local oldnodeId = nil ;
local subject = "Battery status";
local userId = 2 -- primary email address
local checkday = 1 -- 1=Sunday 2=Monday ...
local checktime = "19:15"
local full = 100 --between 50 and 100 the battery status is assumed to be good
local warning = 50 --between 30 and 50 battery is running low
local critical = 25 --below 25 battery status is asumed as critical
local empty = 255 --probably a completely empty battery
Debug = function ( color, message )
fibaro:debug(string.format('<%s style="color:%s;">%s', "span", color, message, "span"))
end
devices = fibaro:getDevicesId({interfaces = {"battery"}, visible = true, enabled = true})
function checkBatteries()
local status = ' ' ;
local n = 0;
Debug('withe', os.date('%c'));
for id = 1, #devices do
local batteryLevel = fibaro:get(devices[id], 'batteryLevel')
local nodeId = fibaro:get(devices[id], 'nodeId')
if batteryLevel ~= nil and nodeId ~= nil
then
local name = fibaro:getName(devices[id])
if oldnodeId ~= nodeId then
local room = fibaro:getRoomNameByDeviceID(devices[id])
if not(room == "unassigned") then
n = n+1
if tonumber(batteryLevel) >= warning and tonumber(batteryLevel) <= full then
Debug('green', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' % OK')
status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % OK\n';
elseif
tonumber(batteryLevel) >= critical and tonumber(batteryLevel) <= warning then
Debug('yellow', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' % Warning')
status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % Warnung\n';
elseif
tonumber(batteryLevel) < critical then
Debug('red', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' %')
status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % Critical\n';
elseif
tonumber(batteryLevel) > full or tonumber(batteryLevel) == empty then
Debug('red', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' % probably empty!')
status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % Error\n';
end
end
end
oldnodeId = nodeId
end
end
status = status .. 'Checked on: ' .. os.date('%c') ..'\n'
status = status ..n.. ' devices were checked. '
Debug('withe', os.date('%c'));
Debug('withe', '------------------------------------------------------------')
Debug('withe', status)
fibaro:call(userId, "sendEmail", subject, status)
--fibaro:call(5, "sendEmail", subject, status)
local status = ' ';
end -- function
function main()
local currentDate = os.date("*t");
local currenthour = string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min)
local weekday = currentDate.wday
local startSource = fibaro:getSourceTrigger();
if (weekday == checkday) and currenthour == checktime then
checkBatteries()
end
setTimeout(main, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
main()
else
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (startSource["type"] == "other") then
checkBatteries()
end
end