Accessing entities' attributes via templae

Hello,

I want to access attributes of an entitiy (my FritzBox). I’ve already found out, that I have to create a template in configuration.yaml. The entitiy is “sensor.fritz_box_6591_cable” and the attributes are “transmission_rate_up” / “transmission_rate_down”.

sensor:
   - platform: template
    sensors:
      transmission_down_speed_kbps:
        friendly_name: "Transmission Down Speed"
        entity_id: sensor.fritz_box_6591_cable
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.fritz_box_6591_cable', 'transmission rate down')|float * 1024 }}"

      transmission_up_speed_kbps:
        friendly_name: "Transmission Up Speed"
        entity_id: sensor.fritz_box_6591_cable
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.fritz_box_6591_cable', 'transmission rate up')|float * 1024 }}"

After restarting HA, I have no syntax errors in log. But also no extra state objects I can access via UI.
I’ve searched the web and this forum but haven’t found anything applying to my case.
I guess it’s only a small thing that is missing.

Your indentation is off and you say that the attribute is transmission_rate_up but in the template you write it without the underscore. It needs to match exactly what you see under Developer Tools -> States.

Try like this:

sensor:
  - platform: template
    sensors:
      transmission_down_speed_kbps:
        friendly_name: "Transmission Down Speed"
        entity_id: sensor.fritz_box_6591_cable
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.fritz_box_6591_cable', 'transmission_rate_down') | float * 1024 }}"

      transmission_up_speed_kbps:
        friendly_name: "Transmission Up Speed"
        entity_id: sensor.fritz_box_6591_cable
        unit_of_measurement: 'kB/s'
        value_template: "{{ state_attr('sensor.fritz_box_6591_cable', 'transmission_rate_up') | float * 1024 }}"

Hello,

thanks for replying. I am sorry for the missing underscore. I’ve tested so my versions that I’ve copypasted the wrong one into here.
I’ve copied your version, but still no extra entity is coming up at Developer Tools -> States.

Does your configuration.yaml file contain more than one of this:

sensor:

No, it’s the only “sensor:” one. I had already tried splitting both templates up, but then theres an error in the log that there are two “sensor” sections.

Ok, I’ve put it on top of the config file, directly under “default_config:”.
Now it appreas under Developer Tools -> States.

Is there a way to check for right indentation?

If you use a text editor like VS Code, it has extensions that can identify YAML formatting mistakes and even highlight the spacing so it’s easier to see. For example, here are your Template Sensors in my VS Code editor:

That implies something was originally wrong with the sensor: section because moving it higher up in the file isn’t really a cure.