I have the blueprint for my Lexman controller. It has 4 buttons for switching scenes and some buttons for on/off, brightness, etc.
By pressing scene buttons I save the alias for group of lights. Then when on/off button is pressed I want turn on/off the group of lights depends on alias selected previously.
To avoid a lot of conditions I just want to keep alias/lights mapping. Something like this:
In the code block below I’m trying to use template to prepare the lights_mapping dictionary but it doesn’t work. What is the best practice to create dictionary with dynamic fields?
blueprint:
name: some name
domain: automation
input:
controller_id:
name: Switch MQTT id
group_1_lights:
name: Group of lights 1
selector:
target:
entity:
domain: light
group_1_name:
name: Name of group 1
group_2_lights:
name: Group of lights 2
selector:
target:
entity:
domain: light
group_2_name:
name: Name of group 2
mode: restart
variables:
name1: !input group_1_name
name2: !input group_2_name
lights1: !input group_1_lights
lights2: !input group_2_lights
lights_mapping: >
{% set dict = {} %}
{% set dict[name1] = lights1 %}
{{ dict }}
And the next question. Is it possible somehow to create dictionary once when automation starts first time and modify it during automation? The idea that each time automation is triggered we have some data from previous automation run?
Now I use input_text to store json. But it’s not convenient to store a lot of data
I want to save current state of light entity controller: color preset, temperature color etc. On my controller I can change light groups and then based on current light group state I want to set next color preset from list, for example. But, to select next one, I want to know the id (or name) of the current one which is stored somewhere.
I’ve tried to use var integration but it has some issue at this moment.
And it’s impossible to update dictionaries. You can’t read json from input_text and update one of its fields. You need to create new dict from scratch on the fly to be able to update input_text value.
You’re not actually updating a dictionary, but creating a new one to replace it which is the same as the old one, but with one of the keys having a new value.