Different criteria to turn on vs off a binary switch via a template

I am looking to get a binary sensor in place that indicates if my attic fans are on or not. There is a non-smart temperature sensor attached to the fans, and I’ve found that they turn on when it hits around 108 degrees. However, once they are on, they will not turn off until it drops below 92 degrees (likely to prevent constant on/off conditions).

I have a separate temperature sensor up in the attic as well, and this is handled via another integration, so I do have the temperature in HA today that I am using for the binary sensor.

This works fine to turn on the sensor, but then I would need to somehow add logic to not turn it OFF until the logic is where sensor.attic_temp is < 92.

template:
  - binary_sensor:
      - name: "Attic Fans"
        state: "{{ states('sensor.attic_temp') | float > 108 }}"

I don’t see a way to control the on/off behavior differently other than waiting a certain period of time before it toggles the binary_switch off. Maybe I need to move away from a binary_sensor and go to a switch instead? Any guidance is greatly appreciated.

Don’t use a template sensor. Use this, it supports hysteresis so you can change on or off at different temperatures:

sensor.yaml

  - platform: threshold # on at 100 + 8, off at 100 - 8
    entity_id: sensor.attic_temp
    upper: 100
    hysteresis: 8
    name: Attic Fan

Thanks for this! I hadn’t ever come across this type of sensor in the past. I’ll give this a try - looks promising.