Motion Sensor

Hello I started using Home assistant newly and I got a noob question about my motion sensor connected with Open MQTT Gateway. I want to add it over mqtt. I get the following code {“hcsr501”:“true”} or {“hcsr501”:“false”} if there is motion or not. Its published etc. but Iam to stupid to integrate the sensor into HA. Here is my yaml:

binary_sensor:
  - platform: mqtt
    name: "Bewegung_Schlafzimmer"
    device_class: motion
    state_topic: "home/OpenMQTTGateway1/HCSR501toMQTT"
    #value_template: "{{ trigger.payload_json['hcsr501'] }}"
    payload_on: "{{ trigger.payload_json['hcsr501'] == true }}"
    payload_off: "{{ trigger.payload_json['hcsr501'] == false }}"

But the state is not beeing changed. Any suggestions what Iam doing wrong? Thank you very much :slight_smile:

Not sure, but take a look at the json_attributes_topic of the mqtt binary sensor.

Also there is no ‘trigger.payload’ in the mqtt sensor, this is only available in automations.

Thanks. Got it working.

binary_sensor:
      - platform: mqtt
        name: "Bewegung_Schlafzimmer"
        #device_class: motion
        state_topic: "home/OpenMQTTGateway1/HCSR501toMQTT"
        value_template: '{{ value_json["hcsr501"] }}'
        payload_on: "true"
        payload_off: "false"