Store list/dictionary ?!

I know this is an old thread, but I found it while having the exact same problem. So how about storing the dictionary as a string in an input_text

service: input_text.set_value
data_template:
  value: >
        {% set dict = { 'key1':'value1', 'key2':'value2', 'key3':'value2' } %}
        {{ dict }}
target:
  entity_id: input_text.my_dict

You can then restore it like this:

{% set dictstr = states('input_text.my_dict').replace("{","").replace("}","").replace("'","").split(", ") %}
{% set n = namespace(dict=[]) %}
{% for i in dictstr %}
{% set pair = i.split(":") %}
  {% set n.dict = n.dict + [(pair[0], pair[1])] %}
{% endfor %}
{% set dictrestored = dict.from_keys(n.dict) %}

Not a very nice solution but at least it is working without custom integrations.

2 Likes