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.

Cheers
Michael

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

pi@pi:/etc/openhab/configurations/transform $ cat rain.map
[0,1000[=mm/h
[1000,200[=mm/h
Undefined=keine Daten
-=keine Daten

Hi Markus,

that´s what i tried but it wont work …

BATTERY.map

[2.80,3.00]=voll
[1.60,2.30]=50%
[1.50]=leer
-=unbekannt

Items:

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

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

Number itmHeizung_Kueche_BAT "Batterie Heizung Küche [MAP(BATTERY.map):%s]" <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:

Cheers
Michael

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:

3=voll
[2.40,2.80[=voll
[1.60,2.30[=50%
[1.50[=leer
-=unbekannt

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.

Cheers
Michael

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 …

3=voll
[2.40,2.90]=voll
[1.60,2.30]=50%
[1.50]=leer
-=unbekannt

Cheers
Michael

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 …

Cheers
Michael

Items:

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

Rule:

rule "Convert battery number to String"
when
    Item Battery_Level_Val changed
then
    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"

    Battery_Level_Str.sendCommand(str)
end

Hi Rich,

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

Cheers
Michael

Hi Rich,

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

Cheers
Michael

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:

http://localhost:8080/CMD?Battery_Level_Val=2.0

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:

Cheers
Michael

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.