Scott Conway

Information Security Researcher

mDNS in Isolated Docker Containers

I hope you’re ready for more smart home content.

I’ve been wanting to get a “smart” thermostat for some time now. I put a lot of time into research, since all of the contenders suck in their own ways.

Here were my requirements:

I think that’s a relatively modest ask. However, the only product that I could find that met these criteria was the long-abandoned RadioThermostat CT-80.

I bought it as old stock from ebay, but after two attempts, had trouble finding one that worked. The seller of the second one didn’t ask for it to be returned, so I opened it up and saw some suspiciously yellow capacitors. However, they weren’t marked with any identifiers that I could see, so I gave up trying to look for replacement caps. Due to its ~2010 manufacture date, I’m suspicious that the capacitors may have been affected by the capacitor plague.

If this device were sold today, this would be the solution to my problem. But alas, I gave up on it and looked elsewhere.

DIY ESP-based Thermostats

If nobody makes a product that fulfills this ask, why not make your own?

Joe Stump has a great writeup on making your own ESP-based thermostat with ESPHome and Home Assistant by use of an ESP8266-based relay board. However, this wouldn’t quite fit my requirements, due to lack of physical display/control/sensors (and would require an additional relay for humidifier control). That said, ESPHome can be used to achieve all of these things! It has support for all sorts of displays, and even touch screens, making physical control very doable. And of course, I could staple an SHT-31 to it for temperature and humidity sensing. However, it’d be a decent amount of work to implement, so again, I looked elsewhere.

Ecobee (but firewalled from the Internet)

Eventually, I found that a popular option for smart thermostats, Ecobees (or at least some Ecobees), support Apple HomeKit. This means that they can be (somewhat) controlled locally. So, it should be as easy as installing it, getting it on the network, and firewalling it off from the Internet, right?

Once set up and at the HomeKit pairing screen, I found that my Home Assistant server couldn’t find any un-paired devices.

I found some documentation on HA’s HomeKit Device integration page, that addressed the cause of the issue, but failed to point me in the right direction.

If your devices are on a different VLAN to Home Assistant you must have an mDNS reflector for discovery and pairing to work.

mDNS and Docker

After bouncing between several threads asking for help with this issue (and several people stating that you needed to use network_mode: host), I found a few contenders for mDNS reflectors. Here’s the one I settled on:

https://github.com/vfreex/mdns-reflector

Here’s how to use it:

Conclusion

This whole process sucked, and Ecobees don’t even expose all of their functionality via HomeKit, somewhat diminishing their usefulness to me. If you’re reading this, I beg you to productize a simple, modular ESP-32 based thermostat with ESPHome. All it needs is a few relays, onboard sensors, and a touchscreen display, with a management interface for its configuration. The local configuration doesn’t even need to be complex - it just needs to allow for changing the heat/cool/humidity set points.

Bonus - making ESPHome Dashboard device status work

After the issue with Home Assistant was resolved, I was reminded about how ESPHome’s dashboard won’t display online/offline status unless network_mode: host is used. It even recommends using host networking in its official documentation!

By default ESPHome uses mDNS to show online/offline state in the dashboard view. So for that feature to work you need to enable host networking mode.

Right - another case where a reflector can help. I tried forwarding mDNS to its bridge interface, but noticed no change. However, a quick change to the dns-search option for the container fixed it, no mDNS required. Thanks myradon! However, your DHCP configuration may differ, so I’m not promising that this will work for you. The simplest solution seems to be to use ICMP instead of mDNS, as stated in ESPHome’s documentation:

Alternatively, you can make esphome use ICMP pings to check the status of the device with the Home Assistant add-on "status_use_ping": true, option or with Docker -e ESPHOME_DASHBOARD_USE_PING=true. See also https://github.com/esphome/issues/issues/641#issuecomment-534156628.