DIY Heating and Hot Water Controller

Sure. Has some complications for dealing with turning off mid position valve, dealing with LEDs, and having the double press to force heating on (fall back if losing connection to WiFi/temperature senors). I’m sure if could be improved, but working for now :grinning_face_with_smiling_eyes:

esphome:
  name: heating-controller
  platform: ESP8266
  board: esp12e
  on_boot:
    priority: 800.0
    then:
      - climate.control:
          id: heating_controller
          mode: "OFF"

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  reboot_timeout: 0s

ota:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  power_save_mode: none
  reboot_timeout: 0s

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Heating-Controller"
    password: !secret fallback_password

captive_portal:

status_led:
  pin:
    number: GPIO5
    inverted: True

switch:
  - platform: gpio
    pin: GPIO16
    id: relay1
  - platform: gpio
    pin: GPIO14
    id: relay2
  - platform: gpio
    pin: GPIO12
    id: relay3
    interlock: [relay4]
  - platform: gpio
    pin: GPIO13
    id: relay4
    interlock: [relay3]

  - platform: template
    id: heating
    lambda: |-
      if (id(relay2).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      then:
        - switch.turn_on: relay2
        - if:
            condition:
              switch.is_off: hot_water
            then:
              - switch.turn_on: relay4
    turn_off_action:
      then:
        - switch.turn_off: relay2

  - platform: template
    name: "Hot Water"
    id: hot_water
    lambda: |-
      if (id(relay3).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      then:
        - switch.turn_off: relay4
        - switch.turn_on: relay3
        - light.turn_on: hot_water_led
    turn_off_action:
      then:
        - switch.turn_off: relay3
        - if:
            condition:
              or:
                - switch.is_on: heating
                - lambda: |-
                    if (id(heating_controller).mode) {
                      return true;
                    } else {
                      return false;
                    }
            then:
              - switch.turn_on: relay4
        - light.turn_off: hot_water_led

output:
  - platform: esp8266_pwm
    id: heating_led_output
    pin: GPIO4
  - platform: gpio
    id: hot_water_led_output
    pin: GPIO15

light:
  - platform: monochromatic
    id: heating_led
    output: heating_led_output
    effects:
      - pulse:
      - pulse:
          name: pulse_fast
          transition_length: 0.5s
          update_interval: 0.5s
  - platform: binary
    id: hot_water_led
    output: hot_water_led_output

binary_sensor:
  - platform: gpio
    id: heating_button
    pin:
      number: GPIO0
      inverted: true
      mode: INPUT_PULLUP
    filters:
      - delayed_off: 10ms
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at most 1s
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          if:
            condition: # heating & mode OFF
              and:
                - switch.is_off: heating
                - lambda: |-
                    if (id(heating_controller).mode) {
                      return false;
                    } else {
                      return true;
                    }
            then:
              - switch.turn_on: heating
              - light.turn_on:
                  id: heating_led
                  effect: pulse_fast
      - timing:
          - ON for at most 1s
          - OFF for at least 0.5s
        then:
          - if:
              condition:
                or: # Heating or mode ON
                  - switch.is_on: heating
                  - lambda: |-
                      if (id(heating_controller).mode) {
                        return true;
                      } else {
                        return false;
                      }
              then:
                - if:
                    condition: # heating mode OFF
                      lambda: |-
                        if (id(heating_controller).mode) {
                          return false;
                        } else {
                          return true;
                        }
                    then:
                      - switch.turn_off: heating
                      - switch.turn_off: relay4
                      - light.turn_off: heating_led
                - climate.control:
                    id: heating_controller
                    mode: "OFF"
              else:
                - climate.control:
                    id: heating_controller
                    mode: "HEAT"
  - platform: gpio
    id: hot_water_button
    pin:
      number: GPIO2
      inverted: true
      mode: INPUT_PULLUP
    filters:
      - delayed_off: 10ms
    on_press:
      then:
        - switch.toggle: hot_water

sensor:
  - platform: homeassistant
    id: hall_temperature
    entity_id: sensor.hall_temperature

climate:
  - platform: thermostat
    id: heating_controller
    name: "Heating Controller"
    sensor: hall_temperature
    default_target_temperature_low: 20.0 °C
    visual:
      min_temperature: 16.0 °C
      max_temperature: 24.0 °C
      temperature_step: 0.5 °C
    min_heating_off_time: 0s
    min_heating_run_time: 0s
    heat_overrun: 0.5 °C
    heat_deadband: 0.2 °C
    heat_action:
      - switch.turn_on: heating
      - light.turn_on:
          id: heating_led
          brightness: 100%
          effect: None
    min_idle_time: 0s
    idle_action:
      - switch.turn_off: heating
      - light.turn_on:
          id: heating_led
          effect: pulse
    off_mode:
      - switch.turn_off: heating
      - switch.turn_off: relay4
      - delay: 0.2s  # Clashes with going idle
      - light.turn_off: heating_led
    heat_mode:
      - light.turn_on:
          id: heating_led
          effect: pulse


Hi, this is the wiring diagram of my heat pump. Do you think something similar can be done?

1 Like

Looks orders of magnitude more complicated, with a number of additional parts and sensors. I’d suggest probably better to look at modifying the existing user controller, or even look at CN1/CN2 inputs if you could reverse engineer the protocol.

1 Like

For me is impossible :pensive::face_with_raised_eyebrow:
Thank you for reply

1 Like

I just starting today to look around for such a project. This is great…

@kwirk are you happy with the EST board ? If so, I’m probably going to get the same one. I was hoping to put some redundancy into place… maybe next year :slight_smile:

@belanger I’ve had no issues with it. Been working great. WiFi seems stable, maintaining connection to Home Assistant, which I was little worried about given lots of metal pipework around where I installed it.

They now make an ESP32 version, which has Bluetooth, so may be useful if you have BLE temperature sensors, so could have remote sensor(s) that don’t need to go via Home Assistant (even if as fall back). I think I’d try that out if I was making it again.

1 Like

Very glad to hear that board has been working great. The ESP can likely last for years but the remaining of the board is what worries me most, so the reason to have in mind “redundancy”. I can be away for many weeks.

Not sure if your code is almost “plug n play” to ESP32, if so great. I had in mind to hard wire a T probe but BLE is great idea actually, no need to pass any wire. Perhaps hard wire for outdoor T/humidity and BLE for inside?!? In my area during winter, humidity sensor can be useful to turn on the central humidifier.

I’m not working on any of this within the next ~6-12 weeks, until then will thicker.

1 Like

Should be, other than probably needing to change GPIO pin numbers. ESPHome does all the hard work for you.

I use the Xiaomi LYWSD03MMC sensors throughout the house, so those within range would be picked up easily enough. But I’m happy with ESP8266 board and sending temperature from Home Assistant for now.

1 Like

I have also built a HA-based system for hot water and central heating on a Y-Plan system. However I kept it simple by just replacing the old timer with a SONOFF CH4 PRO switch. It has 4 channels but I only use two: one for hot water and one for central heating. You need the PRO because you need two-way switching of hot water for Y-Plan. One reason I did this is that a future owner of the house could still easily go back to a conventional timer if required.

I use a SONOFF temperature sensor for the hot water cylinder and a cheap temperature sensor in the living room for the central heating (as the living room is the warmest place). Both are controlled with the HA generic thermostat integration.

The ‘last port of call’ motor energisation when not in use happens if you turn off central heating and hot water at the same time. The valve is deigned to cope with this, but to avoid it, an automation could be written that ensures the central heating is turned off at least 10 seconds after the hot water – to allow the valve time to revert to its default hot water only position. That cannot be difficult, but I have not actually done it yet.

2 Likes

Hi Andy,

I am looking to do something similar. I want to keep all my old fashion controls but retrofit them with Shelly 1 relays.

I’ve managed to create an override for the room thermostat by placing a Shelly 1 relay with temperature sensor inline with the switch line and added automation to modulate the CH.

What I’m struggling with is the HW. I havent managed to work out how to control that using a Shelly 1. All I suceeded in doing is turning it all off rather than just the HW.

How did you achieve this with the sonoff?

Many thanks,

Tim

1 Like

@kwirk still all working ok? This is exactly what I’m looking for, probably going to go with a 4 channel relay board and ESP32 NodeMCU separate, but pretty much the same product.

1 Like

Yeah, still working fine without any issues :grinning_face_with_smiling_eyes:

Only thing I’d change if making again, as mentioned in a previous comment, is using the ESP32 version of the board so could communicate to BLE temperature sensors direct in case of WiFi or Home Assistant issues.

3 Likes

@TimDog If you have a y-plan valve then it is important to wire both HW on and HW off – so you need relays with both NO and NC accessible (on and off respectively). The latter makes sure that the CH still works if you do not have HW on, otherwise tuning HW off also turns off the CH. I don’t think the Shelly relays have this. I used the SONOFF CH4PRO, which does have NO and NC accessible.
I found this YouTube video helpful Y plan wiring - made simple - YouTube

2 Likes

Having looked further into this, I’ve gone the Sonoff CH4 Pro R3 route like you @AndySymons i’ve just flashed the CH4 with ESPHome and have managed to add a string of dallas temperature sensors to the spare GPIO2 on the PCB so I can measure boiler flow/return, cylinder temp etc.

2 Likes

@fuzzyfelt I look forward to hearing how you do. I did not bother with ESPHome in this case (though I use it elsewhere) since SONOFF works with eWelink and is picked up for local control in the SONOFF LAN integration.

1 Like

Hi @kwirk I’m using a similar set up as per my reply above and have used a lot of the ESPHome code that you’ve used (thanks!). Would you mind expanding a bit on the control logic and how you’ve wired the mid position valve? As using 3 relays slightly complicates it from the standard Y plan.

Thanks.

1 Like

So my mid-position valve I have has two live feed inputs, one for “heating on” (white) and one for “hot water off” (grey). The problem occurs, when not using heating or hot water, that live feed on “hot water off” keeps valve open, and the motor gets hot. But when using the heating, the the “hot water off” has to be live (if hot water off), so need to manage it if you want to remove all power when not in use.

The logic in the ESPHome, if I configured it correctly, should be that the “hot water off” will turn off only if the heating is off (and obviously the hot water is off as well). If the heating is on, “hot water off” will be live…but regardless, when you want hot water, that “hot water off” must be off, as “hot water on” is live. You’ll see I have interlock on relay 3 and 4 to prevent having both live. (The thermostat on the hot water tank, is what then feeds the “hot water on” live to valve grey wire when tank is hot enough)

Here’s is a diagram I made which I have alongside the controller (just in case someone needs to know how’s it wired…including me!). The “LT” and “HT” are the low temperature and high temperature from hot water tank thermostat.

Hope this helps. Happy to clarify or answer more questions.

2 Likes

Great, thanks! This is extremely helpful, now it’s finding the time to have a tinker! Will report back when I’ve got it working.

1 Like

Hi @kwirk,

Thanks for this really detailed sharing.
For my need, i no need thermostat. I just need temperature setting point.
I tried to break the “Generic Thermostat” to answer my needs but it appears that I failed.
in here my post on my needs: Generic Temperature setting point · home-assistant/frontend · Discussion #17028 · GitHub
On thing I don’t like is that Generic Thermostat doesn’t have persistent data on hvac_mode and the temperature setting point. I even don’t know if it’s a feature in HA.
It means that on HA restart, your setpoint and your hvac mode is back to initial values in your config file.

1 Like

Sorry to ressurect this thread but I am so glad that I have stumbled accross as it seems to cover exactly what I am looking to do.

I currently have a Y Plan system.

The heating is set to constantly on and this is connected to a digital thermostat in my hallway. All the scheduling is done via the thermostat.

The hot water is set to come on once in the morning and once in the evening but we find it really difficult to find a schedule that constantly works - we always seem to be running out of water.

My main goal is to somehow add a temperature sensor to the hot water tank and then have HA turn on the water earlier than its usual schedule if it senses that it has less hot water in it than usual.

One other thing I would say is that I am looking to move house in the next 18 months or so, so I am wary that I should be able to replace the timer and thermostat easily when needed.

Any advice on where to start would be much appreciated - I note that the SONOFF CH4 PRO seems to be a good place to start.