Template Syntax Error?

Hi all,

„Services“ can not executive the following lines. „Syntax Error“ it sais….

service: scene.create
data:
  scene_id: vorherige_werte
  snapshot_entities: "{{ expand(states.light) |select("search", 'light.dg_dg_bad') |map(attribute='entity_id') |list }}"

The Template Editor showes the following as result:
service: scene.create
data:

  scene_id: vorherige_werte
  snapshot_entities: "['light.dg_dg_bad_wandlicht', 'light.dg_dg_bad', 'light.dg_dg_bad_wand2', 'light.dg_dg_bad_wand1']"

Other try:

service: scene.create
data:
  scene_id: vorherige_werte
  snapshot_entities: "{{ area_entities('dg_bad') }}"

has the same syntax(???) an works fine…

Template Editor result:

snapshot_entities: "['sensor.dg_dg_bad_turkontakt_id112_battery', 'binary_sensor.dg_dg_bad_turkontakt_id112_contact', 'sensor.dg_dg_bad_turkontakt_id112_device_temperature', 'sensor.dg_dg_bad_turkontakt_id112_power_outage_count', 'sensor.dg_dg_bad_taster_battery_level', 'event.dg_dg_bad_taster_button_1', 'event.dg_dg_bad_taster_button_2', 'event.dg_dg_bad_taster_button_3', 'event.dg_dg_bad_taster_button_4', 'light.dg_dg_bad_wand1', 'light.dg_dg_bad_wand2', 'light.dg_dg_bad']"

No ideas? Maybe something unclear?

alias: "___test "
sequence:
  - variables:
      entities: >-
        expand(states.light) |select("search", 'light.dg_dg_bad')
        |map(attribute='entity_id') |list }}
  - service: scene.create
    data:
      scene_id: vorherige_werte
      snapshot_entities: "{{ entities }}"
mode: single

Does Not work either, why is “entities” not valid??:

Entity ID expand(states.light) |select(“search” is an invalid entity ID for dictionary value @ data[‘snapshot_entities’]

The following template is missing {{

      entities: >-
        expand(states.light) |select("search", 'light.dg_dg_bad')
        |map(attribute='entity_id') |list }}

Without the leading {{ it is interpreted as a literal string, not a template, so that’s why you got an error message complaining that it’s an invalid entity_id.

thank you very much.
I still do not understand why the variable is needed as “transformation” - but is works now → thanks again for looking at the code - I was blind.

1 Like