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.
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.
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
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.