Automation, service template and multiple notification

Hi Forum,
I’m searching for a solution which involves a service template to create different notification messages according to the trigger entity for the automation. I’ve created a draft which doesn’t work and hope that a clever dude could help me finish this automation.

Here’s my code (where my problems are at the action lines):

- alias: 'NOTIFIKATION: Too hot in a room, test.'
  trigger:
    - platform: numeric_state
      entity_id: sensor.living_temp
      above: 25
    - platform: numeric_state
      entity_id: sensor.bath_temp
      above: 30
    - platform: numeric_state
      entity_id: sensor.bed_temp
      above: 25
    - platform: numeric_state
      entity_id: sensor.office_temp
      above: 25
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: " {{ states.sensor.average_temperature.state <= states.sensor.yr_temperature.state }} "
  action:
    - service: notify.ios_iphone_xr
      data_template:
        title: "Temperature in room..."
        message: >
          {% if 'trigger.entity_id' = 'sensor.living_temp' %}
            "Notification text 1"
          {% if 'trigger.entity_id' = 'sensor.bath_temp' %}
            "Notification text 2"
          {% if 'trigger.entity_id' = 'sensor.bed_temp' %}
            "Notification text 3"
          {% if 'trigger.entity_id' = 'sensor.office_temp' %}
            "Notification text 4"
          {% endif %}

Remove the quotes around your trigger.entity_id, add a second equal sign too. Also, you don’t have to but probably should use else ifs.

    - service: notify.ios_iphone_xr
      data_template:
        title: "Temperature in room..."
        message: >
          {% if trigger.entity_id == 'sensor.living_temp' %}
            "Notification text 1"
          {% elif trigger.entity_id == 'sensor.bath_temp' %}
            "Notification text 2"
          {% elif trigger.entity_id == 'sensor.bed_temp' %}
            "Notification text 3"
          {% elif trigger.entity_id == 'sensor.office_temp' %}
            "Notification text 4"
          {% endif %}
1 Like

was about to reply but I see @petro is already on it. You’re on good hands

1 Like

Also, if you want to be super lazy…

    - service: notify.ios_iphone_xr
      data_template:
        title: "Temperature in room..."
        message: >
          {{ trigger.to_state.name }} is {{ trigger.to_state.state }}

This will use the friendly name of the triggering device and the state.

This look exactly as my intially thoughts. But what if I want to add a small amount of fixed text before the name of the trigger obejct, how do I implement that?

just add it like this

    - service: notify.ios_iphone_xr
      data_template:
        title: "Temperature in room..."
        message: >
          small bit of text {{ trigger.to_state.name }} is {{ trigger.to_state.state }}

If it makes you feel warm and fuzzy, you can add quotes

    - service: notify.ios_iphone_xr
      data_template:
        title: "Temperature in room..."
        message: >
          "small bit of text {{ trigger.to_state.name }} is {{ trigger.to_state.state }}"
3 Likes

LMFAO !!! been digging down SQL statements for so many hours, you brought a ray of sunshine in my grey code :smiley:

1 Like