Template Sensor - No errors, but no "sensor " created

I am trying to create a sensor from a template. I have checked the template in the development tool in the template editor and it provides the correct answer. The intent is to adjust a target temp based on temperature sensor using a simple slope calcuation.

I have place the code below in my configuration.yaml and I do not have any error when I reload the config but it doesn’t appear to be creating my new variable…

template:
  - sensor:
    - name: "TempThreshold"
      unit_of_measurement: "°F"
      state: >
        {% set LightThresTemp = states('sensor.quackshack_inside_temp') | float %}
         {{ (90 - LightThresTemp * 0.56)-0.33 }}

Try restarting home assistant. Also some suggestions to prevent possible errors in future:

Add a default value for your float filter to prevent errors if the source sensor is unavailable.
Add an availability template to make the sensor unavailable when the source sensor is unavailable, rather than presenting an invalid value.
Add a device and state class.

template:
  - sensor:
      - name: "TempThreshold"
        unit_of_measurement: "°F"
        device_class: temperature # gives the correct icon and other stuff.
        state_class: measurement # only if you want long term statistics.
        state: >
          {% set LightThresTemp = states('sensor.quackshack_inside_temp') | float(0) %}
          {{ (90 - LightThresTemp * 0.56)-0.33 }}
        availability: "{{ states('sensor.quackshack_inside_temp') | is_number }}"

Thanks a ton! The key was doing a full restart of the config. The device_class and state is great to know

1 Like