I think we should have a way to define variables in automations/blueprints that could be accessed in different automations instances and that survive different calls. A Global Variable that could be set and got in posterior calls to that automation.
This variable should only be accessible from the automation they were declared.
I’m aware that this can be achieved with an input text helper or through the hass_variables component, but it shouldn’t be necessary to create a different entity just to make data available in an automation. I really think this messes up with some basic coding principles.
Also this could be helpful in Blueprints. I’ve already seen multiple blueprints that require you to separately create a helper to achieve this functionality.
What i suggest would be add a property global_variables apart from the existing variables one.
Then it could be stored as a state for the automation: states.automations.my_automation.global_variables.
This is a long-standing (at least 4 years) wish that has never been granted. Until it’s implemented, if ever, you can store information using a Trigger-based Template Sensor (no custom integration required).
Example 1
The following example demonstrates how to create a sensor that can store a single value of type string, limited to 255 characters (same as an Input Text).
The example can be enhanced to store a single value of any type without a size limitation by simply storing it as an attribute.
Example 2
Here’s a more sophisticated version. A single sensor that’s able to store multiple values of any type (string, int, float, list, dict, boolean, etc) and size.
For both examples, you use a native event call to store a value (i.e. no custom service call is employed).
The advantage of using a Trigger-based Template Sensor, instead of Input Helpers, is that the stored value isn’t limited to being a string (under 255 characters long) but any type and size plus it’s read-only in the UI (i.e. a user can’t easily/accidentally/maliciously modify it).