How to expose template sensor to Home Assistant

Hello.

Who knows how can I expose a template sensor I created in ESP Home to Home Assistant?

this is my code :

sensor:
  - platform: template
    id: "pwmfan"
    update_interval: 2s
    accuracy_decimals: 0
    lambda: |-
      return id(fan).speed;

This shows me the % of my fan speed on the display connected to my ESP8266.

I want to show this in Home Assistant Lovelace, too.

Go into Configuration, Entities, and search for sensor.pwmfan. From there you can expose the entity information, and somewhere under there is an “Add to Lovelace” link, I believe.

That´s my problem. There is no sensor.pwmfan. Only fan.pwmfan with that I can control it, but not the sensor entity…

Okay. I got it!

I simply didn´t define a “name” :slight_smile:

I added this and now the sensor is exposed to HA!

sensor:
  - platform: template
    name: "PWM Fan Speed"
    id: "pwmfan"
    update_interval: 2s
    accuracy_decimals: 0
    lambda: |-
      return id(fan).speed;
1 Like

IIRC if you don’t give a name, the sensor is internal only.