Help with automation to parse mqtt payload

I need some help on an automation. My blinds wake up every 30 minutes and send an MQTT message with two parameters: state and flux_value. I have an automation that looks for the topic and sends me a message to my phone. Everything works fine, however I would like to format the message I receive.

This is my automation:

#BLINDS MESSAGE
- alias: message from blinds
  initial_state: true
  trigger:
    - platform: mqtt
      topic: house/ha/+
     
  action:
    - service: notify.ios_iphonex
      data_template:
        title: "Blind"
        message: >-
          {% set blind_var = trigger.topic|replace('house/ha/', '') %}
          {% set blind_val = trigger.payload %}
          {{ blind_var }} value {{blind_val}}

The message that I am receiving looks like this:

blind3 value{"state":"closed","flux_value":"368"}

Is there a way I can parse or just get one of the values? I would like the message to be:
blind3 is closed.

Thanks in advance for your help.

Is this not as simple as doing:

{{ blind_var }} blinds are {{blind_val.state}} Flux: {{blind_val.flux_value}}

?

Thanks for your quick response. I knew that it was simple but and I just needed a new set of eyes to see it from a different perspective. I really appreciate your help!

Hi Paul.

I tried your solution and unfortunately it didn’t work.

I believe you need to use trigger.payload_json.

    action:
    - service: notify.ios_iphonex
      data_template:
        title: "Blind"
        message: >-
          {% set blind_var = trigger.topic|replace('house/ha/', '') %}
          {{ blind_var }} blinds are {{trigger.payload_json.state}} Flux: {{trigger.payload_json.flux_value}}

Yes, that did it. Thank you very much to all for your help.

1 Like