After long time searching I am out of ideas and maybe I found a bug…
I want to call the service set_temperature in an automation on multiple device_id as target. These device_ids are generated by a template. After many try-and-error I finally found a way to hand it over as a list. But the system still throws an error. Here my setup:
Using this macro:
{% macro get_devices_by_label_with_excludelist(get_label, exclude_list=[]) -%}
{% set ns = namespace(devices=[]) -%}
{% set ns.devices = label_devices(get_label) -%}
{% for l in exclude_list -%}
{% set ns.devices = ns.devices|reject('in', label_devices(l)|list) -%}
{% endfor -%}
{{ ns.devices|join(",") }}
{% endmacro -%}
I call the following automation (here only the important bit):
I use here ccd for the list of devices and cce for the list of entities within the devices. Why? I will explain later!
variables:
get_label: heizgruppe
exclude_list:
- badezimmer
control_climate_devices: >
{%- from 'labels.jinja' import get_devices_by_label_with_excludelist -%}
{{ get_devices_by_label_with_excludelist(get_label, exclude_list) }}
ccd: "{{ control_climate_devices.split(',') }}"
cce: "{{ control_climate_devices.split(',') | map('device_entities') | sum(start=[])| select('is_state', 'heat')| sort }}"
Using ccd
, the list of devices, is not working.
sequence:
- action: climate.set_temperature
metadata: {}
data:
temperature: "{{ states('input_number.home_heizung_raum_tages_temperatur') }}"
target:
device_id: >-
{{ ccd }}
alias: Zieltemperatur für normale Räume setzen
Here is the trace output of the variables section:
control_climate_devices: >-
0812835ce77e70e60c03844965660b3a,7d26100c74eb9381829a56dc2a47c532,255a2ded6783d3ff8ec07e51f14cbd1b,8962e94f57dadf53827ce9a9cfc37e27,f989416a8941e4d7d7950e6360570caf,ccdb9ac6389e71ab09392614addb1c49,2cd403863e80e27a566c27dbb1e4a9f1,fd375b022dec43f32157d1593e18fc4a,dce120ab088a86210330527dad12dcdb,bfa95343f68ad3acae9c931b7308fee5,785c77f29e23394d34df2d26bc0fa08e,528598e69db66c02bc34b7b4f9e046c4,b59d91a9a81e8345c7c2d5cd41f065b7,5533f71505a8ec1f951220a1d9f06019
ccd:
- 0812835ce77e70e60c03844965660b3a
- 7d26100c74eb9381829a56dc2a47c532
- 255a2ded6783d3ff8ec07e51f14cbd1b
- 8962e94f57dadf53827ce9a9cfc37e27
- f989416a8941e4d7d7950e6360570caf
- ccdb9ac6389e71ab09392614addb1c49
- 2cd403863e80e27a566c27dbb1e4a9f1
- fd375b022dec43f32157d1593e18fc4a
- dce120ab088a86210330527dad12dcdb
- bfa95343f68ad3acae9c931b7308fee5
- 785c77f29e23394d34df2d26bc0fa08e
- 528598e69db66c02bc34b7b4f9e046c4
- b59d91a9a81e8345c7c2d5cd41f065b7
- 5533f71505a8ec1f951220a1d9f06019
cce:
- climate.home_eg_flur_heizgruppe
- climate.home_eg_kueche_heizgruppe
- climate.home_eg_wcgast_heizgruppe
- climate.home_eg_zimmer1_heizgruppe
- climate.home_eg_zimmer3_heizgruppe
- climate.home_eg_zimmer4_heizgruppe
- climate.home_eg_zimmer5_heizgruppe
- climate.home_ug_flur_heizgruppe
- climate.home_ug_zimmer1_heizgruppe
- climate.home_ug_zimmer2_heizgruppe
- climate.home_ug_zimmer3_heizgruppe
- climate.home_ug_zimmer4_heizgruppe
- climate.home_ug_zimmer5_heizgruppe
And here the error. You can see that the list is treated as a string.
Error: template value should be a string @ data['device_id'][0]
Result:
params:
domain: climate
service: set_temperature
service_data:
temperature: 21.5
device_id:
- - 0812835ce77e70e60c03844965660b3a
- 7d26100c74eb9381829a56dc2a47c532
- 255a2ded6783d3ff8ec07e51f14cbd1b
- 8962e94f57dadf53827ce9a9cfc37e27
- f989416a8941e4d7d7950e6360570caf
- ccdb9ac6389e71ab09392614addb1c49
- 2cd403863e80e27a566c27dbb1e4a9f1
- fd375b022dec43f32157d1593e18fc4a
- dce120ab088a86210330527dad12dcdb
- bfa95343f68ad3acae9c931b7308fee5
- 785c77f29e23394d34df2d26bc0fa08e
- 528598e69db66c02bc34b7b4f9e046c4
- b59d91a9a81e8345c7c2d5cd41f065b7
- 5533f71505a8ec1f951220a1d9f06019
Using cce
, the list of entity_ids, work fine. There is no error.
sequence:
- action: climate.set_temperature
metadata: {}
data:
temperature: "{{ states('input_number.home_heizung_raum_tages_temperatur') }}"
target:
entity_id: >-
{{ cce }}
alias: Zieltemperatur für normale Räume setzen
Result:
params:
domain: climate
service: set_temperature
service_data:
temperature: 21.5
entity_id:
- climate.home_eg_flur_heizgruppe
- climate.home_eg_kueche_heizgruppe
- climate.home_eg_wcgast_heizgruppe
- climate.home_eg_zimmer1_heizgruppe
- climate.home_eg_zimmer3_heizgruppe
- climate.home_eg_zimmer4_heizgruppe
- climate.home_eg_zimmer5_heizgruppe
- climate.home_ug_flur_heizgruppe
- climate.home_ug_zimmer1_heizgruppe
- climate.home_ug_zimmer2_heizgruppe
- climate.home_ug_zimmer3_heizgruppe
- climate.home_ug_zimmer4_heizgruppe
- climate.home_ug_zimmer5_heizgruppe
I have checked multiple times using the UI with non-template hard coded devices such as the following example:
action: climate.set_temperature
data:
temperature: 21.5
enabled: true
target:
device_id:
- 4c8aa5317f7c3a7dfb397ddd4b89b101
- 785c77f29e23394d34df2d26bc0fa08e
Either I do sonething wrong when I use device_id
or there is a bug. Anyone suggestions or can spot my mistake?