Transforming multiple battery values in fixed values

Hey there,

i´m trying to build a group with all my battery levels in fixed values (full/empty).
Thats no problem for simple Homematic devices like the door/window contact.
They only deliver a LOWBAT value thats true when the battery is low.
But complex devices like the heating unit just offer an BATTERY_STATE with the current voltage.

I´m trying to make it more simple with a basic transformation.
I want to get 3 states out of the voltage ranges.
3.0 to 2.3 = full
2.2 to 1.8 = half
1.7 to 1.5 = empty

How to i get this into a .map file ?
I tried [2.3,3.0], [“2.3”,“3.0”], 2.3-3.0 but none of this worked.


You need to use two ‘[’ brackets, like in

pi@pi:/etc/openhab/configurations/transform $ cat
Undefined=keine Daten
-=keine Daten

Hi Markus,

that´s what i tried but it wont work …



Number itmHeizung_Schlafzimmer_BAT "Batterie Heizung Schlafzimmer [MAP(]" <battery> (Schlafzimmer, BATTERY) {homematic="address=MEQ1557919, channel=4, parameter=BATTERY_STATE"}

Number itmHeizung_Badezimmer_BAT "Batterie Heizung Badezimmer [MAP(]" <battery> (Badezimmer, BATTERY) {homematic="address=MEQ1726970, channel=4, parameter=BATTERY_STATE"}

Number itmHeizung_Kueche_BAT "Batterie Heizung Küche [MAP(]" <battery> (Kueche, BATTERY) {homematic="address=MEQ0056036, channel=4, parameter=BATTERY_STATE"}

I don´t know why the second unit wont show any value, thats problem 1.

Raw values:


Markus wrote, that you need two ‘[’ brackets, not one ‘[’ and one ‘]’. Your map-file is using that kind of brackets. Maybe that’s the cause?

BTW, where did you get your Battery icon from? Is that from the standard library or self-made?

Hi Stefan,

Oh my fault :slight_smile:
Thanks Markus !

I changed the brackets:


The UI shows full for the unit with 3V but nothing for the unit with 2.80V.
I think the different values causes this problem.
The 3V value is without a comma but the 2.80V value is with a comma and another 0.


Likely because 2.80[ means “up to but excluding 2.80” and you have no entry for 2.8-3V now.

Even when using [2.40,2.90[ i get no value in the UI.
Any ideas how to deal with this ?

Except just using the Voltage :slight_smile:

I tried something different, the .scale transformation as described in the wiki.
But still no change …



If you don’t get this working using the maps, you can create a rule and a String Item that gets set to “full” et al as the Number Item changes.

Hi @rlkoshak ,
thanks for the idea.

Could you help me with this rule ? :slight_smile:
I´m pretty new to OH and don´t know much about the rules …



String Battery_Level_Str "Level = [%s]"
Number Battery_Level_Val "Level = [%d]" {homematic ...}


rule "Convert battery number to String"
    Item Battery_Level_Val changed
    val Number value = Battery_Level_Val.state as DecimalType
    var String str = "Empty"

    if(value >=2.3) str = "Full"
    else if(value < 2.3 && value >=1.8) str = "Half"


Hi Rich,

Thanks for your help.
I’m gonna try that tomorrow.


Hi Rich,

i just set up the rule and wait for one of the batterys to change :slight_smile:


If you’re like me and prefer to get immediate answers rather than wait, I think you can use the REST API to do some testing, like this:


Hi Kjetil,

thanks for your idea but it´s not working.
OpenHAB is trying to publish this value to homematic.
But the BATTERY_STATE is read only :wink:


That is correct, but unless I am completely wrong (1) - and I do believe I have tested this on various parts of my system a number of times - then the above “REST API command” should indeed set the value of your item. The Homeatic binding would not be able to set the battery state in the device obviously, but that doesn’t matter since all you care about is the value of the openHAB item so that you can test your rule, right?

(1) I don’t know how the Homeatic binding works but I assume it updates the bound items on a regular basis (every couple of seconds?) so you should be able to set the value of an item through the REST API for a period of time before it gets overwritten (updated) by the binding.

Unfortunately my system is down for an upgrade/overhaul at the moment so I cannot test this right now. I’ll let you know what I find when my system is up again.