Create a a template sensor from an attribute

I have the zwift integration which is working well for me but i want the attribute of FTP to show as a sensor that i can use in nodered
i have the attribute in lovelace using this

type: entity
entity: sensor.zwift_online_123456
attribute: ftp
unit: W
icon: mdi:power
name: FTP

but i dont know how to make a template sensor from this
TIA

Try something like that:

sensor:
  - platform: template
    sensors:
      zwift_online_123456_ftp:
        friendly_name: "FTP"
        value_template: "{{ state_attr('sensor.zwift_online_123456', 'ftp') }}"

Or using the new config rather than the legacy config:

template:
  - sensor:
      - name: "FTP"
        unit_of_measurement: "W"
        state: "{{ state_attr('sensor.zwift_online_123456', 'ftp') }}"

Either will work and continue to be supported but it is recommended you use the new config.

thanks for your help i’m interested in trying the new config, if i’m using a sensor folder" /config/sensor.yaml " and i already have other templates and sensors.
should i format your suggestion differently as i’m getting error when checking the config

“end of the stream or a document separator is expected at line 39, column 1:
template:
^”
or if i remove the template line i get
“Invalid config for [sensor]: required key not provided @ data[‘platform’]. Got None. (See /config/configuration.yaml, line 23).”

If you want to use the new template config, template: has to go hard up against the margin in your configuration.yaml file.

You can still split your config with:

template: !include templates.yaml

And put this in that new file:

- sensor:
    - name: "FTP"
      unit_of_measurement: "W"
      state: "{{ state_attr('sensor.zwift_online_123456', 'ftp') }}"

Or use any of the other !include methods if you want to split your config further.

Or just go with the old config posted by Deinis in your sensor.yaml file.