ESPHome relays logic

Dear HA-friends

I have built a heating controller around an ESPHome relay board for my underfloor heating system which is working very well for me.
(You can find the details here: Underfloor heating project for a HA Newbie)

There is one little quirk that I need some help on though:
I have a number of relays (10) that all correspond to a valve in the heating system. And one spare relay which is supposed to be connected to the pump circulating the hot water. The thing is that the pump relay should go active when either of the 10 valve relays go active. And when the last valve relay goes inactive, the pump relay should also switch off. It is a bit like the boolean expression:
relay_pump = relay_valve01 || relay_valve02 || … || relay_valve10

The valve relays are controlled using the thermostat-card (climate-entity), but at the moment I don’t have any way of controlling the pump-relay.

How do I figure that out?

/D

I think on esphome set up an automation triggered on the valve state, condition as a big or statemeny, action to turn on/off pump.

Personally I would literally create a binary sensor in the way you’ve described (call it “pump_should_be_on”) and then use that to drive the pump state.

1 Like

Thanks for your advice, I will do some research and come back.

/D

Hey there!

So far I only had little time to play with the code, but I got as far as making a new binary sensor which combines all of the valves into one value, this code is in configuration.yaml:

template:
  - binary_sensor:
      - name: Underfloor Heating Circulation Pump Status
        unique_id: binary_sensor.pumpcontrol
        state: "{{
          is_state('switch.relay01','on') or
          is_state('switch.relay02','on') or
          is_state('switch.relay03','on') or
          is_state('switch.relay04','on') or
          is_state('switch.relay05','on') or
          is_state('switch.relay06','on') or
          is_state('switch.relay07','on') or
          is_state('switch.relay08','on') or
          is_state('switch.relay09','on') or
          is_state('switch.relay10','on') or
          is_state('switch.relay11','on')
          }}"
        device_class: "running"

With this I can see the value of this sensor changing with the valves. So far so good.

Next thing is to attach the pump relay (which is also ESPHome) to any changing state of my binary sensor and I am not sure how I should do that. Any suggestions, hints or links to relevant pages are welcome!

/D

You can also have automations defined in ESPHome itself. This way you can be sure that they will run even if HA is down. Take a look here: Automations and Templates — ESPHome

1 Like

I think something like this would work inside of esphome ?

You’ll need to add id to all your relays and the pump relay

binary_sensor:
  - platform: template
    id: pump
    lambda: |-
      if (id(relay01).state == 'on' or
          id(relay02).state == 'on' or
          id(relay03).state == 'on' or
          id(relay04).state == 'on' or
          id(relay05).state == 'on' or
          id(relay06).state == 'on' or
          id(relay07).state == 'on' or
          id(relay08).state == 'on' or
          id(relay09).state == 'on' or
          id(relay10).state == 'on') {
        return true;
      } else {
        return false;
      }
    on_press:
      then:
        - switch.turn_on: relay_pump
    on_release:
      then:
        - switch.turn_off: relay_pump

Hi wizards!

I ended up making two automations from the GUI, which was really easy. The source looks like the below.
Thanks to everybody who contributed!
/David


- id: '1698852385893'
  alias: Pump Control ON
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.underfloor_heating_circulation_pump_status
    from: 'off'
    to: 'on'
  condition: []
  action:
  - type: turn_on
    device_id: 68c47bc369e72d530c06cb1a08127bab
    entity_id: 3be1db4e3ec14babb42504c0b95079ac
    domain: switch
  mode: single
- id: '1698852739931'
  alias: Pump Control OFF
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.underfloor_heating_circulation_pump_status
    from: 'on'
    to: 'off'
  condition: []
  action:
  - type: turn_off
    device_id: 68c47bc369e72d530c06cb1a08127bab
    entity_id: 3be1db4e3ec14babb42504c0b95079ac
    domain: switch
  mode: single

For future posts please take a moment to figure out how to properly format your code so it is easier for us to read. See here…

1 Like