The idea

The build itself took place when the weather started getting colder last year. I had been using Home Assistant for a while to bridge a gap between incompatible domestic IoT devices, and figured this would be a great use case. We live in Ireland, so the winters are relatively mild, but I still wanted to make sure our four-legged family member was nice and comfy while myself and the missus were in work all day. Using Home Assistant gave me an easy way to implement automation based on real feel attribute and provide a nice UI for manual override remotely.

The heat pad

I picked this heated outdoor pet heat pad over the more traditional space heater types, as direct contact is more efficient, and at only 30W power draw it could easily be left on all day without costing a fortune or setting the kennel on fire (nobody wants that). The doggie has been happy so far :)

The build

The first step was removing the plug as the on/off function will be handled by an EM relay and Arduino:

Heat Pad Drill Heat Pad

Next, I had to wire up the relay, microcontroller and power. The easiest approach was getting an IP66 rated junction box with enough space to house all the components.

To power the Arduino Pro Mini, I salvaged an old Blackberry charger and soldered it straight to the Arduino power header:


Once the Arduino had a power source, the relay, voltage step-down (to lower 5V output required by relay to an acceptable 3.3V for the radio) and radio could be wired in and connected to the leftover weather shielded and chew proof(!!!) cable, chopped off at the start. The radio module picked was NRF24L01+PA+LNA with an external antenna to facilitate communication between the gateway module behind a concrete wall (more on the wiring, gateway and software side below).

Wiring Junction Box Spaghetti

Once the Arduino is flashed with simple relay code (made possible by MySensors library) and everything is tested, the kennel can be put back together so the doggie won't know any different:

Insulation Complete Plugged

The wiring

The project uses the MySensors library at its core, and their wiring diagrams are quite easy to follow:

The kennel module code

The following can be flashed to the Arduino in order to make the relay controllable by MySensors gateway:

// Enable debug prints to serial monitor
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <MySensors.h>
#define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define NUMBER_OF_RELAYS 1 // Total number of attached relays
// You may need to flip the below values, depening on hi/lo config and wiring
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay

void before()
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        pinMode(pin, OUTPUT);
        digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);

void setup()


void presentation()
    sendSketchInfo("Relay", "1.0");
    for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
        present(sensor, S_BINARY);

void loop()


void receive(const MyMessage &message)
    if (message.type==V_STATUS) {
        digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
        saveState(message.sensor, message.getBool());
        Serial.print("Incoming change for sensor:");
        Serial.print(", New status: ");

The gateway

At the time, I chose to use the ESP8266 development board as the gateway. The MySensors nodes operate using their own network protocol on the 2.4GHz frequency. In order to make it talk to HomeAssistant easily, I wanted a WiFi gateway to access the sensors over TCP/IP. There are options, including a serial gateway, but these did not suit my needs at the time. The Raspberry Pi gateway is another appealing option, as that's what I've HomeAssistant running on anyway for the time being, or MQTT that essentially sits on top of the TCP/IP version.

Building the gateway is not a terribly complex task, involving connecting a radio module (linked in the wiring section above) and flashing the ESP8266 with the sample Gateway code found on MySensors website. Only modification needed is your SSID and password.

Once the gateway starts up, and you power-cycle the relay module, a simple telnet gatewayip gatewayport command should show you the communication between the relay and ESP8266. You should be observing a row of numbers, standing for node-id ; child-sensor-id ; command ; ack ; type ; payload \n

The controller

The fun part is Home Assistant. If you haven't heard of them, go check them out. It's much like open-Hab, only written in Python, and arguably more powerful. Once everything is configured, we've a remotely controlled heated kennel:

Pretty much everything in Home Assistant is configured by editing $HASSDIR/configuration.yaml. What I was looking to achieve, was a way of automating the heating pad so that our dog was always nice and cosy while we were in work, rain or shine. To achieve that, weather forecast component using DarkSky api in Home Assistant can be used:

  - platform: darksky
    api_key: YOUR_API_KEY
      - summary
      - icon
      - temperature
      - apparent_temperature

In the above sensor entity, we're specifically interested in the sensor.dark_sky_apparent_temperature value. This is what many weather forecast services refer to as "real feel" i.e the combination of temperature / cloud cover / wind chill. Once we've configured the component to our liking, the kennel heating can be added to configuration.yaml. As we used MySensors library for both the gateway and kennel module, adding it is simple:

    - device: 'gateway.ip.address'
      persistence_file: 'path/to/mysensors3.json'
      tcp_port: 5003
  optimistic: false
  persistence: true
  retain: true
  version: 2.0

There's really nothing more to adding the heating pad relay to HomeAssistant, as it'd be automatically discovered on power-cycle (aka presentation). Next, we can grab appropriate entity IDs from Home Assistant web UI, and proceed to edit configuration.yaml to get a basic automation rule going and an item to show in the frontend:

  - alias: "turn kennel on"
      platform: numeric_state
      entity_id: sensor.dark_sky_apparent_temperature
      below: 12
      service: switch.turn_on
      entity_id: switch.relay_2_1

  - alias: "turn kennel off"
      platform: numeric_state
      entity_id: sensor.dark_sky_apparent_temperature
      above: 12
      service: switch.turn_off
      entity_id: switch.relay_2_1

  icon: mdi:radiator
  friendly_name: Kennel Heating

I would highly advise reading the Home Assistant component documentation and giving it a try. It's fairly easy to get up and running, and the project is backed by an amazing community. If you have any questions or comments, feel free to comment below :)

comments powered by Disqus

Checking mdadm for failed drives with Python and Pushover

I've been running a file and media server at home to share stuff with family and friends for many years. As the collection of media has grow…… Continue reading