MQTT Binary Sensor doesn't Appear

Hi Community –
I copied and pasted a binary sensor snippet, which works without any issues, from another Home Assistant instance. I modified the topic to the correct one, I restarted the new instance, but the sensor is not listed anywhere. Is it possible to help me please?

mqtt:
  binary_sensor:
    - name: "Apt 2 Front Door Sensor"
      unique_id: "apt_2_front_door_sensor"
      state_topic: "stat/esprfidapt2/io/door"
      device_class: Door
      state_topic: 'tele/tasmota_018A55/RESULT'
      value_template: "{{ value_json.RfReceived.Data }}"
      payload_on: "5362F2" 
      payload_off: "5362f3"    
      device_class: door

You forgot to state payload on/off. See above example.

Hey –thanks for your response. I had a similar setup before, but couldn’t find the unique_id on the ‘States’ page. I added your suggestions, restarted Home Assistant, but still… Is there a possibility that something else is wrongly configured? Many thanks!

Maybe show your new configuration

mqtt:
  sensor:
    - name: "Apt 1 Front Door Magnetic Sensor"
      unique_id: "apt_1_front_door_magnetic_sensor"
      state_topic: "stat/esprfidapt1/io/door"
      value_template: "{{ value_json.RfReceived.Data }}"
      payload_on: "ON" 
      payload_off: "OFF"
      device_class: Door

I think you might replace

with

  binary_sensor:

What is the json for your sensor? The example and template were just for one of my sensors. Show the payload from mqttexplorer for your sensor

{"model":"Smoke-GS558","id":723,"unit":6,"learn":0,"code":"705a66","protocol":"Wireless Smoke and Heat Detector GS 558","rssi":-66,"duration":1160995}

ZXZXZZXX001X
ZXZXZZXX00XX

The above example that starts with model that has the curly brackets will need a value_template to find code: 705a66 when door opens but lower example only needs a state_topic wth the payload being ZXZXZZXX001X for on and ZXZXZZXX00XX for off.

Is your new ha connected to the mqtt broker? Is your door device connected to the same broker? What do you see in your broker?

Here’s a screenshot from MQTT Explorer:

Initially, I had it as binary_sensor, but didn’t make any difference.

As per my understanding, the output is either ON or OFF, which is defined with payload_on and payload_off. Any other thoughts?

The MQTT Broker is through the Home Assistant add-on –not sure if this helps. The device is indeed connected to the same broker. See screenshot below for the output. Thanks again for your help!

Get rid of the value_template line: that was for Spiro’s example which had JSON in the topic. If yours is just ON or OFF as text you don’t need a value_template line.

Always understand each line rather than just copy-pasting.

Also, device_class: door in all lower-case.

Thanks for the advice @Troon –I removed the value_template line and changed door to lowercase. I restarted Home Assistant, but I still cannot find the new entities under Developer Tools > Entities. Any other thoughts on troubleshooting this?

Only one top-level mqtt: in your config? Anything in the logs?


Get MQTTExplorer on your computer. It will make mqtt bug hunting much easier.

Also each time you change something in mqtt you don’t have to restart. Go into developer tools and select manually configured mqtt enteries and it will just reload that section in few seconds.

Thanks for the insight – on my new instance, I’m not able to find the ‘Manually Configured MQTT Entries’ which is rather strange! No visible issues in the logs either. Here’s my entire configuration.yaml.


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

smartir:

climate:
  - platform: smartir
    name: Apt 1 Air Conditioner
    unique_id: apt_1_air_conditioner
    device_code: 1004
    controller_data: remote.broadlink_rm4_mini_apt_1
    # temperature_sensor: sensor.ble_temperature_studio_ble_sensor
    # humidity_sensor: sensor.ble_humidity_studio_ble_sensor
  - platform: smartir
    name: Apt 2 Air Conditioner
    unique_id: apt_2_air_conditioner
    device_code: 1004
    controller_data: remote.broadlink_rm4_mini_apt_2
    # temperature_sensor: sensor.ble_temperature_studio_ble_sensor
    # humidity_sensor: sensor.ble_humidity_studio_ble_sensor
  - platform: smartir
    name: Apt 3 Air Conditioner
    unique_id: apt_3_air_conditioner
    device_code: 1004
    controller_data: remote.broadlink_rm4_mini_apt_3
    # temperature_sensor: sensor.ble_temperature_studio_ble_sensor
    # humidity_sensor: sensor.ble_humidity_studio_ble_sensor

mqtt:

  binary_sensor:
    - name: "Apt 1 Front Door Magnetic Sensor"
      unique_id: "apt_1_front_door_magnetic_sensor"
      state_topic: "stat/esprfidapt1/io/door"
      payload_on: "ON" 
      payload_off: "OFF"
      device_class: door
    - name: "Apt 2 Front Door Magnetic Sensor"
      unique_id: "apt_2_front_door_magnetic_sensor"
      state_topic: "stat/esprfidapt2/io/door"
      payload_on: "ON" 
      payload_off: "OFF"
      device_class: door

ble_monitor:
  bt_interface: "disable"
  discovery: false
  restore_state: true
  # decimals: 1
  period: 60
  devices:

    ##### APT 1
    - name: 'Apt 1 Smoke Alarm'
      mac: '54:EF:44:C5:9A:77'
      encryption_key: 'f4271770324d3014dfab8715a1963e39'

    ##### APT 2

    # - name: 'Apt 2 Front Door Sensor'
    #   mac: 'E4:AA:EC:5C:BB:35'
    #   encryption_key: 'ddff95b011aff9dc7eeefd3cfd35d6d5'

    - name: 'Apt 2 Smoke Alarm'
      mac: '54:EF:44:C5:3E:24'
      encryption_key: '75bf6119bb038fabd4bc31deab6f559c'
      
    - mac: 'A4:C1:38:CA:32:31'
      name: 'Apt 2 Temp Sensor 1'
      encryption_key: '64d18c2362a04e91cc83e0a0a97a4e6b'
      
    - mac: 'A4:C1:38:5D:09:41'
      name: 'Apt 2 Temp Sensor 2'
      encryption_key: 'ad43275fc7ccc7723a477da1eb7a7e39'

    ##### APT 3

    # - name: 'Apt 3 Front Door Sensor'
    #   mac: 'E4:AA:EC:5F:81:29'
    #   encryption_key: '33852c4f816c806f698e75d6b2f60626'

    - name: 'Apt 3 Smoke Alarm'
      mac: '54:EF:44:C5:9C:14'
      encryption_key: 'd8935e9f8bde1e2d1a7ee6e9d2356adf'
      

      

      
      
      
      
      

Perhaps we are all getting closer to the problem
mqtt

Just checking under addons mosquitto broker running and on integrations mqtt shows up?