Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,


as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.


As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!



Smart Home Forum by FIBARO Team

  • 0

Problem with batterie check script



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"))
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
       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';
               tonumber(batteryLevel) >= critical and tonumber(batteryLevel) <= warning then
               Debug('yellow', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' % Warning')
               status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % Warnung\n';
               tonumber(batteryLevel) < critical  then
               Debug('red', "Battery " ..name..' ('..room..') - Battery: '..batteryLevel..' %')
               status = status .. n .. ") " ..name..' ('..room..') ' ..batteryLevel..' % Critical\n';
               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';
       oldnodeId = nodeId
  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
    setTimeout(main, 60*1000)
if (sourceTrigger["type"] == "autostart") then
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (startSource["type"] == "other") then



Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

simple fix: do not send all information, but only from batteries that are empty or nearly empty.

bit more complex fix: send multiple emails with e.g. 10 modules each



Link to comment
Share on other sites

  • 0
  • Inquirer
  • @tinman

    Thanks for the answer, but I'm sorry, it does not satisfy me.

    For some reasons I do not want to use the simple solution. ( In the past I had battery devices that fell in a week from 70% to 0% ),

    and for  the second, it is not a problem for me to build a version which sends several emails. But I do not like that.

    Because Notification Center can send larger emails I hope for a solution with lua. Perhaps there is a limit to the size of a local variable in LUA.

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    • Create New...