Problem with new MQTT format

I do get this record in the log

2022-09-11 21:41:03.351 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.mqtt

but nothing specific for the binary_sensor.

1 Like

Can you send me a message with the complete MQTT section - so I can see if anything stands out? By that I mean, all the MQTT components, not just the binary_sensor.

mqtt:
  binary_sensor:
    - name: "front_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/front_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/front_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      unique_id: 98F4ABD0B919A0

  binary_sensor:
    - name: "back_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/back_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/back_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      #unique_id: 98F4ABD0B919A1
      unique_id: back_door_bsensor

  binary_sensor:
    - name: "basement_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/basement_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/basement_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      unique_id: 98F4ABD0B919A2

  binary_sensor:
    - name: "wifi_status"
      device_class: connectivity
      state_topic: "home-assistant/wifi"
#      payload_on: "ON"
#      availability:
#        - topic: "home-assistant/contact/front_door/availability"
#          payload_available: "online"
#          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"

  switch:
    - name: "garage_ light"
      state_topic: "shellies/shelly1-98F4ABD0B919/relay/0"
      command_topic: "shellies/shelly1-98F4ABD0B919/relay/0/command"
      payload_on: "on"
      payload_off: "off"
      retain: false
      icon: mdi:light-switch
      unique_id: 98F4ABD0B919A
  switch:
    - name: "Family_room-Mside"
      state_topic: "shellies/shelly1-8CAAB505E297/relay/0"
      command_topic: "shellies/shelly1-8CAAB505E297/relay/0/command"
      payload_on: "on"
      payload_off: "off"
      retain: false
      icon: mdi:light-switch
      unique_id: 8CAAB505E297

  switch:
    - name: "basement finished"
      state_topic: "shellies/shelly1-E09806961421/relay/0"
      command_topic: "shellies/shelly1-E09806961421/relay/0/command"
      payload_on: "on"
      payload_off: "off"
      retain: false
      icon: mdi:light-switch
      unique_id: E09806961421

OK I see the problem immediately.
You cannot have binary_sensor: multiple times like that - your file should look like this:

mqtt:
  binary_sensor:
    - name: "front_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/front_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/front_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      unique_id: 98F4ABD0B919A0

    - name: "back_door_bsensor"
      device_class: door
      state_topic: "home-assistant/contact/back_door"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/contact/back_door/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      value_template: "{{ value_json.state }}"
      #unique_id: 98F4ABD0B919A1
      unique_id: back_door_bsensor

Etc

switch:
  - name: "garage_ light"
    state_topic: "shellies/shelly1-98F4ABD0B919/relay/0"
    command_topic: "shellies/shelly1-98F4ABD0B919/relay/0/command"
    payload_on: "on"
    payload_off: "off"
    retain: false
    icon: mdi:light-switch
    unique_id: 98F4ABD0B919A

  - name: "Family_room-Mside"
    state_topic: "shellies/shelly1-8CAAB505E297/relay/0"
    command_topic: "shellies/shelly1-8CAAB505E297/relay/0/command"
    payload_on: "on"
    payload_off: "off"
    retain: false
    icon: mdi:light-switch
    unique_id: 8CAAB505E297

Note I have had to move all your switch lines back 2 spaces.
While it doesn’t hurt to have them, you should be aware that the default for payloads is “on” and “off”, so you don’t actually need to add the payload_on and payload_off lines.

1 Like

Yeah I appreciate your help. As I was pulling all the lines to respond I notices I did get input from one sensor of each type I had configured. so I was just testing only having binary_sensor, sensor and switch once and it worked. Thanks

1 Like

Ignore what I said about the removing spaces from the switch lines, that was an error on my part just because of how the copy and paste worked. Your indentation is correct.

I would like to thank those that provided examples of working YAML configuration for current MQTT requirements (especially mobile.andrew.jones Andrew Jones). Their examples helped me out tremendously.

Thank you for taking the time to help others, which ended up helping me out as well.

1 Like

Hello community, even though the topic is older, I think my problem fits.

When I want to include a MQTT sensor, and define the unique_id there, the sensor is not displayed with its name under Developer Tools.
If I now remove the unique_id from the sensor, this sensor is displayed to me under its name.

I have split the config, please see my code below.
If I include the sensor directly in the configuration.yaml without splitting the config it doesn’t work either.

Oh yes, the log level is set to debug and does not give anything worth mentioning…

I do not understand the world just more, because on my system (Core 2023.8.1; System 10.4) the whole with the unique_id works, with my mother with exactly the same system but not…

The only difference, my system runs on a PI 4 and my mother runs a PI3B+.

Thanks in advance for your help.

Configuration.yaml:

mqtt: !include mqtt.yaml

mqtt.yaml:

sensor:
  - name: "Push Button Bell Battery Status"
    unique_id: 080820231
    state_topic: "home/Push_Button_Bell/battery"
    unit_of_measurement: "%"
    value_template: "{{ value | float | round(1) }}"
    expire_after: 20
    force_update: true
    state_class: measurement
1 Like

Exactly same behaviour here on my system…
You’re the first one to finally tell exactly the same problem I’m working on for one week!

Except for me it doesn’t work for

binary_sensor:
  - name: "BlahBlah"
    unique_id: "BlahBla"

But those ones work

sensor:
  - name: "BlahBlah"
    unique_id: "BlahBlah"

All in the same mqtt.yaml import file or even directly in config.yaml file :sob:
I will follow closely answers to your questions…

:Update:
Finally I’ve changed my strategy:
I’ve made and virtual homeassistant mqtt discovery publish to create binary_sensor door device_class…
Here is my Service call:

service: mqtt.publish
data:
  topic: homeassistant/binary_sensor/SonOffRF_FrontDoor-Contact/config
  retain: true
  payload: |
    {
      "name": "Porte Balcon Avant",
      "unique_id": "SonOffRF-FronDoor_Contact",
      "state_topic": "maison/gFY/Door/contact",
      "device_class": "door",
      "off_delay": "5",
      "device": {
         "identifiers": ["EED3A0"],
         "name": "QLexDomo Cntr RF",
         "model": "Sonoff Bridge",
         "manufacturer": "SonOff",
         "sw_version": "9.1.0(tasmota)"
      }
    }

Are you certain your unique_ids are truly unique across your system? I use an online generator to create almost-certainly-unique IDs:

https://www.uuidgenerator.net/

They just need to be unique across the integration (MQTT entities). All integrations under the hood add a unique identifier to the ‘under the hood’ unique id that points out the integration. And MQTT may even add the domain to the unique_id as well meaning the uniqueness only has to be in MQTT/sensor for example.

1 Like