So I just updated from 2023.4.0 to 2023.6.1. Everything is working great, except I noticed that none of my template sensors were working. It’s not like they were in an error state - they just were not showing up in Developer Tools > States. It’s as if they did not exist.
I ran a quick seach online and came across an article which mentioned this happening becuase it’s returning a non-numerical result with “unit_of_measurement”. The article suggested to delete “unit_of_measurement” from my sensors. Sure enough, they started working. (Article link: https://community.home-assistant.io/t/templates-misbehaving-in-2023-5/567998/23
Now here’s the thing. My front end is completely made up of multiple Picture Elements Cards with the template sensors on them and the unit of measurement is used as the badge. For example, in the snippet below:
The top 4 “controls” are state badges which use the template sensors as the entity.
Here’s the code I use in configuration.yaml:
- name: "Bedroom Cooling Sensor"
unit_of_measurement: "Air Con"
state: >
{% if is_state('climate.bedroom_ac', 'off') %}
Off
{% elif state_attr('climate.bedroom_ac', 'hvac_action') == 'idle' %}
Idle
{% elif is_state('climate.bedroom_ac', 'cool') %}
On
{% else %}
Error
{% endif %}
- sensor:
- name: "Bedroom Temperature"
unit_of_measurement: "Temp"
state: "{{ states('sensor.rm4_mini_temperature') | int }}°C"
- sensor:
- name: "Bedroom Humidity"
unit_of_measurement: "Humidity"
state: "{{ states('sensor.rm4_mini_humidity') | int }}%"
- sensor:
- name: "Bedroom Air Conditioner Fan Speed"
unit_of_measurement: "Speed"
icon: mdi:fan
state: >
{% if is_state('input_select.br_air_conditioner_fan_speed_selector', 'low') %}
Low
{% elif is_state('input_select.br_air_conditioner_fan_speed_selector', 'medium') %}
Med
{% elif is_state('input_select.br_air_conditioner_fan_speed_selector', 'high') %}
High
{% else %}
Error
{% endif %}
Here’s the code I use on the tile:
- type: state-badge
entity: sensor.bedroom_cooling_sensor
title: Toggle AC
tap_action:
action: call-service
service: input_boolean.toggle
service_data:
entity_id: input_boolean.br_cooling_switch
hold_action:
action: none
style:
top: 7%
left: 2%
color: transparent
'--ha-label-badge-font-size': 1.5em
transform: none
- type: state-badge
entity: sensor.bedroom_temperature
title: Bedroom Temperature
style:
top: 7%
left: 17%
color: transparent
'--ha-label-badge-font-size': 1.5em
transform: none
- type: state-badge
entity: sensor.bedroom_humidity
title: Bedroom Humidity
style:
top: 7%
left: 32%
color: transparent
'--ha-label-badge-font-size': 1.5em
transform: none
After updating to 2023.6.1 (I skipped 2023.5 so not sure if the issue was seen there), all of these template sensors stop working, unless I remove “unit_of_measurement”. In which case, I lose the names of the badges seen in the snippet and I just see the circle with the state of the entity. This looks very ugly and has essentially killed my front end. See below:
Would anyone have any idea how I should go about here? In case you’re wondering, this is what my complete front end should look like and it uses template sensors a whole lot!
Any help would be appreciated.