Camera snapshot button in HA UI

I would like to be able to manually trigger my camera to take a snapshot but not sure of the easiest way to configure this.
I thought I had solved this by creating an automation with an “always true” trigger, then whenever I wanted a snapshot, I simply enabled the automation for a brief moment, then disabled it again.
The always true trigger I used was:

  trigger:
     platform: template
     value_template: "{% if 1 %}true{% endif %}"

The trouble with this trigger is that the automation comes back online (after rebooting Hass.io) as enabled and immediately takes a snapshot (and as part of my desired automation, sends the snaphot to me by Pushbullet). I am now rebooting Hass.io every other night to try and solve the occasional unwanted crashes (host working, but HA unresponsive) and I do not want snapshots being sent to me by Pushbullet at 2am when this happens!

Is there an automation trigger I can use that will allow me to run this automation by clicking on a button in the HA UI?

An alternative - I may be able to use Tasker to run the automation from an api call? I already run other automations this way so perhaps this is the easiest answer!
I will post back my code if I can configure Tasker to achieve this.

Why don’t you put the action of your automation in a script and call it from the UI?

Thanks - this is what I wanted.
I did not have any scripts before and did not understand how to use them, but now have re-written my automation in script syntax and it works perfectly.

For anyone else interested, here is the original automation, usually triggered by PIR sensor movement etc.:

  - alias: 'Living Room Security Camera'
    trigger:
      platform: state
      entity_id: sensor.living_room_pir
      from: 'OFF'
      to: 'ON'
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: 'device_tracker.julian_phone'
          state: 'not_home'
        - condition: state
          entity_id: 'device_tracker.anne_phone'
          state: 'not_home'
    action:
      - service: camera.snapshot
        data:
          entity_id: camera.minicam
          filename: '/config/snapshots/MiniCamSnap.jpg'
      - service: camera.snapshot
        data:
          entity_id: camera.minicam
          filename: '/config/snapshots/MiniCam_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg'
      - service: notify.pushfromha
        data: 
          data:
            file: '/config/snapshots/MiniCamSnap.jpg'
          title: "Living Room Snapshot Taken"
          message: "A snapshot has been taken in the Living Room"

and here is the stand-alone script which allows me to trigger a snapshot from this camera at any time, using the web UI:

living_room_snapshot:
  alias: 'Living Room Snapshot'
  sequence:
    - service: camera.snapshot
      data:
        entity_id: camera.minicam
        filename: '/config/snapshots/MiniCamSnap.jpg'
    - service: notify.pushfromha
      data: 
        data:
          file: '/config/snapshots/MiniCamSnap.jpg'
        title: "Living Room Snapshot Taken"
        message: "A snapshot has been taken in the Living Room"
3 Likes