szafran
(Marcin Szafrański)
May 10, 2023, 8:38am
1
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?
123
(Taras)
May 10, 2023, 12:48pm
2
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.
opened 08:22AM - 06 May 23 UTC
### The problem
The following template sensor don't work in 2023.05 and I don't… know, whats the problem. In 2023.04 this work without any problem...
`
#Sonnenaufgang lokal Zeit
- platform: template
sensors:
sun_sonnenaufgang_local:
friendly_name: Sonnenaufgangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_custom('%H:%M') }}"
#Sonnenuntergang lokal Zeit
- platform: template
sensors:
sun_sonnenuntergang_local:
friendly_name: Sonnenuntergangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}"
`
Look at this:
![grafik](https://user-images.githubusercontent.com/59682922/236612310-638702f0-c32f-4763-9616-8a51da2210fe.png)
and this:
![grafik](https://user-images.githubusercontent.com/59682922/236612344-ecbbd4d8-10c2-4ae1-a0d7-5d2f9c0ab3a0.png)
### What version of Home Assistant Core has the issue?
core-2023.5.2
### What was the last working version of Home Assistant Core?
core-2023.4.6
### What type of installation are you running?
Home Assistant OS
### Integration causing the issue
_No response_
### Link to integration documentation on our website
_No response_
### Diagnostics information
_No response_
### Example YAML snippet
```yaml
#Sonnenaufgang lokal Zeit
- platform: template
sensors:
sun_sonnenaufgang_local:
friendly_name: Sonnenaufgangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_rising')) | timestamp_custom('%H:%M') }}"
#Sonnenuntergang lokal Zeit
- platform: template
sensors:
sun_sonnenuntergang_local:
friendly_name: Sonnenuntergangszeit
unit_of_measurement: "h"
value_template: "{{ as_timestamp(state_attr('sun.sun','next_setting')) | timestamp_custom('%H:%M') }}"
```
### Anything in the logs that might be useful for us?
_No response_
### Additional information
_No response_
szafran
(Marcin Szafrański)
May 15, 2023, 3:28pm
3
As you can see I have 2 units per template (eg. 1d 4h). How to make that work properly?
Troon
(Troon)
May 15, 2023, 3:42pm
4
Remove the unit_of_measurement
instead.
szafran
(Marcin Szafrański)
May 15, 2023, 4:22pm
5
Such an easy thing to do - I feel stupid now
Thank you @Troon that worked.
1 Like
123
(Taras)
May 15, 2023, 5:55pm
6
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.
Troon
(Troon)
May 15, 2023, 6:08pm
7
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.
123
(Taras)
May 15, 2023, 6:28pm
8
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.
Troon
(Troon)
May 15, 2023, 6:39pm
9
Ah right. To be clear, I meant that the UoM should be removed from just the sensors that were no longer working.
szafran
(Marcin Szafrański)
May 19, 2023, 12:27pm
10
That’s not a problem for me - those templates are there purely for dashboard display/formatting purposes - so no need to graph them etc.