Display in UI when automation its running

Hi guys,
I have a simple automation to turn off smart plug after X amount of time, this part it’s working
but i want to know / display in UI when this automation it’s running (yes the automation it’s start manually)


show_name: true
show_icon: true
type: button
tap_action:
  action: perform-action
  perform_action: automation.turn_on
  target:
    entity_id:
      - automation.turn_off_smart_plug_after_5min
show_state: true
theme: Mushroom Shadow
icon: mdi:camera-timer
name: 5 min
entity: automation.turn_off_smart_plug_after_5min

Screenshot 2024-12-22 130439

in screen shoot the automation button it’s always ON, but i want to show state only when i press the automation button.

I think you can look at the current attribute to get how many are running.

I just checked in the developer console and mine have current: 0.

The state is just whether the automation is enabled or disabled.

The action automation.turn_on doesn’t trigger an automation, it enables it so that if the triggers fire the automation will run.

If you’d like to have a series of actions that you can run on demand (such as in your example here), then you really want a script.

Another option, since you want this to happen after some delay is to to have the button press start a timer, and then have an automation that has an event triggered for the timer.finish event and the action would be to turn off the smart plug. Then you could display on your dashboard if the timer is running and even how much time is left before it ends.

I’m using the custom Auto entities card to show me all currently running automations. Maybe it’s something for you too.
You can customize the filter to your taste…

type: custom:auto-entities
card:
  show_name: true
  show_icon: false
  show_state: false
  type: glance
  title: Lopende automatiseringen
  columns: 1
filter:
  include:
    - domain: automation
  exclude:
    - attributes:
        current: 0
sort:
  method: last_triggered
show_empty: true

i think i found an working solution, tell me if this code can be optimize because i’m not expert in coding not even a beginner one .

alias: turn off plug after 5 min
description: turn off smart plug after 5 min
triggers:
  - id: "on"
    event_type: timer.started
    event_data:
      entity_id: timer.5_min
    trigger: event
  - id: "off"
    event_type: timer.finished
    event_data:
      entity_id: timer.5_min
    trigger: event
conditions: []
actions:
  - target:
      entity_id: switch.smart_plug_1_socket_1
    action: "switch.turn_{{ trigger.id }}"
mode: single

This is as good as it gets.
You picked the correct triggers, even the event.
You must have read the documentations.

The only thing that might make it fail is the missing " " here:

action: "switch.turn_{{ trigger.id }}"
1 Like