Step 4: Configure ESPHome to control the relays from Home Assistant

This article is part of the Make your Bellfire fireplace smart project that I presented during the Home Assistant Conference 2020.

It’s time to execute the fourth step, you can find all steps in the overview how it all going to work article.

The wiring is now ready, let’s expose three switches to Home Assistant to control the relays.

Expose pins as switches

Open ESPHome and click EDIT on your node. The ESPHome configuration editor will now show. Add following configuration in the bottom of the configuration.

switch:
  - platform: gpio
    pin: GPIO13   #D7
    name: "IN1" 
    id: IN1
  - platform: gpio 
    pin: GPIO12  #D6
    name: "IN2"
    id: IN2
  - platform: gpio 
    pin: GPIO14  #D5
    name: "IN3" 
    id: IN3

Note: The PIN name is translated from the physical D number printed on the ESP to the addressable name used in configurations and programming.  E.g. pin D7 is referred to as GPIO13, all mappings can be found in the image in the ESP Intro section.

UPDATE (thanks Petr): “Fortunately ESPHome knows the mapping from the on-board pin numbers to the internal pin numbering, but you need to prefix the pin numbers with D as in the image below in order for this automatic mapping to occur. In general, it is best to just use the D0, D1, … pin numbering to avoid confusion”

We are adding three switches of the platform type GPIO, this means that the switch will 1:1 control the GPIO pins. For every switch we define the GPIO pin that is controlled, and we provide a name and ID.

Flash the firmware Over The Air (OTA)

That’s it, now flash the firmware of the ESP with the updated firmware based on our new configuration. We do not need to use the flasher tool anymore, we can use the Over-The-Air flash feature to flash the chip with the new firmware over the WiFi Connection. It is as easy as clicking the UPLOAD button.

ESPHome will compile the new firmware, send it over to the ESP that will than flash itself. After flashing the ESP will come back online with the new firmware. It does not get much easier!

Control the relay from Home Assistant

Wait till the ESP has been flashed successful and is connected to the WiFi.

Find your device in Home Assistant, noticed that the device now has 3 entities. Click on the device and you’ll see that it has three switches, called IN1, IN2 and IN3.

Press the switches and enjoy the sound of clicking relays. Every switch should control the matching relay.

Create timing to control the fireplace

To control the fireplace I need to match following sequences with the switches:

  • Ignition, close contacts 1 and 3 simultaneously for 2 seconds
  • Fire off, clos contact 1,2, and 3 simultaneously for 1 second

We need to control the relays in these sequences with the ESP board. We can do this by extending the ESP configuration. We’ll add an Ignition switch that will execute sequences above when turned on and off.

Open ESP home and click edit on the node to go to the configuration editor.

Add a new Switch (right under IN3) with following configuration.

- platform: template
    name: "Fireplace_ignition"
    id: Fireplace_ignition
    turn_on_action:
      - then:
        - switch.turn_on: IN1
        - switch.turn_on: IN3
        - delay: 2s
        - switch.turn_off: IN1
        - switch.turn_off: IN3
        - switch.template.publish:
            id: Fireplace_ignition
            state: ON
    turn_off_action:
      - then:
        - switch.turn_on: IN1
        - switch.turn_on: IN2
        - switch.turn_on: IN3
        - delay: 1s
        - switch.turn_off: IN1
        - switch.turn_off: IN2
        - switch.turn_off: IN3
        - switch.template.publish:
            id: Fireplace_ignition
            state: OFF

Press the Upload to compile, upload and flash the ESP with the new firmware. Test your new switch and verify that the relay react as expected.

Now it’s time to for the last step, time to wire the relays to the fireplace.

9 Replies to “Step 4: Configure ESPHome to control the relays from Home Assistant”

  1. Hi man, really great show you did there! 😉
    Just one little comment – I believe you can use the “D” names of those pins, ESPHome will translate those when compiling the firmware, check the quote from the website “The NodeMCU’s pin numbering as seen on the board (the D0 etc pins) is different from the internal pin numbering. For example, the D3 pin number maps to the internal GPIO0 pin. Fortunately ESPHome knows the mapping from the on-board pin numbers to the internal pin numbering, but you need to prefix the pin numbers with D as in the image below in order for this automatic mapping to occur. In general, it is best to just use the D0, D1, … pin numbering to avoid confusion” (https://esphome.io/devices/nodemcu_esp8266.html)

    1. Hi Petr, that’s a really good feature. Let me update the article (and in the future my configurations).

  2. Hi Pieter
    Thank you for this guide. Was zelf al op zoek gegaan naar een manier om mijn Bellfire gashaard te bedienen via Home Assistant.
    I added a switch to lower the flame intensity.

    – platform: template
    name: “haardvuur lager”
    id: Fireplace_lower
    turn_on_action:
    – then:
    – switch.turn_on: IN3
    – delay: 4s
    – switch.turn_off: IN3
    – switch.template.publish:
    id: Fireplace_lower
    state: ON
    turn_off_action:
    – then:
    – switch.turn_on: IN1
    – delay: 4s
    – switch.turn_off: IN1
    – switch.template.publish:
    id: Fireplace_lower
    state: OFF

  3. Great job Pieter, and many thanks again for your help! I have the following components

    – Bellfires Debry Large 3 with double “branders”.
    – Mertik G6R-H4TV21-Z22 remote
    – Mertik G6R- R4AU

    Working great! The only downside is that I can’t control to switch between a single or double “brander” to be active, and I don’t thinkt it’s possible looking at the Mertik manual. For me the config was a bit different for shutdown and ignite:

    For shutdown, for a couple of seconds, I only need to enable:
    – platform: gpio
    pin: GPIO14 #D5
    name: “IN3”
    id: IN3

    To ignite, for 2 seconds, I only need to enable:
    – platform: gpio
    pin: GPIO13 #D7
    name: “IN1”
    id: IN1
    – platform: gpio
    pin: GPIO14 #D5
    name: “IN3”
    id: IN3

    For anyone interested. Me ESP config:
    – platform: gpio
    pin: GPIO13 #D7
    name: “GPIO – Increase flame”
    id: IN1
    – platform: gpio
    pin: GPIO12 #D6
    name: “GPIO – Decrease flame”
    id: IN2
    – platform: gpio
    pin: GPIO14 #D5
    name: “GPIO – Turn fireplace on/off”
    id: IN3

    And my HASS config:
    https://github.com/xirixiz/my-hass-config/blob/master/packages/fireplace.yaml

    Working like a charm!

    1. Thanks for your feedback. Glad that you figured out and shared your configurations so it can help others!

      Enjoy your ‘smart fireplace’ 🙂

    2. I need to find some time to get the centerfire function working. I’ve build this implementation the first time with ESPeasy for OpenHab, and rebuild it for the Hassio conf with ESP easy.

      I had the centerfire working before the rebuild, I just need to figure out the combination of the relays.

Leave a Reply

Your email address will not be published. Required fields are marked *