Custom sensor not showing up

Good morning and sorry for my english, i made this custom sensor that bring data from a sensor that gmcan goes positive or negative (it’s a shelly em connected to the main breaker and if the solar energy is higher that the home consuption it goes to negative). In this case, this sensor have to show only the positive numbers, in case of negative, have to show 0, then i can make a meter that count the W to make an accurate “real consumes from the electric company sensor” this is the code

template:
 - sensor:
    - name: consumi_positivi_da_rete_enel
      friendly_name: "Consumi positivi da rete enel"
      state_class: measurement
      device_class: power
      unit_of_measurement: W
      state: "{{ 0 if  states('sensor.consumo_enel_power')|float(0) < 0 else states('sensor.consumo_enel_power') }}"
      availability: "{{ has_value('sensor.consumo_enel_power') }}"

Where i make error? In the log i can’t see error and also in studio code. I really appreciate a solution, thanks

Remove this line completely:

friendly_name: "Consumi positivi da rete enel"

Then change this:

- name: consumi_positivi_da_rete_enel

To this:

- name: Consumi positivi da rete enel

No error in the log vut no sensor created, this sensor is in a yaml file in the folder sensors and another file in this folder work perfecty

How did you include the folder sensors ?

template: is an integration, like sensor: is an integration. They should appear in the configuration.yaml file like this:

sensor:
  - platform: ... etc

  - platform: ... etc

template: 
  - sensor:
      - name: ... etc

  - sensor:
      - name: ... etc
  - sensor:
      - name: ... etc

You can of course use includes to put these entities in files of their own:

sensor: !include sensors.yaml

template: !include templates.yaml

You can not do this:

configuration.yaml

sensor: !include sensors.yaml

sensors.yaml:

  - platform: ... etc

  - platform: ... etc

template: 
  - sensor:
      - name: ... etc

My configuration is this


I thought that was only to specify where the sensir ditectory is, because the other sensor file works but maybe i don’t understa d something in the proces

You are not making a sensor: entity; you are making a template: entity. Put all of the code in your original post (without the friendly_name line) directly into configuration.yaml.

This work! Thank you

Which was exactly what I told you to do two posts ago.

1 Like

I understand it better now i think :slight_smile: