(SOLVED) Automation: mqtt payload contains / partial value

Hi everybody,

this is an attempt to trigger a notification when receiving an mqtt payload. However, the trigger is only part of the payload; the actual payload changes each time the hardware sensor transmits a signal, only this part I am trying to grab is always the same.

- id: '1564422825033'
  alias: '433'
  trigger:
  - payload: A4830A
    platform: mqtt
    topic: espurnarf/rfin
  condition: []
  action:
  - data:
      data:
        color: red
        duration: 3
        fontsize: max
        interrupt: 0
        position: top-left
        transparency: 35%
      message: Tor wurde geƶffnet.
      title: Oh nein!
    service: notify.schlafzimmer

The static part is A4830A, so the payload I might receive could be ADF43D4666A4830A or KKJD99829A4830A, etc. etc.

I have also tried setting up an mqtt sensor for this, and then tried this automation

- id: '1564423885318'
  alias: 433testNEU
  trigger:
  - entity_id: sensor.433mhz_signal
    platform: state
    to: '*HALLO'
  condition: []
  action:
  - data:
      data:
        color: red
        duration: 2
        fontsize: large
        interrupt: 1
        position: center
        transparency: 0%
      message: Messagetext
      title: My Notification
    service: notify.schlafzimmer

However, this will only trigger *HALLO, but not ADD345HALLO etc.

Is there a way to filter for this partial value so that I can trigger a notification each time my hardware sensor (in this case a 433MHz door sensor) transmits the ā€œopenā€ payload, which changes each time?

Thanks in advance for your ideas :slight_smile:

Use templates in combination with the endswith() method for strings. This automation will only trigger if the condition is met. The condition will only be true if the payload endswith the text 'A4830A'.

- id: '1564422825033'
  alias: '433'
  trigger:
  - platform: mqtt
    topic: espurnarf/rfin
  condition:
  - condition: template
    value_template: >
      {{ trigger.payload.endswith('A4830A') }}
  action:
  - data:
      data:
        color: red
        duration: 3
        fontsize: max
        interrupt: 0
        position: top-left
        transparency: 35%
      message: Tor wurde geƶffnet.
      title: Oh nein!
    service: notify.schlafzimmer
1 Like

Awesome, thank you so much! Works perfectly :slight_smile: