Automation with delay, show progress

Hi everybody,

(first post from a new Home Assistant fan :slight_smile: ) I’ve created an automation that’s triggered by turning on a Sonoff S26 plug (running Tasmota). As actions, first I have a delay of 60 minutes, and then that plug is powered off. This works great, when I activate the plug, it stays on for 60 minutes and then turns off. (I use it to water my plants, so I can’t forget to stop the water pump)

Would it be possible to display (in a card?) the status of a running automation? So I could see that the plug/pump was started for example 23 minutes ago, and will run for 37 minutes? I know you can go into the Configuration/Automations section, and see the last triggered timestamp. So basically I would like to present that timestamp on my startpage somehow.

Thanks a lot!
Jan

Create a template sensor with this template:

value_template: "{{ relative_time(states.automation.your_automation.last_changed) }}"

Display that sensor in an entities card.

1 Like

I’ve had issues trying to use the relative_time function. Also last_changed would also indicate the last time the automation was turned on or off.

I’d do it slightly differently:

sensor:
- platform: template
  sensors:
    auto_last_run:
      value_template: "{{ state_attr('automation.XXX', 'last_triggered') }}"
      device_class: timestamp

I haven’t tried exactly this, so it might need some tweaking, but that should show the last time the automation was trigger as “xx min ago” or “xx hours ago”, something like that. E.g., I have my “sun2” sunrise sensor (which has device_class: timestamp) shown in an entities type card, and it shows this way.

@jtlns, I’d also suggest changing your automation slightly so something like this:

- trigger:
  - platform: state
    entity_id: switch.XXX
    to: 'on'
    for:
      hours: 1
  action:
  - service: switch.turn_off
    entity_id: switch.XXX

Without getting into details, you want to avoid using a delay step in an automation’s action. The above avoids the issues associated with that, and it handles the case where the switch is turned off another way before the 60 minutes expires.

2 Likes