I’m doing a BluePrint (that I will share) to control RGB lights from a Milight remote. I’m almost done, but I’m scratching my head to figure the right syntax to transfer a MULTIPLE entities input into a template variable.
I see you struggling a bit, but I’m not getting a good picture of what you have going on.
Perhaps share the whole thing?
I should be able to offer some advice then.
triggers:
- trigger: mqtt
# this works ################
topic: "milight/state/{{ device_id }}/{{ device_type }}/2"
variables:
# THIS DOESNT WORK ############
light_target: "{{ light2 }}"
while device_id and device_type are correctly interpreted, in the topic line, light2 is NOT!
I’ve also tried to put light2 into variables: instead of trigger_variables:
variables:
light2: !input light2
but this is also not interpreted correctly.
BTW, I miss an easy method to log/debbug the content of a variable (being a string, an array or an object), ie via an “action” to print it in the “trace”. Possible? Any advice?
blueprint:
name: Milight Remote 8 Zones
description: Links a Milight remote (using ESPMH) to light entities
domain: automation
author: Soif
input:
mqtt:
name: ESPMH MQTT Topic
icon: mdi:cog
description: "ESPMH publishes in the MQTT topic: milight/state/DEVICE_ID/DEVICE_TYPE/group_id"
input:
device_id:
name: MQTT Device ID
description: ""
default: "0x19EF"
selector:
text:
device_type:
name: MQTT Device Type
description: ""
default: "rgb_cct"
selector:
text:
buttons:
name: Lights
icon: mdi:cog
description: "Define the light entities to be controlled by each Zone button"
input:
light0:
name: Zone 0 (Master) Lights
description: "This is normally the Master zone switch. Leave it Blank to control all other defined lights below. Else to act as an independant switch, fill the entities to be controlled"
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light1:
name: Zone 1 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light2:
name: Zone 2 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light3:
name: Zone 3 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light4:
name: Zone 4 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light5:
name: Zone 5 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light6:
name: Zone 6 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light7:
name: Zone 7 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
light8:
name: Zone 8 Lights
description: ""
default: []
selector:
entity:
multiple: true
filter:
domain:
- light
trigger_variables:
device_id: !input device_id
device_type: !input device_type
light0: !input light0
light1: !input light1
light2: !input light2
light3: !input light3
light4: !input light4
light5: !input light5
light6: !input light6
light7: !input light7
light8: !input light8
triggers:
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/0"
#id: master
variables:
# This my goal at the end, once I finally found how to :
# - get {{ lightX }} correctly replaced
# - verify that the light1 + light2 ... is the correct way to merge arrays
light_target: >-
{% if light0 ==[] %}
{{ light1 + light2 + light3 + light4 + light5 + light6 + light7 + light8 }}
{% else %}
{{ light0 }}
{% endif %}
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/1"
variables:
light_target: !input light1
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/2"
variables:
light_target: !input light2
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/3"
variables:
light_target: !input light3
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/4"
variables:
light_target: !input light4
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/5"
variables:
light_target: !input light5
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/6"
variables:
light_target: !input light6
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/7"
variables:
light_target: !input light7
- trigger: mqtt
topic: "milight/state/{{ device_id }}/{{ device_type }}/8"
variables:
light_target: !input light8
conditions: []
actions:
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.payload_json.state =='ON' }}"
sequence:
- action: light.turn_on
data:
rgb_color:
- "{{ trigger.payload_json.color.r }}"
- "{{ trigger.payload_json.color.g }}"
- "{{ trigger.payload_json.color.b }}"
brightness_pct: "{{ (trigger.payload_json.brightness / 255 * 100)| int }}"
target:
entity_id: "{{ light_target }}"
- conditions:
- condition: template
value_template: "{{ trigger.payload_json.state =='OFF' }}"
sequence:
- action: light.turn_off
target:
entity_id: "{{ light_target }}"
data: {}
mode: single
This works fine for Light1 to Light8, when I fill a SINGLE light in the corresponding inputs.
Here are my two issues:
(1) I did not found the right syntax in the trigger template (for light0) to simply evaluate the light0 variable. I’ve put the full pseudo jinja code in this post, but right now I simply test with : light_target: "{{ light0 }}" and it just dont work.
(2) If i put multiple entities, ie in light1 input, it doesn’t throw any error, but it just dont do anything…
Notice how I put the input inside the triggers’ variables section, not the trigger_variables section. The variables section on individual triggers do not populate the namespace with trigger_variables.
As a sidebar, it’s very interesting how you have each light section allow multiple lights, however your mqtt triggers only accept 1.