Sensors in sensor.yaml not showing up at all

Hi,

Try as I might, I just can’t get any sensors defined in sensor.yaml to show up! I’ve done the sensor: !include sensor.yaml in configuration.yaml and I don’t see any errors in the log.

What am I missing?

template:
  - sensor:
    - name: 'PS Propane Tank Percentage'
      unique_id: sensor.propane_ps_pct
      icon: mdi:propane-tank
      state: >
         {# Set three user supplied variables. Use the same units that the mo>
         {% set overall_length = 94.00 %}
         {% set overall_tank_diameter = 30.00 %}
         {% set wall_thickness = 0.25 %}

         {% set internal_tank_diameter = overall_tank_diameter - 2 * wall_thi>
         {% set side_length = overall_length - overall_tank_diameter %}

         {% set measured_fill_depth = states('sensor.pro_check_b09e_tank_leve>

         {% set R_tank = internal_tank_diameter / 2 %}

         {% set spherical_volume = 4 / 3 * pi * R_tank**3 %}
         {% set cylinder_volume = side_length * pi * R_tank**2 %}
         {% set max_volume = spherical_volume + cylinder_volume %}

         {# Calculate the volume of a spherical cap of height equal to the fi>
         {% set fill_spherical_volume = pi / 3 * measured_fill_depth**2 * (3 >
         {# Calculate the volume of a partial horizontal cylinder: https://ww>
         {% set fill_cylinder_volume = side_length * (R_tank**2 * acos((R_tan>

         {% set measured_fill_volume = fill_spherical_volume + fill_cylinder_>

         {{ (100 * measured_fill_volume / max_volume) | round(2) }}

  - sensor:
    - name: kevin_test
      unique_id: kevin_test
      state: "1234"

If you have this:

sensor: !include sensor.yaml

then it’s NOT for Template Sensors defined in modern format, only in legacy format.

Modern format Template Sensors are defined under the template: key, which you have, but you then put them in a file that is under the sensor: key.

You can do this

template: !include template.yaml

Then put the modern format Template Sensors (and any other Template entities) in template.yaml. However, ensure the first line of the file does NOT contain template: because that would be redundant (and cause a YAML configuration error).

Thanks. I tried that, but I’m still not seeing my template sensor.

  - sensor:
    - name: 'PS Propane Tank Percentage'
      unique_id: sensor.propane_ps_pct
      icon: mdi:propane-tank
      state: >
         {% set overall_length = 94.00 %}
         {% set overall_tank_diameter = 30.00 %}
         {% set wall_thickness = 0.25 %}

         {% set internal_tank_diameter = overall_tank_diameter - 2 * wall_thickness %}
         {% set side_length = overall_length - overall_tank_diameter %}

         {% set measured_fill_depth = states('sensor.pro_check_b09e_tank_level') | float - wall_thickness %}

         {% set R_tank = internal_tank_diameter / 2 %}

         {% set spherical_volume = 4 / 3 * pi * R_tank**3 %}
         {% set cylinder_volume = side_length * pi * R_tank**2 %}
         {% set max_volume = spherical_volume + cylinder_volume %}

         {# Calculate the volume of a spherical cap of height equal to the fill level: https://www.vcalc.com/wiki/Volume-of-a-Sphere-Cap #}
         {% set fill_spherical_volume = pi / 3 * measured_fill_depth**2 * (3 * R_tank - measured_fill_depth) %}
         {# Calculate the volume of a partial horizontal cylinder: https://www.vcalc.com/wiki/volume-of-horizontal-cylinder #}
         {% set fill_cylinder_volume = side_length * (R_tank**2 * acos((R_tank - measured_fill_depth) / R_tank) - (R_tank - measured_fill_depth) * sqrt(2 * R_tank * measured_fill_depth) %}


         {% set measured_fill_volume = fill_spherical_volume + fill_cylinder_volume %}

         {{ (100 * measured_fill_volume / max_volume) | round(2) }}

If you never used template sensors before, you need to restart HA

You could have a tiny syntax error in there, so start with a stripped down version with a simple number to get the sensor creation working and find some success. Then I would take that big template into the developer template tools and make sure what you want is happening. Then paste all that in the working sensor instead of the placeholder number above.
Small steps, testing between, saves frustration and brings better results.

The following line in your template is missing a closing parenthesis.

Oh, I’m restarting after every change.

Good catch. I’ve fixed that line and still no sensor appearing, however.

Check the Log for errors, especially after any time you execute Developer Tools > YAML > Reload Template Entities.

In addition, when creating values for unique_id use letters, numbers, and underscores.

Change this:

unique_id: sensor.propane_ps_pct

to this:

unique_id: sensor_propane_ps_pct

Is what you posted here represent everything in the template.yaml file or is there more?