Expected dictionary for dictionary value @ data['sensors']- thermostat

Hi guys. Been setting up Home Assistant and am starting to play with templates. As a test, I tried creating a sensor that outputs the current temp from my Nest thermostat. Before anyone says it, I know there is an existing sensor for this. This is more a way to learn the template ropes by essentially duplicating the existing thing, so I could validate it’s working correctly by comparing the output with the existing sensor. However, I can’t even get this working! I get an error below about dictionary value. My guess is something about formatting or quotation marks, but I’ve tried many iterations and done quite a bit of Google-fu and am at a dead end. I’m sure it’s simple, and I’d appreciate if any of you HA whizzes could point out where I’m going wrong!

I should add, I put the actual template function into the template testing box in Developer and it returned the right value, so I think that should be right.

Sensors.yaml file in packages:

template:

  sensors:

    thermostat_curr_temp:

      - friendly name: "Thermostat Current Temperature"

        Unit of measurement: "°F"

        value_template: '{{state_attr("climate.thermostat","current_temperature")}}'

Error in logs:

Invalid config for [template]: expected dictionary for dictionary value @ data['sensors']['thermostat_curr_temp']. Got [OrderedDict([('friendly name', 'Thermostat Current Temperature'), ('Unit of measurement', '°F'), ('value_template', '{{state_attr("climate.thermostat","current_temperature")}}')])]. (See ?, line ?).

You’re mixing the old configuration style with the new configuration style. Also, the new configuration style cannot be used in packages.

Use the old style in your package. Also, you had spaces in the field name for friendly name and unit of measurement. Take a look at the examples, yaml does not use spaces anywhere. The field names have to have underscores. Also, home assistant specifically doesn’t allow capital letters in the field names either.

old style inside packages

sensor:
- platform: template
  sensors:
    thermostat_curr_temp:
      friendly_name: "Thermostat Current Temperature"
      unit_of_measurement: "°F"
      value_template: '{{state_attr("climate.thermostat","current_temperature")}}'

or new style outside of packages


template:
- sensor:
  - unique_id: thermostat_curr_temp
    name: "Thermostat Current Temperature"
    unit_of_measurement: "°F"
    state: '{{state_attr("climate.thermostat","current_temperature")}}'
2 Likes

Aha! This makes sense. I didn’t realize there was an old and a new style of config or that the new style didn’t work in packages! Also, makes sense on the underscores. I thought I was copying the example yaml but maybe I misread it. That got it squared away! Thank you!

1 Like

Yeah the new style is very new. Month or 2 old at this point