Template sensor driving me nuts

When I put the following in the template editor, it gives the correct value: 100
{{ states.zwave.aeotec_dsb45_water_sensor.attributes.battery_level }}

But when I put the following into configuration.yaml all hell breaks loose…
sensor:

- platform: template
  sensors:
    - battery_watersensor:
        #friendly_name: 'Water Sensor Battery'
        value_template: '{{ states.zwave.aeotec_dsb45_water_sensor.attributes.battery_level }}'
        unit_of_measurement: '%'

I get the following error:

Invalid config for [sensor.template]: expected a dictionary for dictionary value @ data['sensors']. Got [OrderedDict([('battery_watersensor', OrderedDict([('value_template', '{{ state.zwave.aeotec_dsb45_water_sensor.attributes.battery_level }}'), ('unit_of_measurement', '%')]))])]. (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.template/

Any ideas?

- platform: template
  sensors:
    battery_watersensor:
      #friendly_name: 'Water Sensor Battery'
      value_template: '{{ states.zwave.aeotec_dsb45_water_sensor.attributes.battery_level }}'
      unit_of_measurement: '%'

Try without the -

1 Like

That seems to have worked. Is it because the ‘-’ means that I’m giving it multiple sensors?

No, multiple sensors are also without the -

It worked because sensors wants a dictionary, not a list. By using ‘-’ you are effectively creating a list, not a dictionary.

If you’re familiar with Python or JSON, and are struggling to learn YAML (like I was not that long ago), you might want to try this:

http://yaml-online-parser.appspot.com/

I found it very useful. It helped the “light go on” for me regarding how YAML works.

1 Like

Cool thanks!

1 Like