Generic thermostat with scheduler

Hi there!
It has been one month since @vladosam and me did this, and I figured we should share the project, as I think someown out there will find this thing usefull.
What we did (@vladosam did most of the stuff, i was more like ginny pig) is to convert my old central heater in the apartmen in to smart heater :wink:
I hooked up sonoff basic in to boiler (central heater) instead of the old thermostat. I already had some temperature sensors around apartment (xiaomi and BRUH multisensor).
This is how it looks like in the HA frontend:

And here is my configuration package:

######################
# Climate - central heater
######################
climate:
  - platform: generic_thermostat
    name: Heater
    heater: switch.heater
    target_sensor: sensor.sn1_temperature
    min_temp: 20
    max_temp: 29
    target_temp: 21
    tolerance: 0.3

######################
# Automation part
######################
automation:
- alias: 'Time heater on'
  hide_entity: true
  trigger:
    - platform: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_time_heater.state }}'
  condition:
    condition: or
    conditions:
      - condition: and
        conditions:
          - condition: state
            entity_id: input_boolean.alarmweekday_heater
            state: 'on'
          - condition: state
            entity_id: binary_sensor.working_day
            state: 'on'
      - condition: state
        entity_id: input_boolean.alarmweekday_heater
        state: 'off'
  action:
    - service: climate.set_operation_mode
      data:
        entity_id: climate.heater
        operation_mode: "auto"
    - service: climate.set_temperature
      data_template:
        entity_id: climate.heater
        temperature: '{{ states.input_number.set_temp_heater.state }}'

- alias: 'Turn heater ON boolean switch'
  hide_entity: true
  trigger:
    - platform: state
      entity_id: climate.heater
      to: 'heat'
  action:
    - service: homeassistant.turn_on
      entity_id: input_boolean.automode_heater

- alias: 'Turn time heater OFF'
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_boolean.timeonoff_heater
      to: 'off'
  action:
    - service: automation.turn_off
      entity_id: automation.time_sheduler_heater

- alias: 'Timer scheduler ON'
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_boolean.timeonoff_heater
      to: 'on'
  action:
    - service: automation.turn_on
      entity_id: automation.time_sheduler_heater

- alias: 'thermostat_heater Temp'
  hide_entity: true
  trigger:
    - platform: state
      entity_id: input_number.set_temp_heater
  action:
    - service: climate.set_temperature
      data_template:
        entity_id: climate.heater
        temperature: '{{ states.input_number.set_temp_heater.state }}'

- alias: "thermostat_heater On"
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_boolean.automode_heater
    from: 'off'
    to: 'on'
  action:
    - service: climate.set_operation_mode
      data:
        entity_id: climate.heater
        operation_mode: "auto"
    - service: climate.set_temperature
      data_template:
        entity_id: climate.heater
        temperature: '{{ states.input_number.set_temp_heater.state }}'

- alias: "thermostat_heater Off"
  hide_entity: true
  trigger:
    platform: state
    entity_id: input_boolean.automode_heater
    from: 'on'
    to: 'off'
  action:
    - service: climate.set_operation_mode
      data:
        entity_id: climate.heater
        operation_mode: "off"

# thermostat INITIALIZATION
- alias: 'HASS startup'
  initial_state: true
  hide_entity: true
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: climate.set_operation_mode
      data:
        entity_id: climate.heater
        operation_mode: "off"
    - service: climate.set_operation_mode
      data:
        entity_id: climate.heater
        operation_mode: "off"
    - service: homeassistant.turn_on
      entity_id: input_boolean.timeonoff_heater
    - delay: '00:00:02'
    - service: homeassistant.turn_off
      entity_id: input_boolean.timeonoff_heater
    - service: homeassistant.turn_on
      entity_id: input_boolean.timeonoff_heater
    - delay: '00:00:02'
    - service: homeassistant.turn_off
      entity_id: input_boolean.timeonoff_heater

sensor:
 - platform: template
   sensors:
     alarm_time_heater:
       friendly_name: 'Time'
       value_template: '{{ "%0.02d:%0.02d" | format(states("input_number.alarmhour_heater") | int, states("input_number.alarmminutes_heater") | int) }}'

input_boolean:
  alarmweekday_heater:
    name: Worday only
    icon: mdi:calendar
  automode_heater:
    name: 'Set AUTO / OFF'
    initial: off
  timeonoff_heater:
    name: 'Scheduled heater'
    initial: off

input_number:
  alarmhour_heater:
    name: Hour
    icon: mdi:timer
    min: 0
    max: 23
    step: 1
  alarmminutes_heater:
    name: Minutes
    icon: mdi:timer
    min: 0
    max: 59
    step: 1
  set_temp_heater:
    mode: slider
    name: Set temperature
    initial: 21
    min: 15
    max: 30
    step: 0.5
    unit_of_measurement: "°C"

This is in groups.yaml

 Central heater:
   name: Central heater
   control: hidden
   entities:
    - climate.heater
    - switch.heater
    - input_boolean.automode_heater
    - input_boolean.timeonoff_heater
    - sensor.alarm_time_heater
    - input_number.set_temp_heater
    - input_number.alarmhour_heater
    - input_number.alarmminutes_heater
    - input_boolean.alarmweekday_heater

As I had almost all of this in Croatian language (automations and switch names etc.), I did my best to translate it to english, so everyone can understand what is what.

8 Likes

Very nice, but i’m missing the ‘scheduled turn off’ part here.
You turn auto schedule the heater on at for example 6h35 through the sliders, but for how long the heater stay on and when does it turn off?

Or do you turn if off manually?

1 Like

I turn it off manualy, and it is the part I’m missing this days.
I’m gonna have to add it soon in to the config.
Ofcourse - heater turns off automaticly if it reaches targeted temperature

True it will turn off when temp is reached.

I was looking for scheduled dynamically turning on (as example above) and off for each desired room.
Room 1= 2 hours
Room 2= 3 hours (bigger room)

Later when colder, add half an hour to each room or whatever time we want.

Just registered on HA community to thank you.

That’s what I wanted to add to my config

That’s the reason I posted all this here, as I tryed searching it, and didn’t find anything similar here.
Luckily @vladosam contacted me, and we started to work on my problem.
Keep in mind there are some typos in the configuration, I just noticed it (worday - workday :stuck_out_tongue_winking_eye:)

1 Like

Hi,

@elRadix

You could add an input_boolean for dynamic turning off to serve as trigger for the automation and use a delay made from input sliders for hours or minutes:

action:
  - delay: '{{ states.input_number.heater_off_after_x_hours.state | int }}:{{ states.input_number.heater_off_after_x_minutes.state | int }}:00'
  - service: climate.set_operation_mode
    data:
      entity_id: climate.heater
      operation_mode: "off"

Hi there!
Awesome work here and very inspiring :smiley: !

Now that generic thermostat has away mode, i’m trying to figure out how to incorporate that in your setting, say in automation when i’m not home and the away mode turns on, but i’m stuck at the moment :confused:

Invalid service data for climate.set_away_mode: required key not provided @ data[‘away_mode’]. Got None

this is the error i get.

Hmmmm… Paste you config so we can take a look.

  • service: climate.set_away_mode
    data:
    entity_id: climate.living_room_thermostat
    set_away_mode: “on”

edit:
i’ve found my mistake, it’s supposed to be:

away_mode: on

Awsome, I realy don’t use away mode… I usualy just turn on heater when I’m on my way home.
How does away mode work for you?

I just have an automation to turn away mode on, when i’m not home. That’s basically it.
It sets a temperature of 16c.
And I set it to turn back on when I arrive at home with presence detection.

That’s actualy awsome solution!
Ill try that out

@INTEL why you turn on and turn off this automation multiple times?

- service: homeassistant.turn_on
  entity_id: input_boolean.timeonoff_heater
- delay: '00:00:02'
- service: homeassistant.turn_off
  entity_id: input_boolean.timeonoff_heater
- service: homeassistant.turn_on
  entity_id: input_boolean.timeonoff_heater
- delay: '00:00:02'
- service: homeassistant.turn_off
  entity_id: input_boolean.timeonoff_heater

Sometimes input boolean switch stuck in wrong position on hass reboot, this way I’m shure it will be in off possition when hass reboot.
The point of double entry here is becouse I have 2 heaters I’m using the same automation, just forgot to delete second automation.
This should be enough:

- service: homeassistant.turn_on
  entity_id: input_boolean.timeonoff_heater
- delay: '00:00:02'
- service: homeassistant.turn_off
  entity_id: input_boolean.timeonoff_heater
1 Like

Please help me with climate. Current room temprature is 21.1 and target_temp: 19 but heater is still on .
I think heater must turn off when meet target temp.

climate:
      - platform: generic_thermostat
        name: heater
        heater: switch.switch_4
        target_sensor: sensor.fibaro_system_fgms001_motion_sensor_temperature
        min_temp: 18
        max_temp: 28
        target_temp: 19
        tolerance: 0.1
        initial_operation_mode: "auto"
        min_cycle_duration:
          seconds: 5
        keep_alive:
          minutes: 3

Hi, this is my config for generic thermostat, try using that:

climate:
  - platform: generic_thermostat
    name: Centralno
    heater: switch.centralno
    target_sensor: sensor.temperature
    min_temp: 15
    max_temp: 30
    target_temp: 22
    tolerance: 0.3
    initial_operation_mode: "off"
1 Like