Automation with push messages and different text

Hi there

My HA instance is decoding messages and with some messages text I want to receive an push messages.

The text fields are:
P1 message with sound 1
P2 message with sound 2
“others” message with sound 2

I have one automation searching for text I’ll display that at the end. What I want is that the pushed messages depends on the hits on the 3 text above?

alias: P2000 P1/2
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.p2000_catchall_2
    attribute: raw message
condition: []
action:
  - service: notify.mobile_app_iphone11
    data:
      title: Prio 1
      message: >-
        {% if is_state('A1' in state_attr('sensor.p2000_catchall_2', 'raw
        message')) == true %}  Priority 1
        {% else %}            
        Priority 2        
        {% endif %}
mode: single

the above is not working

alias: P2000 LLN ZST of BNK
description: Lifeliner words
trigger:
  - platform: state
    entity_id:
      - sensor.lln
condition:
  - condition: or
    conditions:
      - condition: template
        value_template: "{{ ('Hometown' in state_attr('sensor.lln', 'raw message')) == true }}"
action:
  - service: notify.mobile_app_iphone11
    data:
      title: Lifeliner  hometown
      message: "{{ states.sensor.lln.state }}"
      data:
        url: /lovelace/p2000
        push:
          sound: RDCS5TVO.wav
mode: single
message: >-
      {% set x = trigger.entity_id %}
      {% set ok = state_attr(x, 'raw message') is iterable %}
      {% set raw = state_attr(x, 'raw message') if ok %}
      {{ 'Priority 1' if 'A1' in raw else 'Priority 2' }}

Thanks

could you elaborate a bit more on this?

{% set x = trigger.entity_id %}

The related automation gets triggered by sensor.p2000_catchall_2 .


trigger:
  - platform: state
    entity_id:
      - sensor.p2000_catchall_2

That’s called the trigger.entity_id (= trigger variable).

1 Like