Homematic & Batterie Status

 

This tiny script iterates through all objects and checks against LOWBAT true values. In case there’s an entry it sends a pushover notification.

! user
string custDate = system.Date("%d.%m.%Y");
string custMsg = "Batteriestatuspruefung vom : ";
string custNoError = "Keine Batterie muss gewechselt werden.";
string custError = "Ladezustand der folgenden Batterien niedrig, austauschen!";
string pushoverUrl = "http://api.pushover.net/1/messages.json";
string pushoverToken = "";
string pushoverUser = "";

! system
string sDevId;
string sChnId;
string sDPId;
integer counter = 0;
string sMsg = "";



 foreach (sDevId, root.Devices().EnumUsedIDs())
 {
 object oDevice = dom.GetObject(sDevId);
 foreach(sChnId, oDevice.Channels())
 {
 object oChannel = dom.GetObject(sChnId);
 foreach(sDPId, oChannel.DPs().EnumUsedIDs())
 {
 object oDP = dom.GetObject(sDPId);
 string sName = oDP.Name();
 var channel = dom.GetObject(sName);
 string chValue = channel.Value();
 string chState = channel.State();
 string ochName = oChannel.Name();

 ! Channel with Battery? > -1
 integer hasBattery = sName.Find(".LOWBAT");
 if(hasBattery > 0 ){
 if(chValue == true){
 sMsg = sMsg # "- " # ochName # " \r\n";
 counter = counter + 1;
 }

 }
 }

 }

 }

 if(counter > 0){
 string msg = custMsg # custDate # "\r\n";
 msg = msg # custError # "\r\n";
 msg = msg # sMsg;
 }else{
 string msg = custMsg # custDate # "\r\n";
 msg = msg # custNoError;
 }


!pushpver
var cURL="LD_LIBRARY_PATH=/usr/local/addons/cuxd /usr/local/addons/cuxd/curl";
dom.GetObject("CUxD.CUX2801001:1.CMD_EXEC").State(cURL#" -d token='"#pushoverToken#"' -d user='"#pushoverUser#"' -d message='"#msg#"' '"#pushoverUrl#"'");



The script runs once a week on my CCU.

Leave a Reply

Your email address will not be published. Required fields are marked *