Configure by platform instead of component

I have a configuration that works listed below but my brain doesn’t seem to compute the “2nd way” to configure devices as laid out in the docs.

binary_sensor:

  • platform: w800rf32
    devices:
    c1:
    name: motion_hall
    off_delay: 5
    device_class: Motion

So not by binary_sensor but by device. Something like:

c1:
platform: w800rf32
name: motion_hall
off_delay: 5

But that doesn’t work.

If someone can help me out I’ll help update the documentation, cause really one shouldn’t use two different examples to try demonstrate a feature. I’m talking about this page: https://www.home-assistant.io/docs/configuration/devices/

Where style 1 talks about something completely different than style 2… That’s poor, should explain the same devices in the two different forms.

It’s impossible to help you if you won’t format the code correctly. See the note at the top of every page!

1 Like

Then please use Edit this page on GitHub and submit an update :wink:

Thank you, you are of course correct in the formatting part. It did look right when I created the post and I did try the block quote but once I submitted it didn’t come through. I shall try again:

Summary

This text will be hidden

binary_sensor:
   - platform: w800rf32
     devices:
       c1:
         name: motion_hall
         off_delay: 5
         device_class: Motion

That seems to work when I use the preview. So the above code works fine of course. My question is how do I change that into style 2?

Thanks

Well it seems you didn’t understand my post possibly english is not your first language, not sure. I would very much like to edit that page if I understood the formatting better. That was my original question. My block quote did not come through the first time so it was a little hard to read but the gist of the question was not about indentation.

Hi all, I think I’ve pretty much answered this. It seems all examples I’ve looked at do not use Style 2 as laid out in the docs, at least for such things as sensors, binary_sensors, switches etc.

I still think the docs need touching as it’s confusing especially for new people, which lets face it, that is mostly who the documentation is aimed at, because if you understand it, well, you don’t require documentation:-)

I’m still interested in an answer if someone cares.
Thanks

I’m pretty sure to convert your example to “style 2” it would look like this:

binary_sensor UNIQUE_VALUE:
  platform: w800rf32
  devices:
    c1:
      name: motion_hall
      off_delay: 5
      device_class: Motion

where UNIQUE_VALUE is some unique (to binary_sensor’s) number or string.

As you mentioned, style 2 isn’t very popular (at least as far as I know.) I suspect it’s mostly there for legacy reasons, but that’s just a guess because I’ve only been using HA for about a half year.

Thank you but that is essentially what I have. I was under the understanding it would be more like this:

platform: w800rf32
  binary_sensor:
    device: c1
      name: motion_hall
      off_delay: 5
  switch:
    device: a5
      name: switch_kitchen
  light:
    device: b3
      name: dinning_room

No. “Style 1” starts with a key which is a “domain” name, like binary_sensor. “Style 2” starts with a key which is a “domain” name, plus whitespace, plus a unique string or number. I think it will be clearer if you see the two different styles for defining two entities of the same domain.

Style 1:

binary_sensor:
  - platform: abc
    name: bs1
  - platform: def
    name: bs2

Style 2:

binary_sensor 1:
  platform: abc
  name: bs1
binary_sensor 2:
  platform: def
  name: bs2

In Style 1 there is one top-level config key, which contains a list of two entity definitions. In Style 2, there are two top-level config keys, each defining one entity.

Your example of three entities, each in a different domain, but all using the same platform, would look like this in Style 2:

binary_sensor 1:
  platform: w800rf32
  device: c1
    name: motion_hall
    off_delay: 5
switch 1:
  platform: w800rf32
  device: a5
    name: kitchen
light 1:
  platform: w800rf32
  device: b3
    name: dinning_room

I actually see no advantage to Style 2 here (or really anywhere.) Even when using Packages, which I believe is much more common, I don’t see it being used.

1 Like

Yes right, now when I go back and look, the doc page does make sense, it’s too bad the person that wrote it didn’t use the same example for both styles. I was under the impression that media_player was a platform, however, now that I look at it again, I see more clearly. Funny how the brain works.

So if we were to update the documentation it would look like so:

Style 1

sensor:
  - platform: mqtt
    state_topic: "home/bedroom/temperature"
    name: "MQTT Sensor 1"
  - platform: mqtt
    state_topic: "home/kitchen/temperature"
    name: "MQTT Sensor 2"
  - platform: rest
    resource: http://IP_ADDRESS/ENDPOINT

switch:
  - platform: vera

Style 2

sensor 1:
  platform: mqtt
  state_topic: "home/bedroom/temperature"
  name: "MQTT Sensor 1"
sensor 2:
  platform: mqtt
  state_topic: "home/kitchen/temperature"
  name: "MQTT Sensor 2"
sensor 3:
  platform: rest
  resource: http://IP_ADDRESS/ENDPOINT

switch 1:
  platform: vera
1 Like

I got a similar issue as I am fully rewriting my configs from style1 to style2.

It works pretty well so far, but can anyone tell me how to do so with input_boolean, input_number, etc?
I get this in check_config:

Testing configuration at /home/homeassistant/.homeassistant
ERROR:homeassistant.scripts.check_config:BURB
Traceback (most recent call last):
    File "/srv/homeassistant2/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 207, in check
        res['components'] = check_ha_config_file(hass)
    File "/srv/homeassistant2/lib/python3.6/site-packages/homeassistant/scripts/check_config.py", line 348, in check_ha_config_file
    result[domain] = config[domain]
KeyError: 'input_boolean'
Fatal error while loading config: 'input_boolean'
Failed config
    General Errors:
      - 'input_boolean'