I want to make a sensor that displays the battery charge level icon based on numerical values ranging from 0 to 105. The chip’s supply voltage is measured in an 8bit value, one LSB corresponds to 1/32 volt.
So for example, if I want a battery empty icon when VCC is below 1.5V, then the state value for that should be 48 (1.5/0.03125). Lets make that 50. A full battery equals 105.
Looks easy, every 10% the battery-charge icon would change, but since I totally suck at math I have no idea how to do this and translate that in to a HA template.
Anyone willing to help?
I’ve tried the compensation, but no idea how to make this work. I understand what it does, but where do I place the code? I’ve tried all sorts of combinations and indentations, but all results in errors. Searching the forum, youtube or google doesnt get me any futher either, there isnt much info on how to use it.
This gives me ‘Property compensation is not allowed’
- platform: template
sensors:
ble_battery_status:
friendly_name: Battery status
value_template: >-
{{ ((states ('sensor.bthome_sensor_0001_count_1') | int / 0.03125) / 1000) | round (2) }}
{% set ble_battery = states ('sensor.bthome_sensor_0001_count_1') | int | round(0) %}
icon_template: >-
mdi:battery-{{ble_battery}}
unit_of_measurement: "v"
compensation:
ble_battery_charge:
source: ble_battery
data_points:
-[50, 0]
-[105, 100]
Is there example code or more documentation on how this works?
As you might have guessed already, I’m new to HA
Why? Because I thought that is the correct way. Obviously its not
I’m new to HA and am trying by means of parts of code from this forum, to figure out how it works
Did I understand it correctly that the compensated value of sensor.bthome_sensor_0001_count_1 would be made available by means of ble_battery_charge?
If try to read {{states ('ble_battery_charge')}} it either is empty or unknown. sensor.bthome_sensor_0001_count_1 currently has a value of 105 and should be changed to 100
What am I missing?
Strangely enough that never happens. I’ve forced a state change in Developer tools, but the result is always unknown. {{ble_battery_charge}} gives UndefinedError: 'ble_battery_charge' is undefined
This could be correct as 'ble_battery_charge' is not a variable but a sensor.
that’s impossible for that template to “value 105”. It will return a state object, which has a very specific format when output from that template. Please paste the results of the template that troon provided.