Hi,
I’m trying to create a notification with the estimated completion time of my washing machine… however I cant figure out how to add the remaining time to the current time
the remaining time is in the format H:MM as an attribute to sensor.washer
Ive tried loads of different combos of as_timestamp or .timestamp() but always resulting in type errors
{{ now() + strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M') | timestamp_custom('%H:%M') }}
ive had a good read through the EPIC time conversion topic, but still cant make this work. There are several other topics asking for similar things but cant find a working solution
tom_l
December 12, 2021, 1:50am
2
Try this:
{{ now() + timedelta(hours=state_attr('sensor.washer', 'remain_time').split(':')[0]|int(0)), minutes=state_attr('sensor.washer', 'remain_time').split(':')[1]int(0) }}
123
(Taras)
December 12, 2021, 1:56am
3
{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
{{ now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second) }}
EDIT
Correction. Overlooked to include the attribute.
Removed unnecessary argument for today_at
(see tom_l’s post below).
1 Like
tom_l
December 12, 2021, 2:14am
4
Can you not just use: today_at()
instead of today_at('00:00:00')
?
Also it’s an attribute of sensor.washer
, not the state.
1 Like
123
(Taras)
December 12, 2021, 2:17am
5
My mistake: I copy-pasted it from a nearby identical post I made elsewhere. Fixed.
1 Like
tom_l
December 12, 2021, 2:28am
6
Also since when does strptime()
take 3 arguments?
123
(Taras)
December 12, 2021, 2:32am
7
The third argument is the default in case the conversion fails.
You’re right; today_at()
returns today at zero-hour so the argument I supplied is unnecessary (I have removed it).
tom_l
December 12, 2021, 2:34am
8
Ah of course it is. Thanks.
Thanks both for your help, I hadn’t seen the timedelta thing…
{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
{{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}
To get a nice looking time for the notification I had to convert it back to a timestamp to be able to use the timestamp custom format.
Next fun task will be to use the initial time and the remain time to calculate how many % through the wash it is.
Gussir
December 19, 2022, 1:56pm
10
Hello,
That’s nice !
Could you share your code for the timestamp value as a notification:
- service: notify.mobile_app
data_template:
title: Washing machine time remaining
data:
chronometer: true
when: "{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M', today_at()).time() %}
{{ as_timestamp(now() + timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}"
Here you go,
service: notify.mobile_app_chris
data:
message: >-
{% set t = strptime(state_attr('sensor.washer', 'remain_time'), '%H:%M:%S',
today_at()).time() %} Cycle {{ states('sensor.washer_current_course') }}
<br> Currently {{ states('sensor.washer_run_state') }} <br> Estimated
completion time: {{ as_timestamp(now() + timedelta(hours=t.hour,
minutes=t.minute, seconds=t.second)) | timestamp_custom('%H:%M') }}
title: Washing Machine Running
data:
tag: washing_machine
notification_icon: mdi:washing-machine
1 Like