New MQTT binary_sensor format, how to migrate old setup?

Hi everyone, need some assistance with migrating from the original MQTT->binary_sensor setup to the new format.

I have arranged my configuration.yaml like @frenck has, with pointers to directories and files which contain the actual definitions of the automations and sensors.
So my setup in my configuration.yaml looks like this:

switch: !include_dir_list switches/
sensor: !include_dir_list sensors/
binary_sensor: !include_dir_list binary_sensors/
input_number: !include_dir_named input_number/
input_boolean: !include_dir_named input_boolean/
input_datetime: !include_dir_named input_datetime/

In case of my binary_sensor files, I put those in the /binary_sensors directory.
So in this directory there are dozens of files like this example named triple_01_links.yaml

---
platform: mqtt
name: 'triple_01_links'
state_topic: 'home/triple_links_01' #'home/[name] comes from python-script file
off_delay: .2

I struggled ages to get the indentation right, so now I’m with my hands in my hair on how to migrate all these files to the new format.
My question is: how do I make a similar nested structure to organize my binary_sensors according to the new formatting?
probably with a line in my configuration.yaml like this:

mqtt: !include_dir_list mqtt/

and add migrated .yaml files to this /mqtt directory.
But I struggle a lot with indentation and formatting these files. Tried several options, but keep getting errors when I check my config-validation.
If anyone has the correct migration from the above triple_01_links.yaml file to the new convention, I probably can do the others myself. Just need a first example.
Any help much appreciated!

In a flash op insight, I tried this and it works, posting for anyone who’s also struggling with this:
The culprit was the placement of the included directory, not straight after the mqtt statement, but (with indentation) after the binary_sensor statement, like this in my configuration.yaml file:

mqtt:
  binary_sensor: !include_dir_list mqtt/binary_sensor

And created the directory /mqtt/binary_sensor
Copied all my original sensor.yaml files from the old /binary_sensors directory into the new /mqtt/binary_sensor directory and edited every single file bij commenting out the platform: mqtt line with a # (you could also delete the line of course).
So this was the old version of triple_01_links.yaml in the /binary_sensors directory:

---
platform: mqtt
name: 'triple_01_links'
state_topic: 'home/triple_links_01' #'home/[name] comes from python-script file
off_delay: .2

Copied and edited this into a new version of triple_01_links.yaml in the /mqtt/binary_sensor:

---
# platform: mqtt
name: 'triple_01_links'
state_topic: 'home/triple_links_01' #'home/[name] comes from python-script file
off_delay: .2

And of course deleted all old mqtt-platform related files in /binary_sensors directory.

Working with no errors, [sight of relief].

1 Like