Time templating help

Hi guys,
I’m trying to make two sensors that shows

1, if my car is charging. When it will be completed based on the last time it was update plus the state (H:M to full charge)

2, if my car isn’t currently charging. I would like to see how long it would take based on the current time plus the state (H:M to full charge)

I have the following

{{ (as_timestamp(states.sensor.car_battery_last_received.last_changed)) | timestamp_custom("%H:%M") }}

this shows when the sensor was last updated

{{ (utcnow().strftime("%s") | int) |
timestamp_custom("%H:%M")}}

this is showing me the time as of now

{{(states('sensor.car_charge_time_full'))}}

this is showing me how long it will take to charge to full: 1:30:00.000000

yet for the life of me I can’t create two sensors
now + state
last_changed + state

could someone please help

last_changed + state

{{ (states.sensor.car_battery_last_received.last_changed 
    + as_timedelta(states('sensor.car_charge_time_full'))).strftime("%H:%M") }}

now + state

{{ (now() + as_timedelta(states('sensor.car_charge_time_full'))).strftime("%H:%M") }}
1 Like

Thank you
Really appreciate it

Happy to help. I answered your question as asked, but if you’d like another hint - you can format your template sensor for charging complete time as a timestamp and then take advantage of the built in timestamp formatting options to control the display in the front end. I made up the entity binary_sensor.car_charging in this example, I assume you have an actual sensor for this based on your question.

template:
  - sensor:
      - name: "Car Charging Completed"
        unique_id: car_charging_complete
        device_class: timestamp
        state: >
          {% if is_state('binary_sensor.car_charging','on') %}
            {{ states.sensor.car_battery_last_received.last_changed 
                + as_timedelta(states('sensor.car_charge_time_full')) }}
          {% else %}
            {{ now() + as_timedelta(states('sensor.car_charge_time_full')) }}
          {% endif %}

Then in your front end:

- entity: sensor.car_charging_complete
  format: time

image

- entity: sensor.car_charging_complete
  format: time

image

- entity: sensor.car_charging_complete
  format: total

image

- entity: sensor.car_charging_complete
  format: relative

image

1 Like

Thank you
This is really helpful

One issue I am having is the last_changed is 1hour out (currently summer time hrs in the UK)
How do I get around this, aside from waiting a few week :slight_smile:

It shouldn’t be off if your time zone is set correctly.

Maybe you have the same issue as this person?

Your right I am
Now() is correct
Utcnow() is wrong
Strange as I’m running home assistant os