[SOLVED] Config validation confusion

Hi all,

I am attempting to replicate Frenk’s HA config setup.

When I validate my config I am getting this error:

Invalid config for [sensor]: expected a dictionary. Got OrderedDict([('recorder', 
OrderedDict([('purge_keep_days', 3), ('purge_interval', 1)])), ('cloud', OrderedDict([('mode', 
'production')])), ('weather', [OrderedDict([('platform', 'darksky'), ('name', 'Dark Sky'), ('api_key', 
MY_KEY'), ('mode', 'hourly')])]), ('rachio', OrderedDict([('api_key', 
'MY_KEY')])), ('script', OrderedDict()), ('config', OrderedDict()), 
('group', OrderedDict()), ('panel_iframe', OrderedDict([('ide', OrderedDict([(.... (See ?, line ?). Please 
check the docs at https://home-assistant.io/components/sensor/

I am quite confused. I suspected it may be a spacing issue, but I am not sure. Here is my configuration.yaml

homeassistant:
   name: Home
   latitude: !secret latitude_home
   longitude: !secret longitude_home
   elevation: !secret elevation_home
   unit_system: imperial
   time_zone: America/Los_Angeles
   customize: !include customize.yaml
   packages: !include_dir_named components/packages

Now, if I understand it, everything under packages should be indented two more spaces. For instance, the sensor.yaml file is indented a total of 4 spaces:

    sensor: !include_dir_list ../sensors

And then anything in the ‘sensors’ directory should start 6 spaces indented? For instance, my /config/components/sensors/system_monitor.yaml:

      - platform: systemmonitor
        resources:
          - type: disk_free
            arg: /
          - type: memory_free
          - type: processor_use
          - type: last_boot

It seems no matter how I space it I still get the error message I posted above. What am I missing? Can anyone help?

Thank you.

That is your issue, sensor: should not be indented. The first sensor defined would be indented 2 spaces.

In an included file, the first line would be indented 2 spaces.

YAML is very sensitive to spaces

Still the same issue. Same error.

I do understand spacing is important in yaml. My reasoning for my spacing is in the configuration.yaml the packages entry is indented over two since it is under the homeassistant heading. And, as I thought I understood it, since packages includes the the files they would be over two more spaces. So, if I put this all in configuration.yaml I would think it would look like this:

homeassistant:
  packages:
    sensor:
      - platform: darksky
        api_key: !secret darksky_api_key

Either my spacing is still incorrect (sensor.yaml is an included file within packages), or I am missing something else…

My sensor.yaml file looks just like Frenk’s here: https://github.com/frenck/home-assistant-config/blob/master/config/components/packages/sensor.yaml

If I comment out sensor: !include_dir_list ../sensors then the configuration checks out…

My configuration.yaml does not have a packages: line.

Take a look at Frenk’s: https://github.com/frenck/home-assistant-config/blob/master/config/configuration.yaml

Also, if I remove everything from the sensors directory with sensor: !include_dir_list ../sensors uncommented then the configuration also checks out. The moment I add any yaml file to the sensors directory, no matter the spacing, I get the original error.

I think I figured it out…

I have been using - platform to define the various items. However, apparently with this method of config the - is not needed, and in fact FUBARs it.

1 Like

My darksky sensor has a -platform: line …

Right. But you are not using packages to further organize.

It really depends on where you are using the “-” whether it’s needed or not…

If you are creating a list of, for example, sensors in your package you will need to include the - in front of each sensor configuration section.

Either way using the - shouldn’t fubar anything even if you only have one item in the list unless you are using it in the wrong place/way.

Are you keeping all of you configuration in your configuration.yaml or do you have it split using !include statements?

I am splitting it, and using !includes. Take a look at Frenck’s setup: https://github.com/frenck/home-assistant-config/tree/master/config

For the sensors I am including them via sensor: !include_dir_list ../sensors Each sensor is in it’s own yaml file. When I had the -, I got the error I showed. When I remove them, the config is valid. I am still learning the in’s and out’s of yaml. The - functionality is not super clear to me yet…

can you give an example of how you configured one of your sensors with the - added that gave you an error?

I’m really confused about the roundabout way that Frenck configured his set up. it seems to add unnecessary complexity to define !includes in packages that define !includes to components/directories when you could just as easily reference them directly in the configuration.yaml.

Sure.

- platform: mqtt
  name: "Flower Lights Amps"
  state_topic: "tele/slitinto-plug1/SENSOR"
  value_template: "{{value_json['ENERGY'].Current }}"
  qos: 2
  unit_of_measurement : "A"
  icon: mdi:flash-circle
  availability_topic: "tele/slitinto-plug1/LWT"
  payload_available: "Online"
  payload_not_available: "Offline"

This results in the error in my first post. In fact, just to be sure, I added the - back, and I have the error again. Remove it, and the config is happy.

I just created a new package file then I copied your code above into it and got no errors. But to honest I’ve never seen anyone else use packages in the way he uses them. Maybe there is some weirdness going on there with the chaining of all of those !includes together.

Typically packages are used to put all of the different components together into one single file to prevent spreading everything used for one purpose over your entire config.

In my “homeassistant:” section I have an entry for packages: !include_dir_named packages then I created a packages directory that contains several other yaml files containing my package contents.

For example my “alexa_tts_package.yaml” file contains the follolwing:

sensor:
  - platform: template
    sensors:
      last_alexa:
        entity_id:
          - media_player.computer_room_dot
          - media_player.kitchen_dot
          - media_player.livingroom_dot
          - media_player.master_bedroom_dot
          - media_player.garage_dot
          - media_player.big_room_dot
        value_template: >
          {{ states.media_player | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}

light:
  - platform: template
    lights:
      alexa_virtual:
        friendly_name: "Alexa Dummy Light"
        turn_on:
        turn_off:
        set_level:

automation:
  - alias: "Alexa Report"
    trigger:
      - platform: state
        entity_id: light.alexa_virtual
        to: 'on'
    condition:
    action:
      - service: alexa_media.update_last_called
      - delay: 00:00:01
      - service: notify.alexa_media
        data_template:
          target: 
            -  '{{ states.sensor.last_alexa.state }}' 
          data:
            type: tts
          message: >-
            {% if (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 1  %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion.  For example Degreess
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 2 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion. For example  miles
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 3 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion For example minutes
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 4 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
             {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 5 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 6 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 7 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 9 %}
              Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
            {% elif (states.light.alexa_virtual.attributes.brightness | int / 255 * 100 ) | round  == 10 %}
               Words.  What you want to say {{ states('sensor.name_of_sensor') }} follow on informtion
            {% else %}
              {{ states('light.alexa_virtual.attributes.brightness') }}
            {% endif %}
      - service: light.turn_off
        entity_id: light.alexa_virtual

Packages allow you to put many different components (sensors, lights, switches, automations, scripts, etc.) all together under one yaml file.

2 Likes