Template configuration to read attribute

Beginner here. I am trying to setup an attribute as a sensor and have found the following page: https://www.home-assistant.io/integrations/template/

However, upon following the instructions I do not see the new entity popping up and all other entities configured in my configuration.yaml are broken. I think it might be a syntax problem but I am unable to find my error. The code I added to my configuration.yaml is:

sensor:
- platform: template
  sensors:
    rx_data:
      friendly_name: "Received data"
      value_template: "{{ state_attr('sensor.unifi_gateway_www', 'rx bytes-r') }}"

The only error I am getting in the logs is the following:

2020-10-17 20:48:51 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /home/homeassistant/.homeassistant/configuration.yaml contains duplicate key "sensor". Check lines 16 and 36
2020-10-17 20:48:51 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /home/homeassistant/.homeassistant/configuration.yaml contains duplicate key "sensor". Check lines 36 and 47

But as far as I understand I am required to call the entry a ‘sensor’.

Can anybody show me the correct syntax or my (probably obvious) mistake?

Welcome to Home Assistant !!

You should only have one ‘sensor:’ key in your configuration.yaml
All your sensors need to be under this key.

sensor:
- platform: template
  sensors:
    rx_data:
      friendly_name: "Received data"
      value_template: "{{ state_attr('sensor.unifi_gateway_www', 'rx bytes-r') }}"

- platform: rest

- platform: mqtt
1 Like

Thanks a lot! That solved my issue.

1 Like