I have succesfully implemented some automation to notify me when my washing machine is finished. I used this configuration.
I want to create a sensor which I can use in my lovelace configuration. This sensor simply needs to display the last time a washing machine program finished. I tried looking at the last_changed value of input_boolean.wasmachine, but that reset after a reboot of HA. I want it to be persistent, so that even after a server reboot it still says i.e. “8 hours ago”. I can’t seem to figure it out. How should I do this?
Isn’t that unnecessarily complex? There is already an automation for ‘Set washing machine as finished’. Can’t I just add an action that updates a value?
I have this right now:
wasmachine_last_run_date:
friendly_name: "Wasmachine datum laatste programma"
value_template: "{{ as_timestamp(states.input_boolean.wasmachine.last_changed) }}"
But this just displays as 1570839077.300437 in Lovelace UI. Before I tried this:
input_datetime:
wasmachine_last_run:
name: Datum laatste programma
has_date: true
has_time: true
initial: 2019-10-12 12:00
I discovered an even better solution. Since I have an automation setup that runs when the program finishes, and I just want to know when the program ran for the last time I can just do this:
- platform: template
sensors:
wasmachine_last_run_date:
friendly_name: "Date last program run"
device_class: timestamp
value_template: "{{ state_attr('automation.set_washing_machine_as_finished', 'last_triggered') }}"
This is persistent through restarts. The end result looks like this:
Because I find this the most effective for my use case I’ll mark my answer as the solution.