Previously working sensor templates are constantly unavailable now

Hi,

I have some sensor templates in my sensors.yaml that were working without problems not so long ago.

Some of them:

- platform: template
  sensors:
    vacuum_card_filtr:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_main_filter') | float / 1440 )) | round(0, 'floor', default) }}d {{ (( states('sensor.valetudo_dreame_z10_pro_main_filter') | float % 1440 / 60 )) | round(0, 'floor', default) }}h"
      unit_of_measurement: "d h"
    vacuum_card_szczotka_glowna:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_main_brush') | float / 1440 )) | round(0, 'floor', default) }}d {{ (( states('sensor.valetudo_dreame_z10_pro_main_brush') | float % 1440 / 60 )) | round(0, 'floor', default) }}h"
      unit_of_measurement: "d h"
    vacuum_card_szczotka_boczna:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_right_brush') | float / 1440 )) | round(0, 'floor', default) }}d {{ (( states('sensor.valetudo_dreame_z10_pro_right_brush') | float % 1440 / 60 )) | round(0, 'floor', default) }}h"
      unit_of_measurement: "d h"
    vacuum_card_czujniki:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_sensor_cleaning') | float / 1440 )) | round(0, 'floor', default) }}d {{ (( states('sensor.valetudo_dreame_z10_pro_sensor_cleaning') | float % 1440 / 60 )) | round(0, 'floor', default) }}h"
      unit_of_measurement: "d h"
    vacuum_card_czas:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_current_statistics_time') | float / 60 )) | round(0, 'floor', default) }}min"
      unit_of_measurement: "min"
    vacuum_card_powierzchnia:
      value_template: "{{ (( states('sensor.valetudo_dreame_z10_pro_current_statistics_area') | float / 10000 )) | round(0, 'floor', default) }}m²"
      unit_of_measurement: "m²"

when I copy those templates into dev/templates then I get those:

which is correct.

But dev/states page shows:


(the last one is from my vacuum - not from templates).

What do I need to do to make those sensor templates work again?

Remove the text you appended at the end of each template (h, d, min, m², etc).

Each Template Sensor already has a unit_of_measurement so there’s no need to repeat the unit in the template. In fact, this duplication is what’s causing the problem you’re experiencing.

It appears that the rules for how unit_of_measurement is employed have become more strict in 2023.5.0.

As you can see I have 2 units per template (eg. 1d 4h). How to make that work properly?

Remove the unit_of_measurement instead.

Such an easy thing to do - I feel stupid now :confused:
Thank you @Troon that worked.

1 Like

If you didn’t remove the text strings from your templates like I had suggested, and simply removed the unit_of_measurement option, then you didn’t just eliminate the unavailable value, you also made your Template Sensors unable to be graphed, or used for long-term statistics, because their values are now non-numeric.

Removing unit_of_measurement isn’t a cure-all.

In this case, OP’s sensors have always been non-numeric by intent — it’s only the recent strict unit checking that’s caused the error.

min and m² appear to represent purely numeric values. If szafan has no intention of graphing them then the side effects of removing unit_of_measurement have no consequences in this case.

I agree the other ones are non-numeric by design (they display days and hours in a custom time format). Removing their unit_of_measurement is now needed to suppress warning messages about non-numeric values.

Ah right. To be clear, I meant that the UoM should be removed from just the sensors that were no longer working.

That’s not a problem for me - those templates are there purely for dashboard display/formatting purposes - so no need to graph them etc.