How to use trigger source in an action

Hi,

I have automation with several triggers, how can I know the source in order to create a conditional template to define a different comfort temperature according to a flag which will indicate Comfort +.

My wish is to limit the number of automations … Otherwise I could do that with multiple copy / paste …

- alias: 'CONFORT Séjour Semaine'
  trigger:
  - platform: template
    value_template: '{{ states.sensor.time.state == states.input_datetime.sejour_start_semaine_matin.state[0:5] }}'
  - platform: template
    value_template: '{{ states.sensor.time.state == states.input_datetime.sejour_start_semaine_midi.state[0:5] }}'
  - platform: template
    value_template: '{{ states.sensor.time.state == states.input_datetime.sejour_start_semaine_soir.state[0:5] }}'

# Conditions are used for other things... time:, workday: etc...

  action:
  - service: climate.set_temperature
    entity_id: climate.thermostat_sejour
    data_template:
      temperature: '{% if is_state("input_boolean.boost_sejour_semaine_matin", "on") %}
                      {{ states.input_number.consigne_confort_plus.state }}
                   {%-elif is_state("input_boolean.boost_sejour_semaine_matin", "off") %}
                      {{ states.input_number.consigne_confort.state }}
                   {% endif %}'

Flag is input_boolean, Start time is input_datetime

Temperatures are input_number

Trigger is an object available in automation templates.

Yes, I have Google and I read this, but I find an exemple…

There is an example at the bottom of the page @brahmafear linked to.

trigger.entity_id

Also to prevent errors do not use these forms:

states.sensor.time.state

states.input_datetime.sejour_start_semaine_matin.state[0:5]

Use these instead:

states('sensor.time')

states('input_datetime.sejour_start_semaine_matin')[0:5]
1 Like

Thank you @tom_l for your constructive remarks.

However “{{trigger.entity_id}}” returns me “sensor.time” but not which of the three triggers …

You could put the same templates from your trigger section in an if-elseif block in action section to determine which evaluated to true.

1 Like

My result (in french)