Hey fellas. Apologies for bumping an old thread, but in case any one is interested, I have a solve.
As seen in the situation above, any sensor with a non-numeric value cannot have a Unit of Measurement (UoM) as it is not supported any more. As with @JvH, my dasboard also consists of a lot of badges, which I was using for non numeric purposes, such as power toggle. See my post (again an older one) - https://community.home-assistant.io/t/template-sensors-not-showing-up-after-updating-to-2023-6-1/580912/6. Due to this, I have been running on 2023.4.0.
Today, I finally upgraded to 2024.2.2, and as expected, faced the same issue again. However, I have managed to figure out a work around. Try these steps out:
- In the non numeric sensor code, add the availability function. Just make sure that the entity is one which will ALWAYS a non numeric value so the sensor would be unavailable. Just add a light or fan entity. This will cause the sensor to be forever unavailable and instead of not working, it will be displayed as an unavailable badge. See below:
My code reads like this:
- sensor:
- name: "Bedroom Fan Sensor"
unit_of_measurement: "Fan"
state: >
{% if is_state('light.bedroom_fan', 'off') %}
Off
{% elif is_state('light.bedroom_fan', 'on') %}
On
{% else %}
Offline
{% endif %}
availability: "{{ is_number(states('light.bedroom_fan')) }}"
Now that we have the badge displaying as unavailable, we just need to change its value to “On” or “Off”. If you go to Developer Tools > States, and then change the value manually, you’ll see that the badge is displayed exactly as before. The key is to now automate the state change of this unavailable sensor on the basis of the entity it represents. However, there is no function in HA which allows us to do this.
A quick search led me to this video - https://www.youtube.com/watch?v=V2-bwsTLjh4 which walks you through installing a small Python script which creates a service we can use to set the state
Follow the instrunctions in the video and you will end up with a service named “python_script.set_state”. You can use this to change the state of the unavailable sensor. All that needs to be done is to create an automation which sets the required state. Here’s the code I am using
alias: Hack - Set UI Fan Sensor Value as per fan state
description: ""
trigger:
- platform: state
entity_id:
- light.bedroom_fan
condition: []
action:
- service: python_script.set_state
data_template:
entity_id: sensor.bedroom_fan_sensor
state: "{{trigger.to_state.state | title}}"
mode: single
This has worked beautifully for me and I just had to share it with the community. I hope this helps.
Cheers