I have sensors that send their battery level as a float (9.99) every hour and I’d like to display a battery icon (e.g. fas-battery-*) indicating the battery level.
e.g.:
battery_level >3 : fas-battery-full
battery_level <3 and >2.5 :fas-battery-three-quarters
etc…
Looking at the list of standard widget types the Icon widget seems like it should be able to do the job, however I can’t seem to get the syntax right to enter a condition in the icons list instead of a state.
If anyone’s interested this is how I got it to work. I created an entity in Home Assistant that transformed the numerical battery reading from the sensor into a state (FULL, EMPTY etc…).
configuration.yaml:
- platform: mqtt
name: "Ground Floor Temperature Battery State"
entity_id: ground_floor_temperature_battery_state
state_topic: "myhome/RF_Device04/BATT"
value_template: >-
{% if value|float>2.8 %}
FULL
{% else %}
{% if value|float>2.7 %}
THREE-QUARTER
{% else %}
{% if value|float>2.6 %}
HALF
{% else %}
{% if value|float>2.4 %}
QUARTER
{% else %}
EMPTY
{% endif %}
{% endif %}
{% endif %}
{% endif %}