Time Calculation in Home Assistant (sensor & Helper)

Dear Community (-wizzards :slight_smile: ) i have a question concerning about a sensor time calcultaion.

Helper:
input_datetime.gewenste_aankomsttijd

What I want to do is the following.
I want to specify a hour & minutes in input_datetime helper (no date only hours and minutes);

Than I want to take the minutes that the waze_travel_time from my home to the destination (Lego Store):

- platform: template
  sensors:
  type - platform: waze_travel_time
  name: naarlegostore
  origin: 51.15922736431498, 4.139082944514981
  destination: 51.224295996914464, 4.501470432630029
  region: 'EU'or paste code here

This gives me the minutes

So what I want to know: what code do I use to substract the minutes I receive from the waze sensor from the hours stated in the helper?

- platform: template
  sensors:  
      theoretisch_vertrek_min:
        value_template: >
          {{% set minutes = states('sensor.naarlegostore') | int %}
          {{ (state_attr('input_datetime.input_datetime.gewenste_aankomsttijd', 'timestamp')) - 
           (minutes * 60) | timestamp_custom('%H:%M', false) }}

But that doesn’t seem to work.
Any wizard advice ?

- platform: template
  sensors:  
    theoretisch_vertrek_min:
      value_template: >
        {{ (state_attr('input_datetime.gewenste_aankomsttijd', 'timestamp') - (states('sensor.naarlegostore') | int * 60)) | timestamp_custom('%H:%M', false) }}

EDIT

Correction: Removed duplicated input_datetime

3 Likes
- platform: template
  sensors:  
    theoretisch_vertrek_min:
      value_template: >
        {{ (state_attr('input_datetime.gewenste_aankomsttijd', 'timestamp') - (states('sensor.naarlegostore') | int * 60)) | timestamp_custom('%H:%M', false) }}

There is an extra input_datetime written by the OP.

1 Like

Yes and an incorrect variable declaration on the first line.

Thx for yur help :slight_smile: Much appreciated!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.