Passing values / variables across scripts in an automation

I want to create a number of scripts which I use in a single automation. Is it possible to create a value / variable in either an action or script which I then use in subsequent scripts.

Use case: in the first action (or script) I create a camera snapshot. The next script sends a notification with the snapshot to my mobile phone. The following script sends the snapshot using a persistent notification to HA. The final script sends an email notification of the camera snapshot. I want to have the location available to all scripts.

https://www.home-assistant.io/integrations/script/#passing-variables-to-scripts

1 Like

Here is some pseudo code of what I would like to achieve (yes, I know it will not work). How can I assign the file_path to a variable so that I can use it in multiple actions and I don’t have to hardcode it in multiple actions?

action:
  - service: camera.snapshot
    entity_id: camera.my_camera
    data:
      filename: '{{ *file_path* }}'
  - service: script.email_me
    data:
      filename: '{{ *file_path* }}'
  - service: script.email_you
    data:
      filename: '{{ *file_path* }}'

Reading the link I posted would be a good start. It explains exactly that.

Would it be like this even though it is just the action part of an automation?

variables:
  filepath: "/local/www/tmp/snapshot.jpg"
action:
  - service: camera.snapshot
    entity_id: camera.my_camera
    data:
      filename: '{{ filepath }}'
  - service: script.email_me
    data:
      filename: '{{ filepath }}'
  - service: script.email_you
    data:
      filename: '{{ filepath }}'

Yes. The actions of an automation have identical syntax to scripts. Automations are just scripts with triggers.