Custom sensor not visible


I’m new to HA, and I’m trying to create my first custom sensor, just the substraction of two sensor values.

I have added the following code to developer/templates:

  - sensor:
      - name: Sensor de Consumo
        unit_of_measurement: W
        state: "{{ states('sensor.inverter_active_power')|float(0) - states('sensor.power_meter_active_power')|float(0)}}"
#        state_class: "measurement" 
#        unique_id: energy_current_usage_power_sensor
#        device_class: current
#        icon: "mdi:power"
#        friendly_name: "Sensor de Consumo"

I can see the following in the right side:

  - sensor:
      - name: Current Power Usage
        unit_of_measurement: W
        state: "513.0"
#       state_class: "measurement" 
#       unique_id: energy_current_power_usage_sensor
#       device_class: current
#       icon: "mdi:power"
#       friendly_name: "Sensor de Consumo"

513 is a reasonable value for that sensor in the moment I’m doing this.

The problem is I cannot see the sensor at all, neither under devices, nor under entities. I can’t add it to a entities card in a panel, I can’t use it as trigger in automation. etc. It’s like it doesn’t exist.

I already restarted HA, and also I have tried to add that code directly to configuration.yaml and restart HA (no errors found on boot after I fixed a typo), but no way, it doesn’t appear.

Am I missing something?


PS: I’m using HA via a docker image running on a Synology NAS, in case it matters.
PS2: I’ve already checked other posts with more or less similar problems, and tried everything I saw on them, the code above is a curated version of my original code, but still doesn’t work :frowning:

The code should go in configuration.yaml . developer/templates is just for testing templates.

1 Like

Thanks. Understood, but it doesn’t work in configuration.yaml either.

You will need to go into developer tools /yaml and click on template entities at the bottom to reload your new sensor entity.

1 Like

That was it, it’s working now. Many thanks!