phairplay
(Phairplay)
October 23, 2022, 10:35am
1
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
jazzyisj
(Jason)
October 23, 2022, 10:59am
3
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
phairplay
(Phairplay)
October 23, 2022, 11:36am
4
Thank you
Really appreciate it
jazzyisj
(Jason)
October 23, 2022, 12:20pm
5
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
- entity: sensor.car_charging_complete
format: time
- entity: sensor.car_charging_complete
format: total
- entity: sensor.car_charging_complete
format: relative
1 Like
phairplay
(Phairplay)
October 23, 2022, 12:24pm
6
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
jazzyisj
(Jason)
October 23, 2022, 12:29pm
7
It shouldn’t be off if your time zone is set correctly.
Maybe you have the same issue as this person?
I’m running in docker and am using British Standard Time which is Europe/London both docker and the host are setup correctly but home assistant is showing one hour behind.
phairplay
(Phairplay)
October 23, 2022, 1:02pm
8
Your right I am
Now() is correct
Utcnow() is wrong
Strange as I’m running home assistant os