With my cistern, the fill level in centimeters and liters is calculated from the voltage of the water level sensor . Of course I know that at 100.5 cm fill level the cistern is full to overflowing and therefore contains 5130 liters of water according to the manufacturer’s specifications. But how do you output the fill level as a percentage? This is also interesting for battery displays, because 70% battery level is more intuitive to understand than 2.7 volts.
With a sensor template, the conversion is very simple, because you can practically build a “virtual” sensor that outputs a calculation from other sources.
⚠ [affiliate] Keine Produkte mit Cache für home-assistant.
Bitte affiliate-sync --lang en ausführen.

We need a sensor with the current value, e.g. the current water level in liters. For me, this is the entity sensor.zisterne_liter. Also the maximum value to be achieved, the base value. For my cistern, that would be 5130 (liters).
Now create a new sensor. Either under sensors: in the configuration.yaml or, as I do, in an external sensors.yaml that only contains my sensors - this creates more clarity.
|
|
In value_template we divide the measured value of the sensor by the base value, i.e. 5130, and multiply the result by 100. round(1) indicates that it should be rounded to one decimal place. If you don’t want decimal places, specify round(0).
After reloading, you have a new entity sensor.zisterne_prozent that you can then integrate into the dashboard.
For a battery, you first need to know at what point a battery can be considered empty. For button cells, as found in many devices like the Aqara ZigBee sensors, 3 volt lithium button cells are used. Most manufacturers state that the cell is empty at a voltage of 2 volts. Therefore, you must not assume 3 volts as the base value, but only the difference between a new battery at 3 volts and an empty battery at 2 volts, i.e. 1 volt. For 1.5 volt batteries, 0.9 volts is assumed for an empty battery, so you would have to assume 0.6 volts as the base value (1.5 volts - 0.9 volts).
|
|
Here you take the sensor that measures the current battery voltage of a device and, for example, set 1 as the base value for a 3 volt battery, and you already have the battery status in percent.
What do you think? Leave a comment!
Share your thoughts, questions or experiences with the community.