MQTT Config Changes

OK, please take it easy on me, I’m very part-time on this, trying to keep a friend’s HA configuration running after her husband passed away. Unfortunately, I live three states away and don’t have the time needed to really get into this and understand everything her husband did.

What I’m trying to do now is correct all the MQTT configuration he has in the old format. There are lights and binary_sensors and sensors, so I need to make changes in each area. The shortest area to use as an example is the binary_sensors.

There is a file called: components\binary_sensors\binary_sensors_mqtt.yaml that contains the following:

- platform: mqtt
    state_topic: "stat/Mailbox/POWER2"
    name: "Mailbox Top Door"
    payload_on: "ON"
    payload_off: "OFF"
    # icon_template: >-
    #   {% if is_state('binary_sensor.mailbox_top_door', 'ON') %}
    #     mdi:email-outline
    #   {% else %}
    #     mdi:email-open
    #   {% endif %}

There is also a file called: components\binary_sensors\binary_sensors_RF.yaml that also has a bunch of sections that look like this:

- platform: mqtt
  name: "Kitchen Window"
  state_topic: "tele/sonoff/RESULT"
  value_template: '{{value_json.RfReceived.Data}}'
  payload_on: "FE09EE"
  payload_off: "FE09E7"
  device_class: Window
#  optimistic: false
  qos: 1
#  retain: false

I read several of the posts about this change, but I guess I don’t have enough experience with HA to be able to translate the required changes that are shown in generic examples into the specific changes I need to make. If someone could show me the specific configuration changes I need to make with the examples I’ve included, I think I’ll be able to make the rest of the changes.

TIA!

Something like:

mqtt:
  sensor:
    - name: "Mailbox Top Door"
      state_topic: "stat/Mailbox/POWER2"
      payload_on: "ON"
      payload_off: "OFF"

  binary_sensor:
    - name: "Kitchen Window"
      state_topic: "tele/sonoff/RESULT"
      value_template: '{{value_json.RfReceived.Data}}'
      payload_on: "FE09EE"
      payload_off: "FE09E7"
      device_class: window
      qos: 1

And repeat for the rest.

Here’s one of my lights as an example:

mqtt:
  light:
    - name: "BBQ Light"
      command_topic: "cmnd/sonoff1/power"
      state_topic: "stat/sonoff1/POWER"
      payload_on: "ON"
      payload_off: "OFF"
      retain: true

@zoogara
I just found another post that has some more detail, so combining your reply with that information…

It sounds like I need to create a new file called mqtt.yaml and then add an include statement in the master configuration.yaml file. Since the file is named mqtt.yaml I wouldn’t need to include mqtt: at the top.

In that file I need to move all the configurations that used to say:

- platform: mqtt
    state_topic: "stat/Mailbox/POWER2"
    name: "Mailbox Top Door"

Now in the mqtt.yaml file they would say:

binary_sensor:
    state_topic: "stat/Mailbox/POWER2"
    name: "Mailbox Top Door"

repeated for each binary_sensor

Then repeat for each binary_sensor, sensor and light.

I assume that if any of the previously included files end up empty after the refactoring I would just delete it and remove any include statements.

If the mqtt.yaml file ends up being too big and unwieldy, I suppose I could create a file for each type (binary_sensor_mqtt.yaml, sensor_mqtt.yaml, lights_mqtt.yaml) and then add the mqtt: back at the top of each file.

Is that the right track?

This thread should hopefully help you out.

Yes - in configuration.yaml:

mqtt: !include mqtt.yaml

In mqtt.yaml, be aware you need to start indented:

  binary_sensor:
      state_topic: "stat/Mailbox/POWER2"
      name: "Mailbox Top Door"

Also track down the old include statements and remove them.

Alternatively - you could use the merged lists format linked above - which is probably how it was done before, however it sometimes gets confusing.

And also be aware that “binary_sensor:” or “sensor:” can only be there once each.

so like this:

binary_sensor:
  - state_topic: "stat/Mailbox/POWER2"
    name: "Mailbox Top Door"
  - state_topic: "stat/something_else/POWER2"
    name: "Some Other Binary Sensor"
sensor:
  - state_topic: "some/thing"
    name: "Some Thing"
  - state_topic: "some/other/thing"
    name: "Some Other Thing"