I now have automations working that monitor the power draw of my washing machine power outlet and sets a input_select to either: Idle or Running
I currently have a notification sent when the washing machine switches back from Running to Idle so that I know it has finished, but ideally I would also like to include the time the washing machine ran for. In my case this would be the difference between when the input_select was changed from Idle to Running and the time it was changed back again. Does anyone have some code I could steal that does this already please?
I use automations to update the status input_select, so I imagine I could base things off the last_triggered times for these automations, but happy for any solution to be honest.
I eventually figure out how to do this myself. It may not be perfect, but it seems to work. Code snippet of what I am using is below in case it’s of use to anyone else:
- alias: Laundry - Set washing machine finished when power drops
trigger:
- platform: numeric_state
entity_id: sensor.washing_machine_power
below: '2'
for:
minutes: 1
condition:
condition: and
conditions:
- condition: state
entity_id: input_select.washing_machine_status
state: Running
action:
- service: notify.all_ios_devices
data:
message: The washing cycle has finished! It took {{ (now().timestamp() - (as_timestamp(states.input_select.washing_machine_status.last_updated))
| float) | timestamp_custom('%-H hours and %-M minutes', 0) }}
- service: input_select.select_option
data:
entity_id: input_select.washing_machine_status
option: Finished