Binary_sensor doesnt initialize properly based on state values

I’m trying to create a binary sensor which indicates whether my basement humidity is less than my living room humidity. I’ve tried doing it directly and also via another template sensor which calculates the relative temp. Neither seems to correctly capture the state.

Screen shot (notice that since the relative humidity is -7.0 I would expect that the basement < humidity state would be “on”.

Any idea whats going on wrong here?

`

sensor 3:
    platform: template
    sensors:
        basement_minus_living:
            friendly_name: 'Basement Humidity - Living Room Humidity'
            value_template: '{{ states.sensor.basement_humidity.state|float - states.sensor.living_room_humidity.state|float}}'

binary_sensor:
    platform: template
    sensors:
        basement_humidity_lt_livingroom_humidity:
            friendly_name: 'Basement Humidity < Living Room Humidity'
            value_template: '{{ ((states.sensor.basement_minus_living|float)) < 0}}'

A wild stab in the dark and I don’t have time to check for you but I suspect that the binary sensor in the UI will respond to states of “on” or “off” - if you rewrite your template to have these values it might work.

The binary sensor documentation provides the following example which I believe is very similar to what I’ve done so not sure what you mean by on/off rewriting?

# Example configuration.yaml entry
binary_sensor:
  platform: template
  sensors:
    sun_up:
      value_template: '{{ states.sun.sun.attributes.elevation > 0}}'
      friendly_name: 'Sun is up'

Figured it out. If you apply the |float operator to the state object it will return 0.0 irrespective of the underlying state. You need to apply the |float operator to the state of the state object. Not sure I’m using the right terms here but if others run into this:

Correct:
states.sensor.basement_minus_living.state|float

Incorrect:
states.sensor.basement_minus_living|float