How to call an automation through a button?

I have an automation, that works fine when I trigger it through the automatons menu.
I would like to make a button on the main page to trigger this automation, is this possible?

If you’re using the button card, here’s an example of one of mine:

      - aspect_ratio: 2/1
        color: 'rgb(66, 134, 244)'
        color_type: icon
        entity: script.1560010397544
        show_name: false
        show_state: false
          action: call-service
          service: script.toggle
            entity_id: script.1560010397544
        type: 'custom:button-card'

That is a script not an automation?

Are you sure you mean automation and not script? If it is an automation, why do you want to trigger it from the frontend? Normally you’d put the actions in a script instead, which, of course, can also be called from an automation if you also need it run, you know, automatically. :wink:

You’re only supposed to trigger automations manually to test them. Sounds like you should use a script ang get the automation to call the script too to save duplication. Then you can use a button.

1 Like

Yes… If you use a boolean, normally off… With a button card, you set this boolean to on with a click (tap_action) and in your automation trigger, you check the state of this boolean moving from ‘off’ to ‘on’… Than in your automation actions, you reset the boolean to off and execute other actions you want in this automation… Easy…

1 Like

your idea is what I needed, but how can I

reset the boolean to off and execute other actions you want in this automation

can you help me with the code?

  - service: input_boolean.turn_off
1 Like

You’re really making this difficult on yourself. If you want to run something from the frontend, you should put it in a script, not an automation. (Automations are intended for automating things, not for manual operation.) Then you can run the script directly from the frontend using the entity_id of the script. If you still need/want the automation, then call the script in the action part of the automation as well.

E.g., let’s say this is your automation:

- trigger:
  - step1
  - step2

Move the action steps to a script:

    - step1
    - step2

Now you can call the script from the frontend using the service script.my_script.

And, if you still need to run the steps from the automation:

- trigger:
  - service: script.my_script

i can understand your concern … but now i changed it to an automation assigned to a toggle switch