Is it possible to re-use a large dictionary in several automation templates?

In 3 templates of one action I need to use a rather large dictionary.
Basically, I’m trying to fill in event_data like this:

- event: test
  event_template_data:
    value1: >-
      {% set dict = {...} %}
      {{ ... }}
    value2: >-
      {% set dict = {...} %}
      {{ ... }}
    value3: >-
      {% set dict = {...} %}
      {{ ... }}

I tried to use template sensor, but there is state’s length limit of 255 symbols, my dict is bigger than that.
Any other idea how to avoid pasting the same dict in each template?

My dict looks like:

{
         'sensor/pir/ground_floor/hall': {'codes': {13937454: {'state': 'detected', 'command': 'ON'}}},
         'wall_switch/1st_floor/bathroom/extractor_fan': {
            'codes': {
              12001361: {'state': 'on', 'command': 'ON'},
              12001360: {'state': 'off', 'command': 'OFF'}
            }
          },
          'sensor/contact/1st_floor/safe': {
            'codes': {
              8895854: {'state': 'open', 'command': 'Open', 'retain': true},
              8895847: {'state': 'closed', 'command': 'Closed', 'retain': true},
              8895851: {'state': 'tampered', 'command': 'Tampered'}
            },
            'attributes': {
              8895855: {'name': 'low_battery', 'command': 'ON'}
            }
          }
}

You might be easier off moving this to use a python script or something where you can reuse this easier.

You are limited by what you can do in the YAML configs.

But there are several clever folks on here that likely will have a way to optimize it :wink:

states are restricted to 255 chars but attributes are unlimited AFAIK

the question is how to use that knowledge… I don’t know how to deal with attributes :\

I’d suggest using AppDaemon (https://appdaemon.readthedocs.io/en/latest/). It’s really better for doing things like this (and at least IMO, it’s a better way to do most automations).

Thanks for the suggestion.
I don’t know if I can run Hass.io AND AppDaemon on my RPi3 though… will have a read.

Yaml has anchors and references, maybe you can use these to avoid duplicating.

https://blog.daemonl.com/2016/02/yaml.html