Thermostat with hysteresis / smoothing factor

I am looking for a Thermostat in HA with hysteresis / smoothing factor.

Currently I have this in Domoticz, but I would like to move completely to HA.

The script in Domoticz:

Hysteresis:

Thermostat without Hysteresis: As soon as the sensor/room hit the desired temperature, it would immediately power the switch, which causing the AC/Heating unit to turn on and off in very short cycles.

Average reading:

Also there is a smoothing factor in the script: don’t use the current reading but average it out over the past <SMOOTH_FACTOR> readings (data smoothing) to get rid of noise, wrong readings etc. So if you open a window for 1-2 min in winter and your sensor reads -5C as usual, it does not turn on your heating immediately, because of smooth factor - average reading is not under the set temperature. So temperatures are stored in a variable (avgTemp in the script), and they are averaged.

I don’t know about the hysteresis thing, but there is a filter sensor for the averaging

Also the options for generic thermostat I think will do the hysteresis thing

Thanks not the filter sensor, but the statistics sensor works nicely.

I want to try out heating system on a dummy switch. I am using this:

sensor:
  - platform: statistics
    entity_id: sensor.room_temp
    sampling_size: 3

input_boolean:
  heating_device:
    name: Heating device

binary_sensor:
  - platform: template
    sensors:
      futes:   
        value_template: "{{ states.input_boolean.heating_device.state }}"

climate:
  - platform: generic_thermostat
    name: Heating  
    heater: input_boolean.heating_device
    target_sensor: sensor.stats_mean
    min_temp: 15
    max_temp: 29
    ac_mode: False
    target_temp: 23   
    cold_tolerance: 0.5
    hot_tolerance: 0
    min_cycle_duration:
      seconds: 5
    keep_alive: 
      minutes: 3
    initial_operation_mode: "off"
    away_temp: 19

As you can see I am trying to accomplish this with a input_boolean, but it doesn’t seem to be updated.

I have a thermostat + relay connected to it in HA, initial_operation_mode: “off”. When thermostat is turned ON and I restart HA, thermostat starts as OFF as it should, but relay switch remains ON. What would be the best way to be sure to turn OFF relay if thermostat is OFF? I think thermostat should be send an OFF command on start.