Sensor does not change state

I created a simple sensor to identify if the temperature is going to be warmer or cooler using darksky. It returned “warmer” but does not change to “cooler”. No errors in the logs. It’s as if it only evaluated when I restarted HASSIO and won’t evaluate again. What am I doing wrong?

  #State of weather for weather light bulb
  - platform: template
    sensors:
      weather_state_custom:
        entity_id:
          - sensor.dark_sky_daytime_high_temperature_0d
          - sensor.dark_sky_daytime_high_temperature_1d
        value_template: >-
          {% if float('sensor.dark_sky_daytime_high_temperature_0d') < 
          float('sensor.dark_sky_daytime_high_temperature_1d') %}warmer
          {% else %}cooler
          {% endif %}

You might need to specify “states.” prefix in the floats, something like:

float('states.sensor.dark_sky_daytime_high_temperature_0d')

You’re also missing a state at the end, and remove the quotes.
Copy an paste your template in Dev Tools/templates and play with it.

I suggest using the states(…) notation instead of states.xxx as recommended in the docs to avoid errors when the entity is not ready.

1 Like

VD, why bother with float if you are just going to print it immediately anyway ?
I prefer burning’s format if I was pushed.

Thanks everyone. Burningstones format works in the template tool, mine did not. modifying the configuration.yaml to:

  - platform: template
    sensors:
      weather_state_custom:
        entity_id:
          - sensor.dark_sky_daytime_high_temperature_0d
          - sensor.dark_sky_daytime_high_temperature_1d
        value_template: >-
          {% if states('sensor.dark_sky_daytime_high_temperature_0d') < 
          states('sensor.dark_sky_daytime_high_temperature_1d') %}warmer
          {% else %}cooler
          {% endif %}

Eric, you have marked your own post as the solution even though you said you went with Burning’s solution.
Think about this.
Imagine a world where every single question on a forum was solved by the original poster.
“Our work here is done !”
Everyone solves their own so we don’t even need to contribute
Easy !

amaximus, VDRainer and Burning gave you ideas and all nudged the solution along.
It is customary to give the solution to the guy who you feel helped you the most.

1 Like

Hi All,
I have similar issue. I have following template:

type or paste code here
sensor:
  - platform: template
    sensors:
      dryes_watts:
        value_template: '{{ states.switch.bathroom_dryer_machine.attributes["current_power_w"] | default(0) | round(2) }}'
        unit_of_measurement: 'W'


binary_sensor:
  - platform: template
    sensors:
      dryer_on:
        entity_id:
          - sensor.dryes_watts
          - switch.bathroom_dryer_machine
        value_template: >-
          {% if states('sensor.dryes_watts')|float >10 %}
            on 
          {% else %}
            off
          {% endif %}

Problem is that first sensor is updating value as expected, but the second on is always “off”. If I check in template editor (in HA web interface) - status is updated based on the first sensor.

Please format your code correctly, use the </> button and read the sticky at the top of the forum.

Your template (from what I can see of the text you’ve entered (I can’t be sure because of the formatting)) looks over complex try this for the template instead : -

    value_template: "{{ states('sensor.dryes_watts') | float > 10 }} "

And make sure your spacing is correct

Thanks.
This fix the issue. And I found what was the problem with my code - as the sensor is binary - value_template should return “true/false” instead of “on/off”

Yes binary sensors only have those two states, if you add a device class you can make it show ‘open’ and ‘closed’ and others also can be applied, but underneath it’s still true/false