Automation on time diference

Hello all,

I am making the card for my Dishwasher to show time left and other parameters (via a Smart plug with energy info).
I am stucked on the automation that have to update the time left, and I cannot understand what am I doing wrong.

service: input_number.set_value
data:
  value: >-
    {{ ((as_timestamp(strptime(states('input_datetime.dishwasher_hora_estimada'),
    '%H:%M:%S'), default=0))|round(0) - now().timestamp() )/60
    }}
target:
  entity_id: input_number.dishwasher_tempo_restante

So, my “tempo_restante” should keep track of the number of minutes left, just by calculating time passed between NOW and the future time where the dishwasher should stop (this I calculate at the begining, using the last duration + starting time).

Can anyone help me to find the error here?
Thanks!

How about posting the error :wink:

Here is a template where I calculate the difference between the time where my washing machine started and now:

{{(as_timestamp(now())-as_timestamp(states('var.waschmaschine_start')))|timestamp_custom('%H:%M',false)}}

Maybe that helps. You’d just need to turn the substraction around.

EDIT: Works now ! I was doing definitively something wrong, so finally I created the sensor.time (via configuration.yaml as explained here Time & Date - Home Assistant ) and now it works like a charm :slight_smile:

Thanks, but now I see that I may have another errors, because yours also fails to be.
Sorry for not posting the error, here it is:

Invalid value for input_number.dishwasher_tempo_restante: -64613949.1292022 (range -400.0 - 400.0). Got {'type': 'execute_script', 'sequence': [{'service': 'input_number.set_value', 'data': {'value': Template("{{ ((as_timestamp(strptime(states('input_datetime.dishwasher_hora_estimada'), '%H:%M:%S'), default=0))|round(0) - now().timestamp() )/60 }}")}, 'target': {'entity_id': ['input_number.dishwasher_tempo_restante']}}], 'id': 45}

So basically it tells me that I am saving a number too big, but the thing is that “horas_Estimada” is 20:57:56 and right now it is 16:07, so the diference should be ~300 min, not “-64613949” minuts :frowning: