Splitting mqtt.yaml by devices

Hi,

I’m struggling trying to split my mqtt.yaml file by device.
I have a bunch of mqtt devices with lots of sensors, switches, etc…
For the ease of use and editing I would like to have one file per device under mqtt/ directory having ALL device entities.

I then specified the following in configuration.yaml
mqtt: !include_dir_merge_named mqtt/

One of the mqtt file (esp_altherma.yaml)

#mqtt:

binary_sensor:
 - unique_id: HP_Defrost
   name: "HP defrost mode"
   state_topic: 'esp_altherma/ATTR'
   value_template: "{{ value_json['Defrost Operation'] }}"
   availability_topic: "esp_altherma/LWT"
   payload_available: "Online"
   payload_not_available: "Offline"
   payload_on: "ON"
   payload_off: "OFF"


 - unique_id: HP_Oil_Return
   name: "HP oil return mode"
   state_topic: 'esp_altherma/ATTR'
   value_template: "{{ value_json['Oil Return Operation'] }}"
   availability_topic: "esp_altherma/LWT"
   payload_available: "Online"
   payload_not_available: "Offline"
   payload_on: "ON"
   payload_off: "OFF"

sensor:
 - unique_id: HP_Target_Temp
   state_topic: 'esp_altherma/ATTR'
   name: 'HP Water Target T°'
   unit_of_measurement: '°C'
   value_template: "{{ value_json['Target Cond. Temp.']|round(2)}}"
   availability_topic: "esp_altherma/LWT"
   payload_available: "Online"
   payload_not_available: "Offline"

 - unique_id: HP_Outdoor_Air_Temp
   state_topic: 'esp_altherma/ATTR'
   name: 'HP Outdoor'
   unit_of_measurement: '°C'
   value_template: "{{ value_json['Outdoor air temp.'] }}"
   availability_topic: "esp_altherma/LWT"
   payload_available: "Online"
   payload_not_available: "Offline"

 - unique_id: HP_Outdoor_Heat_Exchanger_Temp
   state_topic: 'esp_altherma/ATTR'
   name: 'HP Outdoor Heat Exchanger'
   unit_of_measurement: '°C'
   value_template: "{{ value_json['Outdoor heat exchanger temp.'] }}"
   availability_topic: "esp_altherma/LWT"
   payload_available: "Online"
   payload_not_available: "Offline"

switch:
 - unique_id: HP_switch
   name: "HP Heating"
   state_topic: "esp_altherma/STATE"
   command_topic: "esp_altherma/cmd"
   availability_topic: "esp_altherma/LWT"
   payload_on: "on"
   payload_off: "off"
   state_on: "ON"
   state_off: "OFF"
   payload_available: "Online"
   payload_not_available: "Offline"
   optimistic: false
   qos: 0
   retain: false

I saw some topics where it is detailed a split configuration where the split criteria is based on entities like sensors, switches, etc… but it is not my will…

You may want to have a look here, I have files per integration, or use or ‘whatever’ I decided…to group multiple sensors in one file, e.g. solar.yaml / electricity.yaml / travel.yaml / lights.yaml

Packages - Home Assistant

Dear Vingerha,

Indeed a very nice feature I didn’t knew about.

It (you) solved my problem.

However it took some time figuring out the right syntax for mqtt.

Here follow the structure that worked for me:

mqtt:

  binary_sensor:
   - unique_id: HP_Defrost
     name: "HP defrost mode"
     state_topic: 'esp_altherma/ATTR'
     value_template: "{{ value_json['Defrost Operation'] }}"
     availability_topic: "esp_altherma/LWT"
     payload_available: "Online"
     payload_not_available: "Offline"
     payload_on: "ON"
     payload_off: "OFF"

  sensor:
   - unique_id: HP_Mode
     state_topic: 'esp_altherma/ATTR'
     name: 'HP mode'
     value_template: "{{ value_json['Operation Mode'] }}"
     availability_topic: "esp_altherma/LWT"
     payload_available: "Online"
     payload_not_available: "Offline"

  switch:
   - unique_id: HP_switch
     name: "HP Heating"
     state_topic: "esp_altherma/STATE"
     command_topic: "esp_altherma/cmd"
     availability_topic: "esp_altherma/LWT"
     payload_on: "on"
     payload_off: "off"
     state_on: "ON"
     state_off: "OFF"
     payload_available: "Online"
     payload_not_available: "Offline"
     optimistic: false
     qos: 0
     retain: false