Marius82
(Marius)
November 28, 2016, 8:43am
1
Hi,
ic create a Template sensor which calculate the wind speed from m/s in km/h. The result ist ok- but how can I limit the numbers of characters of the result? Sometimes the result looks like 8,989898923 km/h but I only need eg. 8,98 km/h.
- platform: template
sensors:
wind_einheit:
value_template:
'{{ states.sensor.dark_sky_wind_speed.state | multiply(3.6) }}'
unit_of_measurement: 'Km/h'
silvrr
November 28, 2016, 12:13pm
2
You can create a template sensor and limit the number of decimal places, however it wonβt always work.
HA seems to have an issue with this. I believe there is a bug request in related to temperature readings. Not sure if it applies to other readings.
Maybe using round(2)
. Taked from https://home-assistant.io/topics/templating/#sensor-states
- platform: template
sensors:
wind_einheit:
value_template:
'{{ states.sensor.dark_sky_wind_speed.state | multiply(3.6) |round(2)}}'
unit_of_measurement: 'Km/h'
Marius82
(Marius)
November 28, 2016, 1:25pm
4
Thank you! Round work for me!
TheCrey
(TheCrey)
January 19, 2018, 8:26pm
5
Hi
sorry to open such an old thread, but it was the only one I found.
I do have kind of the same issue but in my case, it does not work
I use this:
value_template: '{{ states.vacuum.eva.attributes.total_cleaning_time | float / 60 | round(2) }}'
But it still gives me a number like x.xxxxxxxx but I only need it like x.xx
Also, If the number changes, there is still that long string.
I thought maybe one it will happen, but it seems like it does this all the time.
Anyone know where it could be related to?
You need to use brackets, otherwise 60
will be rounded before the division happens:
value_template: '{{ (states.vacuum.eva.attributes.total_cleaning_time | float / 60) | round(2) }}'
1 Like
TheCrey
(TheCrey)
January 20, 2018, 10:41am
7
Thanks, that was the trick.
Simple math, did not thought about this.