How to make an automation for a specific MQTT event (in my case for Sleep As Android)

I’m absolutly new to MQTT and I’m trying to make an automation that triggers only if the MQTT "event": "sleep_tracking_stopped" is triggered. I found that the MQTT event looks like this in the MQTT Broker

Message 15 received on SleepAsAndroid at 9:26 PM:
    "event": "sleep_tracking_stopped"

I’m guessing the code must look something like this, but I’m not quite there:

description: Test
mode: single
  - platform: mqtt
    topic: SleepAsAndroid
  - condition: template
    value_template: "value_template: '{{ "event" == "sleep_tracking_started"}}'
  - type: toggle
    device_id: xxxxxx
    entity_id: light.licht_arbeitszimmer_standlampe_light
    domain: light

Nobody ???

This has a condition example…Issues with Automation Parsing MQTT json Value - #5 by dfiore

1 Like

I’m not at home right but when I compare them this should be the correct syntax:

  - condition: template
    value_template: >-
      {{ trigger.payload_json.event == "sleep_tracking_stopped" }}

Yes it worked!!! Thank you very much. I looked everywhere for a comparable automation…