Help - Using template to convert float into time/int

My first time asking a question in this community, I tried to search how to do it before posting but no luck

So here is the situation, I want home assistant to trigger a Assistant Routine(google home) to announce a particular value based on current sensor value, I want the assistant relay to announce “time to full”, sensor.water_level gets a int number every 7 seconds, thats the current level of water and here is the formula Im using to calculate ETA to full for the 1070 Liters of tank inside the template

{{states('sensor.water_level')| int * -1/23.1 + 1070/23.1 }}

Value I am getting if the water level is 840 Liters is 9.956709956709958

which is very accurate… too accurate… it takes the google assistant a while to announce all the decimals, is there any way I can convert this into minutes? or even a int would be fine…
( I have used the above formula inside a rest command for assistant relay and it works fine)

service: rest_command.assistant_relay
data:
  command: >-
    announce on kitchen speaker, {{states('sensor.water_level')| int * -1/23.1 + 1070/23.1 }} minutes

Have you tried using the round filter?

{{ (states('sensor.water_level')| int * -1/23.1 + 1070/23.1) | round }}

If you want one or two decimal places, use round(1) or round(2)

2 Likes

Thank you, it works perfectly, still learning to use formulas in templates :sweat_smile:

The Jinja2 interpreter used by Home Assistant supports many (but not all) of the filters listed here:

https://jinja.palletsprojects.com/en/2.11.x/templates/#builtin-filters

1 Like