New MQTT format used in separate sensors.yaml file

Hello,
I am stuck with the use of the new MQTT format.
I have in my configuration an inclusion for the sensors to a separate sensor.yaml file which looks like below.

in the configuration.yaml:

sensor: !include sensors.yaml

In the sensors.yaml file:

- platform: mqtt
  state_topic: "ITHO/Fan/State"
  name: Fan Speed

However after the update with the new format I get this warning:

Your manually configured MQTT sensor(s) needs attention
This stops working in version 2022.12.0. Please address before upgrading.
Manually configured MQTT sensor(s) found under platform key sensor.

Please move the configuration to the mqtt integration key and restart Home Assistant to fix this issue. See the documentation, for more information.

I tried to fit in the new format in the sensors.yaml file but I can not find the correct notation to put it in there.
Does this mean I have to move all sensor configs back to the configuration.yaml ?

There is no clear documentation regarding this new format in cinjunction with a separated sensor file

Using the simple example in the docs:

mqtt:
  sensor:
    - state_topic: "home/bedroom/temperature"

I would think the config.yaml would look like:

mqtt:
  sensor: !include sensors.yaml

and the sensors.yaml file would look like (including the leading white spaces) :

    - state_topic: "home/bedroom/temperature"
1 Like

No the leading spaces in the include file are not required.

Yep! (To me its just good practice :wink:).

No.

Look at how you specified where your sensor entities are defined.

sensor: !include sensors.yaml

You can now do the same thing for entities based on the MQTT integration.

mqtt: !include mqtt.yaml

The mqtt.yaml file can contain all your MQTT-based entities (sensor, binary_sensor, light, etc). You can even split up the information into separate files but you must use a different !include directive for that.

Sample contents of mqtt.yaml

  sensor:
    - name: Fan Speed 
      state_topic: "ITHO/Fan/State"
    - name: Something Else 
      state_topic: "home/whatever"
    - name: Yet Another Sensor 
      state_topic: "etc/foo"

There’s an entire chapter in the documentation that explains how to split your configuration. Splitting the mqtt configuration into one or more files follows the rules explained here:

1 Like

Thank you very much !
That is what you get when you have configured HA for a while now and not have touched it for a long time because of other priorities unfortunately. But I am very thankful for such a great community HA has !
I managed to create also a separate mqqt file like you said and added the entities and sensors in there.
Thanks again for pointing this out :+1:

1 Like

As Taras said. But, let me publish my working splitted config adapted to new mqtt syntax, if it helps someone:

First create new folder for mqtts and edit configuration.yaml. (in my case):

---configuration.yaml
mqtt: !include_dir_merge_named programaciones/mqtts/
---

Now multiples files in mqtt folder for different tasks. Each can contain multples switches, sensors, etc in the same file, but only one ‘sensor:’ line and only one ‘switch:’ line. If you repeat the ‘sensor:’ header on each paragraph, it will no load. (i had to hit my head to the wall to realize that).

---programaciones/mqtts/mqtts_piscina.yaml
### mqtts_piscina.yaml

#########################################################
################     MQTTs SESORS     ###################
#########################################################

sensor:

##################
###   DHT22    ###
##################

  - name: "DHT22 temperatura"
    state_topic: "/arduino/dht22temperatura"
    unit_of_measurement: "C"

  - name: "DHT22 humedad"
    state_topic: "/arduino/dht22humedad"
    unit_of_measurement: "%"



##################################################
####   ULTRASONICO DE DISTANCIA, WATERPROOF    ###
##################################################

  - name: "Ultrasonico nivel piscina"
    state_topic: "/arduino/ultrasonicodistancia"
    unit_of_measurement: "cm"




#------------------same file, but separation for switches:



#########################################################
################     MQTTs SWITCHES     #################
#########################################################

switch:

######################
####   ARDUINO     ###
######################

### PIN22
  - unique_id: arduino_pin_22
    name: "Arduino pin 22"
    state_topic: "/arduino/switchConfirm22"
    command_topic: "/arduino/switch22"
    payload_on: "1"
    payload_off: "0"
  #  qos: 0
    optimistic: true
    retain: true

---end off: programaciones/mqtts/mqtts_piscina.yaml

And, as example, another file in the mqtt folder for other tasks, with another two sensors:

---programaciones/mqtts/mqtts_zigbee.yaml
### mqtts_zigbee.yaml

####################################################
################     MQTTs SESORS     ##############
####################################################

sensor:

### CREA UN SENSOR DEL ESTADO DEL BRIDGE MQTT<->ZIGBEE
  - name: Bridge state
    state_topic: "zigbee2mqtt/bridge/state"
    icon: mdi:router-wireless

### CREA UN SENSOR PARA EL ADDON NETWORKMAP DE HACS DE ZIGBEE
  - name: Zigbee2mqtt Networkmap
    state_topic: zigbee2mqtt/bridge/response/networkmap
    value_template: >-
      {{ now().strftime('%Y-%m-%d %H:%M:%S') }}
    json_attributes_topic: zigbee2mqtt/bridge/response/networkmap
    json_attributes_template: "{{ value_json.data.value | tojson }}" 

---end of: programaciones/mqtts/mqtts_zigbee.yaml

…this seems to load fine. Hope it helps someone to adapt their mqtt configs…

1 Like

The mqtt yaml is totally inconsistent.
Why is mqtt handle so different that other platforms?
Why do I have to have a yaml file for sensors and a different file for mqtt if both files define sensors.
I would like to understand the logic behind this.

the old definition

- platform: mqtt
  state_topic: "ITHO/Fan/State"
  name: Fan Speed`

make much more sense.