Including files after component header mixed with other mapping values possible?

My configurtation.yaml looks like this:

[much stuff cutted out]

switch: !include ulink-switches.yaml
 - platform: mqtt
   name: "ca-remote-rs-tx"
   state_topic: "home/ca-remote/rs-tx"
   command_topic: "home/ca-remote"
   qos: 0
   payload_on: "online"
   payload_off: "offline"

ulink-switches.yaml’s content is:

 - platform: mqtt
   name: "ulink-living-shutdownbutton-shutdown"
   state_topic: "home/living/ulink-shutdownbutton/state0"
   command_topic: "home/living/ulink-shutdownbutton"
   qos: 0
   payload_on: "on"
   payload_off: "off"
   retain: true

You see I want to include my external config file ulink-switches.yaml in the component section “switch:”. I want to include the specified file and after this I want to define some more switches.

This does not work:

Sep 9 13:23:19 homeautomation hass[8907]: #033[31m2017-09-09 13:23:19 ERROR (Thread-2) [homeassistant.util.yaml] mapping values are not allowed here
Sep 9 13:23:19 homeautomation hass[8907]: in “/home/pi/.homeassistant/configuration.yaml”, line 159, column 12#033[0m
Sep 9 13:23:19 homeautomation hass[8907]: #033[31m2017-09-09 13:23:19 ERROR (MainThread) [homeassistant.bootstrap] Error loading /home/pi/.homeassistant/configuration.yaml: mapping values are not allowed here
Sep 9 13:23:19 homeautomation hass[8907]: in “/home/pi/.homeassistant/configuration.yaml”, line 159, column 12#033[0m
Sep 9 13:23:19 homeautomation hass[8907]: Config directory: /home/pi/.homeassistant

I tried it this way too:

switch: 
!include ulink-switches.yaml
 - platform: mqtt
   name: "ca-remote-rs-tx"
   state_topic: "home/ca-remote/rs-tx"
   command_topic: "home/ca-remote"
   qos: 0
   payload_on: "online"
   payload_off: "offline"

There is an additional newline after “switch:”. Here, home assistant tells me “could not find expected ‘:’”.

It’s my understanding that home assistant includes the external file as it is at the position where !include stands. Home Assistant tells me “mapping values are not allowed here”.

Is it possible at all to include my config file this way? Is there some one to show me the right way?

Thanks for helping me!

You’re blending two methods of defining things, you either need to include a merged directory with the various switch files, or do this:

switch: !include ulink-switches.yaml

switch 2:
 - platform: mqtt
   name: "ca-remote-rs-tx"
   state_topic: "home/ca-remote/rs-tx"
   command_topic: "home/ca-remote"
   qos: 0
   payload_on: "online"
   payload_off: "offline"

So many thanks!

Does “switch 2” mean I have two switch services afterwards? Or is switch and switch 2 on the same domain in the end?

Thank you.

Could you provide me a link to this “switch 2:” feature? What is it called? I never stumbled over it… I think I missed something in the last month or so…

It’s just basic home assistant yaml structure.

I would presume it’s the same domain, but I use the merged directory method so I don’t know.

1 Like

Thank you @anon43302295! Indeed the examples on the site you link to (so called style 2: here) show the use of multiple components with appended number. I have to look into yaml language it seems. Thanks again and happy home assistant hacking :upside_down_face:!

1 Like