MQTT motion sensor

Hello,

I’m trying to get my motion sensor to work in an automation but I’m failing to find out how the payloads its sending over mqtt shall be configured and used.

The sensor works fine and toggles between “motion detected” and “standby” when I trigger it.
I’ve tried to define it as a binary sensor but that doesn’t seem to work either.

Any tip would be greatly appreciated.

Sensor defined as the following works fine in HA - can view live status in a card:

  - platform: mqtt  
    state_topic: "huset/sensornode1"
    name: "SN1 PIR"  
    value_template: '{{ value_json.motion }}'  



#BinarySensorTest

  platform: mqtt
  state_topic: "huset/sensornode1"
  name: "Källare (Rörelse)"
  qos: 0
  payload_on: "motion detected"
  payload_off: "standby"

Above doesn’t work…

And using the default sensor declaration in the following automation doesn’t work either.

#Automation 1#
  - alias: PIR 1  On
    trigger:
      - platform: mqtt
        topic: "huset/sensornode1"
        payload: 'motion detected'
    action:
       service: light.turn_on
       entity_id: light.sn1_led

#Automation 2#
  - alias: PIR 1  Off
    trigger:
      - platform: mqtt
        topic: "huset/sensornode1"
        payload: 'standby'
    action:
        service: light.turn_off
        entity_id: light.sn1_led

If this works, it means that the incoming MQTT message is encoded in JSON format, which means your binary sensor must decode this. At the moment it is expecting just text in the data. To get the binary_sensor to decode JSON, you need to add the value_template line to its definition.