copyright 1998-2017 by Mark Verboom
ipv6 ready RSS Feed Schakel naar Nederlands

Go back to What's new

Check and email battery status

To blog index

Thursday, 26 June, 2014

Check and email battery status

After having found and tried a couple of setups to receive an email from the CCU when there are batteries that are low, I decided to write my own. The reason being that most weren't documented very well and all of them required the user to create a specific category for devices with batteries.

To start out you need the Email addon for the CCU, I have version 1.4 installed. To install, see the documentation on the Homematic-inside website:

http://www.homematic-inside.de/software/email

To generate a custom mail body for the email message there needs to be communication between the script code in the programm and the email addon. This is done through a system variable.

First we define the variable through the menu's:

Einstellungen -> Systemvariable

Below choose Neu to define a new variable.

Fill in the details as follows.

This wil define a new string variable with the name EmailText.

Now we need to setup the email configuration. Open the setup through the following menu's:

Einstellungen -> Systemsteuerung

Then choose the option

Zusatzsoftware

This should show the E-Mail addon you installed. In the line showing this add-on choose the optoin

Einstellen

Now go to the icon defined as

Tcl

In this tab I used the following code

load tclrega.so

array set values [rega_script {
var v3 = dom.GetObject("EmailText").Value();
} ]

set emailtext [encoding convertfrom utf-8 $values(v3)]

Which should look like this

Once defined, press the button Ubernehmen at the bottom of the screen.

Next we have to define an Email. Go to the tab

E-Mails

Choose an empty spot in the pull-down menu to define an email template. For me it is spot 4 that is being used to define the email for low battery warnings.

Below is an example of the configuration. Make sure you active the TCL for this email so the variable $emailtext will be expanded.

Press the button Ubernehmen to save the email.

Now that the email configuration is in place we need to define a program that will periodically check for devices that have a low battery and send an email when it finds one or more.

Go to the following menu:

Programme und Verknupfungen -> Programmerstellung & Zentralerverknupfhungen

And choose the button Neu to create a new program.

At the top of the screen you can click the text Neues Programm and change it to the name you would like.

I want the program to run daily at 12:00 noon. So for the first option press the plus symbol below Bedingung: Wenn... and choose the option Zeitsteurung from the pulldown. Next click the option Zeitmodul next to the pulldown. I filled out the popup window as follows:

And press OK to store.

Next press the plus symbol in the next part named Aktivitat: Dann... From the pulldown that appears choose the option Skript. Now click the option Skript erstellen to open a popup window. Copy & Paste the following script in the upper part of the window:

string deviceid;
integer count = 0;
string message = "";
foreach(deviceid, dom.GetObject(ID_DEVICES).EnumUsedIDs()) {
var dev = dom.GetObject(deviceid);
var if = dom.GetObject(dev.Interface());
string channame = if.Name() # "." # dev.Address() # ":0.LOWBAT";
var chanid = dom.GetObject(channame);

if ( (chanid.State() == true) && (chanid.Value() == true) ) {
if ( count == 0 ) {
message = dev.Name(); }
else {
message = message # "n" # dev.Name(); }
count = count + 1;
}
}
if ( message != "") {
dom.GetObject("EmailText").State(message);
string stdout;
string stderr;
system.Exec("/etc/config/addons/email/email 04", &stdout, &stderr);
}

Make sure to change the 04 in the previous to last line to the number of the email template you choose before. It should look something like this:

And press OK to store the configuration.

And press OK to store the new program.

Now you're done! Ofcourse the program will only send out an email when one of the devices has reported a low battery status.