Need a second set of eyes on feasibility of a 3 way fireplace design

I'm still fairly new to Arduino, having just played around with some simple circuits so far with an Uno. Now I'm trying to figure out whether what I want to do is feasible, before dropping the coin on the new boards needed to support this project.

I want to Homekit enable my fireplace, but not in the same manner as every other reference I've found on the internet. Like many others, my fireplace is controlled by a wall mounted switch, connected to the Millivolt system generated by the thermopile. Most people who have enabled their fireplaces have either:

a) Replaced the fireplace switch with a relay, disabling the switch from working


b) Added a relay in parallel to the switch, which means the method that turns on the fireplace has to be the same one that turns it off.

In my house, neither of these would generate a good user experience for my family. For instance, if somebody walks by and flips the fireplace on from the switch when entering the room, then, when they want it shut off they'd have to go back to the switch instead of using voice commands. Similarly, if they were all snuggled in watching TV, and wanted the fire on and used a voice command, they couldn't then just hit the switch on the way out turning it off.

The existing HomeKit switches we have in our house (Leviton Decora Homekit ones) provide a 3-way type of behaviour. I can hit the switch walking by, and then ask Siri to turn it off, and vice versa. I can't use a smart switch with a millivolt system obviously, so I want to see if I can recreate the same behaviour in software in an Arduino, controlling a relay, and have the wall switch connect to the Arduino instead. There's no mains voltage at the switch, it's just a switch loop from the thermopile and gas valve, so I don't see there being an issue with the hardware side of things. (Other than one question I'll get to further on down.)

My issue is, I'm not familiar enough with how HomeKit is implemented. I've found various libraries for ESP32 and ESP8266 that supposedly can be integrated with the Arduino IDE, but since I only have an Uno on hand currently, they're not ones I can test out yet. What I want to know is if these kinds of libraries support this flip/flop approach I'm attempting? I'd like to be able to effectively have the state of the relay represented in Homekit, and to be able to change the state of the relay from either a Homekit command, OR the fact that whatever GPIO pin I connect the switch to goes High/Low accordingly. Ideally, hitting the switch will either turn on or off the fireplace, depending on the state of the relay and the state of the switch. Like, if the fireplace is currently off, closing the switch will turn it on. Or, if the fireplace is on, closing the switch will turn it off.

Secondly, on the hardware, what type of board should I be looking at for this implementation? The libraries I've found are for either the ESP32 or the ESP8266, but I'm not familiar with them (yet). Do they essentially work similarly to my Uno, just with less onboard features?

My thanks for any feedback.


What gives you the impression that a Uno has more features than an ESP32?

Here is a link to the ESP32's API, you may see that the ESP32 can do a whole lot more then an Uno, API Reference - ESP32 - — ESP-IDF Programming Guide latest documentation (

Sorry, perhaps a poor choice of phrasing. I didn't mean the ESP32 was less capable, just that the boards I've looked at don't physically have the same features like the Uno, like a barrel jack input for power, a button, an onboard LED, breadboard headers, etc.... Heck, some of the ESP32s I've seen on Amazon didn't seem to have a USB connection, so I'm not sure how I'd even program those ones. (I intended to pick up one of the ones with a USB to avoid that). When it comes to the actual chip, yes the ESP32 actually has more features than the ATMega in my Uno.

With the ESP, I'll have to do a little more hands work, like figuring out how I want to get power to it, soldering directly to the GPIO pads instead of leveraging the breadboard style headers on the UNO, etc. All stuff I'd probably want to do anyways for an actual install vs a prototype, but still, stuff I have to work out how to do vs just using the Uno.

Not much help but here is a ESP32, one of 2, in my weather station:

I realize what's going on there, but it looks really odd at first sight to have that tiny little ESP needing that giant battery :laughing:

There are 2 ESP32's juicing on the battery. The large battery is for the winter time.

Where the project can spend weeks under the snow, with only brief periods of sunlight offering little in the way for recharging from the solar cell.

Well, I went ahead and ordered this ESP32 ( and this relay ( As I said in my first post, I'm completely unfamiliar with this boards, so hopefully I've picked ones that will work with what I'm trying to do here, and I that I'm not completely off my rocker.

HomeSpan/HomeSpan: HomeKit Library for the Arduino-ESP32 (

Yurik72/ESPHap: ESP32/ESP8266 Arduino library for native Apple Homekit Accessory Protocol (HAP) (

Reads as if they'll work with an ESP32. One has even been updated to work with the ESP32S models. Shows that maintenance is still going on.


Well, it turns out I picked the wrong relay. Didn't realize it at the time but that was a latching relay. I had to signal the relay twice to get it to change state. So, I had to go buy some other ones.. which of course I could only find in a 5 pack. (

Using the proper relays and the HomeSpan library, I've got the solution working on the bench. Now I'm just waiting for a prototype board to come in so I can solder it instead of the breadboard I'm using now. In the meantime, here's what I'm using to achieve this three-way approach, first the code:

 * This program is used to control a relay to turn a fireplace on and off
 * while converting the existing wall switch into a three way switch.
 * To do this, the existing wall switch will need to be wired between the Ground and a GPIO Pin on the ESP32.
 * The Relay would be attached to the other GPIO Pin.  
 * Once in place, the wall switch changing state, whether being turned on or turned off, 
 * will cause a flip-flop in both the relay and the HomeKit state.  This allows the user the ability to turn on
 * the fireplace with either the wall switch or Homekit, and also turn off the fireplace with either the
 * wall switch or Homekit.  This is an improvement over the other provided solutions that require the fireplace
 * to be turned off via the same method it was turned on.

#include "HomeSpan.h"
#include "DEV_FIREPLACE.h"

void setup() {
  //Setup the Serial Monitor.

  new SpanAccessory(); 
    new Service::AccessoryInformation(); 
      new Characteristic::Name("Fireplace"); 
      new Characteristic::Manufacturer("Heat-N-Glo"); 
      new Characteristic::SerialNumber("123-ABC"); 
      new Characteristic::Model("6000DVTFL"); 
      new Characteristic::FirmwareRevision("0.9"); 
      new Characteristic::Identify();            
    new Service::HAPProtocolInformation();      
      new Characteristic::Version("1.1.0");  

    new DEV_FIREPLACE(16,17); //Structure is the Pin Number going to the Relay Input, followed by the Pin Number where the wall switch gets attached.


void loop() {
  // put your main code here, to run repeatedly:



 * New structure to support a Relay as a Switch in Homekit

int switchStatus;
int previousSwitchStatus;
struct DEV_FIREPLACE : Service::Switch { 

  int switchPin;
  int wallSwitchPin;                                       
  SpanCharacteristic *power;
  SpanCharacteristic *name;                        
  DEV_FIREPLACE(int switchPin, int wallSwitchPin) : Service::Switch(){

    power=new Characteristic::On();
    name=new Characteristic::Name("Fireplace");                 


  boolean update(){            


  void loop(){
    switchStatus = digitalRead(wallSwitchPin);
    if(switchStatus != previousSwitchStatus)
      //Need to make Homekit flip
      //Then update the previous status to the new status
      previousSwitchStatus = switchStatus;

Supporting this, I would need to wire the ESP32 and the Relay (sort of, not exact as I didn't draw in all the components on the relay board, just the transistor and the relay itself so I can represent the VCC, GND and Trigger the board takes) like this:

Once I get the ESP, relay and connectors mounted into a permanent state, I'll update again with how those turned out.

Thanks again for all the help.


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.