Create helper via jinja dict in configuration.yaml

This is part of a much larger project of mine, so while I’m aware there are more proper ways of doing this, I want to see if anyone knows how to do this specific thing.

I want to create an input_text via a package in configuration.yaml (I’m using the include_dir_merge_named method of creating packages). I want to make the input_text using a jinja dict, primarily because my ultimate goal is to create a list of input_text’s based on the contents of a group in home assistant.

This is the correct way to create an input_text in the config file

      max: 255
      initial: 'hi'

I’m trying to accomplish the most basic piece here, so instead of doing the above configuration I want to do the configuration using a jinja dict like I have here:

  input_text: |
    {% set testval = {"default1": {"max": 255, "initial": 'hi'}} %}
    {{ testval }}

When I try to use this config and reload my yaml in the dev tools, I get an error:

Setup of package 'bulb_setting_default' failed: Invalid package definition 'bulb_setting_default': expected dict for dictionary value @ data['input_text']. Package will not be initialized

This is not unexpected, however I still feel this is possible because I’m doing something hacky in my automations where I set the data of a light using json from a text_helper like so:

service: light.turn_on
continue_on_error: true
metadata: {}
data: |
  {{states('input_text.default_bedtime_color') | from_json}}
    - upstairs_hallway
    - living_room
    - light.children_s_bedtime_lights_off

The content of input_text.default_bedtime_color is this:


So my problem is that it works in an automation, but not in a config file. If I can get this working it will make my blueprint significantly smaller. If anyone knows a way to create helpers dynamically please let me know, thanks!

YAML is processed first, Jinja2 is processed second.

That’s why you can’t use Jinja2 templates to generate YAML configurations.