I would like to devide two sensor values to get a percentage:
Devide by a number works:
{{ states("sensor.germany_coronavirus_confirmed") | float / 4 }}
But if I put a sensor value instead of the 4, I get an unknown error…
I would like to devide two sensor values to get a percentage:
Devide by a number works:
{{ states("sensor.germany_coronavirus_confirmed") | float / 4 }}
But if I put a sensor value instead of the 4, I get an unknown error…
What sensor are you trying to replace 4 with?
Is the sensor’s state an integer?
Have you tried
{{ (states("sensor.germany_coronavirus_confirmed") | int) / (states("sensor.germany_coronavirus_confirmed") | int) }}
(I replaced float
with int
as I’d hope you don’t have a 0.7 of a person confirmed
{{ 100 * (states("sensor.germany_coronavirus_deaths") | int) / (states("sensor.germany_coronavirus_confirmed") | int) }}
Might you have one more hint, how to round that value to have 3 digits (i.e. 0.233%)
got it:
{{ (100 * (states("sensor.germany_coronavirus_deaths") | int) / (states("sensor.germany_coronavirus_confirmed") | int)) | round(3)}}
{{ ((100 * states("sensor.germany_coronavirus_deaths")|int) / states("sensor.germany_coronavirus_confirmed")|int) | round(3) }}
should work the same - you don’t need brackets to convert states to int
.