I’m trying to pass a list of entity_ids to the target
field of an action, but am running into a very basic problem:
actions:
- variables:
thermostats: |
{{ [ states.climate.mbr_thermostat,
states.climate.mbr_bath_thermostat ] }}
- variables:
active_thermostats: "{{ thermostats | map(attribute='entity_id') | list }}"
- action: climate.set_fan_mode
metadata: {}
data:
fan_mode: Low
target: "{{ {'entity_id': active_thermostats } }}"
I split the variable definitions into two different actions so I could see each step in the trace. The first step produces the trace output I would expect:
thermostats: >-
[<template TemplateState(<state climate.mbr_thermostat=cool;
hvac_modes=[<HVACMode.OFF: 'off'>, <HVACMode.HEAT: 'heat'>, <HVACMode.COOL:
'cool'>], min_temp=32.0, max_temp=122.0, fan_modes=['Auto low', 'Low',
'Circulation'], preset_modes=['none', 'Energy heat', 'Energy cool'],
current_temperature=74, temperature=75, current_humidity=47, fan_mode=Low,
hvac_action=idle, preset_mode=none, fan_state=Running / running low,
friendly_name=Master Bedroom Bedroom Thermostat , supported_features=409 @
2025-05-17T12:39:46.987462-04:00>)>, <template TemplateState(<state
climate.mbr_bath_thermostat=off; hvac_modes=[<HVACMode.OFF: 'off'>,
<HVACMode.HEAT: 'heat'>, <HVACMode.COOL: 'cool'>], min_temp=32.0,
max_temp=122.0, fan_modes=['Auto low', 'Low', 'Circulation'],
preset_modes=['none', 'Energy heat', 'Energy cool'], current_temperature=74,
temperature=None, current_humidity=48, fan_mode=Low, hvac_action=idle,
preset_mode=none, fan_state=Running / running low, friendly_name=Master
Bedroom Bathroom Thermostat , supported_features=409 @
2025-05-17T12:39:46.973856-04:00>)>]
but the second step gives
active_thermostats: >-
[Undefined, Undefined, Undefined, Undefined, Undefined, Undefined, Undefined,
Undefined, Undefined, Undefined, Undefined, Undefined, Undefined, Undefined,
<snip 150 more lines of the same>
If my second variable is just active_thermostats: "{{ thermostats }}"
, that produces a second copy of the list as you would expect, so it’s able to access the thermostats
variable. And if I tack on | map(attribute='entity_id') | list
to my first variable, it produces the list entity_ids I expect. When I split them out, though, I get the huge mass of Undefined
s.
- What’s going on here?
- Is there a better way to pass a list to the target of an action?