Template Sensor shows as unavailable

Hi,

Am trying to create a template from an attribute of a sensor to get a seperate entity for the power consumption. The entity is created but shows as unavailable.

My config as follows:

sensor:
  - platform: template
    sensors:
      josh_thermostat_power:
      unit_of_measurement: "W"
      value_template: "{{ state_attr('switch.sonoff_10013bfxxx', 'power') }}"

I dont get any erros when checking config but remains as unavailable.

Try add’l indentation below josh_thermostat_power: line

sensor:
  - platform: template
    sensors:
      josh_thermostat_power:
        unit_of_measurement: "W"
        value_template: "{{ state_attr('switch.sonoff_10013bfxxx', 'power') }}"

thanks, been 2 days on this :joy:

Thanks, one last issue, when adding the new sensor to the Riemann sum helper to be able to use in the energy dashboard, it doesnt show up, do i need to add a device class to power to the template sensor?

Unfortunately can’t speak to that, as I don’t use it currently. Would suggest reading the docs around it - you could well be correct, I’m not able to confirm however.