You use a template to produce a value that will be assigned to an option.
some_option: "{{ template to produce a value for "some_option" }}"
You cannot use a template to produce options.
data: "{{ template producing more options and values }}"
Try this version:
- alias: co2_alarm
description: "CO2 - Ampel"
trigger:
- platform: state
entity_id:
- sensor.netatmo_unser_heim_wohnzimmer_buro_co2
- sensor.netatmo_unser_heim_wohnzimmer_kuche_co2
- sensor.netatmo_unser_heim_wohnzimmer_co2
action:
- service: input_text.set_value
target:
entity_id: >-
{% set ent = trigger.entity_id %}
{% if ent == 'sensor.netatmo_unser_heim_wohnzimmer_buro_co2' %}
input_text.co2_buero
{% elif ent == 'sensor.netatmo_unser_heim_wohnzimmer_kuche_co2' %}
input_text.co2_kueche
{% elif ent == 'sensor.netatmo_unser_heim_wohnzimmer_co2' %}
input_text.co2_wohnzimmer
{% endif %}
data:
value: >-
{% set co2 = trigger.to_state.state | int %}
{% if co2 <= 800 %} grün mit {{ co2 }} ppm
{% elif 800 < co2 <= 1000 %} gelb mit {{ co2 }} ppm
{% elif 1000 < co2 <= 1400 %} orange mit {{ co2 }} ppm
{% else %} rot mit {{ co2 }} ppm
{% endif %}
mode: queued
If you wish, you can replace all of this:
entity_id: >-
{% set ent = trigger.entity_id %}
{% if ent == 'sensor.netatmo_unser_heim_wohnzimmer_buro_co2' %}
input_text.co2_buero
{% elif ent == 'sensor.netatmo_unser_heim_wohnzimmer_kuche_co2' %}
input_text.co2_kueche
{% elif ent == 'sensor.netatmo_unser_heim_wohnzimmer_co2' %}
input_text.co2_wohnzimmer
{% endif %}
with this:
entity_id: >-
{% set oid = trigger.to_state.object_id %}
input_text.co2_{{ 'buero' if 'buro' in oid else 'kuche' if 'kueche' in oid else 'wohnzimmer' }}
Sorry but I really don’t know what you are talking about. I do not produce more options and/or values. How did you come to this? Please be more precise.
Anyway, I figured out I had a typo and the code is running now. That’s why I really want to understand what you are talking about.
Wonderful, post the corrected version so we can all see that one typo you claimed it had.
You can’t template target and you can’t declare data_templateanddata under target because it counts as two instances of the same option (because data_template is the equivalent of data).
That may allow it to pass Check Configuration but, upon execution, errors will be reported in Log.
Try the example I posted above or this reduced version:
- alias: co2_alarm
description: "CO2 - Ampel"
trigger:
- platform: state
entity_id:
- sensor.netatmo_unser_heim_wohnzimmer_buro_co2
- sensor.netatmo_unser_heim_wohnzimmer_kuche_co2
- sensor.netatmo_unser_heim_wohnzimmer_co2
action:
- service: input_text.set_value
target:
entity_id: >-
{% set oid = trigger.to_state.object_id %}
input_text.co2_{{ 'buero' if 'buro' in oid else 'kuche' if 'kueche' in oid else 'wohnzimmer' }}
data:
value: >-
{% set co2 = trigger.to_state.state | int %}
{% set x = 'grün' if co2 <= 800 else 'gelb' if 800 < co2 <= 1000 else 'orange' if 1000 < co2 <= 1400 else 'rot' %}
{{ x }} mit {{ co2 }} ppm
mode: queued
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. It will also place a link below your first post that leads to the solution post. All of this helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.
trigger:
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.home_outer_ring
event: enter
action:
- service: input_datetime.set_datetime
target:
entity_id: >-
{% set enter = trigger.zone.object_id %}
input_datetime.doris{{ 'outer' if 'outer' in enter }}
I tried the following and it didn‘t work. Just the else part is working.
- alias: doris_enter
trigger:
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.home_outer_ring
event: enter
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.davids_home_middle_ring
event: enter
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.home
event: enter
action:
- service: input_datetime.set_datetime
target:
entity_id: >-
{% set oid = trigger.to_state.object_id %}
input_datetime.doris_{{ 'outer' if 'outer' in oid else 'middle' if 'middle' in oid else 'home' }}
data:
datetime: "{{ now().strftime('%Y-%m-%d %H:%M') }}"
mode: single
I don’t have any device_trackers or zones so I can’t test anything for you. In this situation you have three separate triggers so it’s more efficient to simply assign an id to each trigger and use that in the template.
- alias: doris_enter
trigger:
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.home_outer_ring
event: enter
id: 'outer'
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.davids_home_middle_ring
event: enter
id: 'middle'
- platform: zone
entity_id: device_tracker.doris_iphone_2
zone: zone.home
event: enter
id: 'home'
action:
- service: input_datetime.set_datetime
target:
entity_id: "input_datetime.doris_{{ trigger.id }}"
data:
datetime: "{{ now().timestamp() | timestamp_local }}"
mode: single