Science and technology

Control your own home automation remotely with Raspberry Pi and Traefik Hub

Over the years, a number of pals have requested me for recommendations on managing their residence networks. In most instances, they’re establishing residence automation and wish to entry their providers from the surface.

Every time I helped them, every made the identical remark: “Are you kidding? It cannot be so complicated to publish one simple application!”

Publishing functions that do not put your community or cluster in danger can certainly be fairly difficult. When we began engaged on Traefik Hub—the newest product by Traefik Labs—I knew it might be a game-changer for publishing functions.

This article demonstrates the complexity of publishing providers and the way Traefik Hub makes your life so much simpler. I take advantage of the instance of establishing a server to regulate your own home automation remotely with Traefik Hub working on a Raspberry Pi.

The problem

Setting up a server to handle your own home automation is sweet, however having the ability to management it remotely from wherever on the earth utilizing solely your cell phone—that is even nicer!

However, with nice energy comes nice duty. If you need entry to your native community from the surface, you’d higher guarantee it is resilient and that you’re the one one with entry.

First, I’ll have a look at the steps you’ll usually take to realize that.

Reach your Home Assistant remotely any time

Home Assistant is a widely known resolution to handle residence automation units. It’s an open supply undertaking written in Python. It means that you can have Home Automation with a neighborhood set up: No information on the cloud and every little thing is saved non-public. I like to recommend this excellent article that can assist you set up Home Assistant in your Raspberry Pi utilizing Docker.

To attain your Home Assistant from the surface, you have to expose your Raspberry Pi to the web. To achieve this, you must:

Note: Most web suppliers assign dynamic public IPs—every time your router restarts, your IP will in all probability change. To construct a resilient system, you’ll additionally want a dynamic area.

Encryption issues

When you talk along with your server, you ship delicate information, similar to your username and password. You should confirm and encrypt communication utilizing a TLS certificate to keep away from this information being stolen.

This requires:


To sum it up, after putting in Home Assistant in your Raspberry Pi, it’s essential:

  • Get your router public IP.
  • Create a port ahead to your Raspberry Pi.
  • Buy a site identify.
  • Create a dynamic area.
  • Install a reverse proxy and configure it for encrypted entry utilizing a TLS certificates.

Now, think about when you might skip all the steps above and publish your providers in just a few clicks!

Traefik Hub to the rescue

Traefik Hub is a cloud-native networking SaaS platform that enables customers to publish their providers on the edge shortly. Using Traefik Hub, you may publish your Home Assistant utility in just a few clicks.

Remember the challenges I discussed earlier? Scratch that. Once you could have Home Assistant put in in your Raspberry Pi, all you must do is join your Raspberry Pi to Traefik Hub. Traefik Hub handles every little thing for you, together with:

  • Making your service reachable from the web.
  • Providing a dynamic area (without spending a dime).
  • Encrypting communication with a TLS certificates and an Access Control Policy.

And now that I’ve launched Traefik Hub, I’ll get right down to the enterprise of configuring it.

Step 1: Connect your Raspberry Pi to Traefik Hub

First, head over to Traefik Hub and sign up for a free account. You can enroll by way of Google or GitHub.

You want so as to add a brand new agent to attach your Raspberry Pi to Traefik Hub.

(Nicolas Mengin, CC BY-SA 4.0)

Traefik Hub supplies a number of snippets that mean you can begin from scratch.

Since the Home Assistant setup is a bit advanced, you will get your token from the Hub UI and use the script under for this instance. The token means that you can join your agent to Traefik Hub. Traefik Hub then attaches this agent to your account, and you can begin publishing your providers.

Here’s the script:

model: '3'

  traefik: {}

    container_name: homeassistant
    picture: ""
                  # /! Mount the customized configuration file described under /!
      - ./configuration.yaml:/config/configuration.yaml
      - /and many others/localtime:/and many others/localtime:ro
    restart: unless-stopped
    privileged: true
      - traefik
                        - 8123
        # Start the agent with the newest model
    restart: "on-failure"
    container_name: hub-agent
      - traefik
      - run
      - --hub.token=<YOUR_TOKEN> # Set your token right here
      - --auth-server.advertise-url=http://hub-agent
      - --traefik.tls.insecure=true
      - --hub.url=
      - --hub.ui.url=
      - /var/run/docker.sock:/var/run/docker.sock
      - traefik

  # Start Traefik with the newest model
    picture: traefik:v2.8
    container_name: traefik
      - traefik
      # Enable Hub communication (open the port 9900 and 9901 by default)
      - --experimental.hub=true
      - --hub.tls.insecure=true
      - --metrics.prometheus.addrouterslabels=true

# ./configuration.yaml to mount on your own home assistant container
# in /config/configuration.yaml

# These modifications are required by residence assistant to be uncovered utilizing
# a 3rd celebration software program such because the Traefik Hub agent

# Loads default set of integrations. Do not take away.

  ip_ban_enabled: true
  login_attempts_threshold: 5
  use_x_forwarded_for: true
    - ::1
    - fe80::/64
    - fe00::/64
    - fd00::/64

# Text to speech
  - platform: google_translate

Step 2: Publish your service

Once you could have put in the agent in your Raspberry Pi, Traefik Hub discovers each service working in your cluster so you may publish them with out digging into your configuration recordsdata.

(Nicolas Mengin, CC BY-SA 4.0)

Select your Home Assistant service, and click on the Save and Publish button to publish it.

(Nicolas Mengin, CC BY-SA 4.0)

And now let the magic occur!

(Nicolas Mengin, CC BY-SA 4.0)

Once Hub notifies you that your service has been printed, you may attain it from the web utilizing the area Traefik Hub has generated. The connection is verifiable and encrypted, and your Home Assistant stays reachable even when your public IP adjustments.

(Nicolas Mengin, CC BY-SA 4.0)

Behind the scenes

Your utility is printed. Next, I’ll talk about just a few issues Traefik Hub takes care of behind the scenes to supply a seamless expertise and a few useful configuration choices.

Traefik occasion

When you put in the Traefik Hub Agent, you actually observed that it comes with a Traefik Proxy occasion.

Traefik Hub creates a tunnel between its platform and the agent you put in in your Raspberry Pi to publish your service on the web. The agent passes by the requests to open supply Traefik Proxy, which is used as an Ingress Controller. Traefik Hub manages each the area and the TLS certificates, and it shares the certificates along with your Traefik occasion to permit it to do the TLS termination.

(Nicolas Mengin, CC BY-SA 4.0)

Access Control Policy

Another level to recollect is {that a} deployed Home Assistant utility comes with its personal login system. However, whenever you publish a service utilizing Traefik Hub, you may limit entry additional by utilizing an Access Control Policy similar to JWT and Basic Auth.

(Nicolas Mengin, CC BY-SA 4.0)


If you’re a Kubernetes person, you may as well publish your Kubernetes Services. Traefik Hub can handle Kubernetes Services by the UI or a devoted CRD.

Manage and monitor

Traefik Hub additionally supplies an online UI that means that you can handle and monitor the exposition of providers.

(Nicolas Mengin, CC BY-SA 4.0)

Wrap up

This article began by going by an extended and sophisticated checklist of duties that include publishing an utility over an encrypted and verifiable connection. Setting up residence automation is a wonderful instance of that stage of complexity. But when issues appear impossibly onerous, there’s all the time a neater various! Traefik Hub makes your life less complicated by taking up a lot of the mundane operations duties, saving time, and permitting builders to deal with constructing functions.

Now you may flip the lights on in your home, even when you’re on the opposite aspect of the world!

If you are all in favour of studying extra about Traefik Hub, take a look at this getting started article. Traefik Hub is presently in Beta, so please do not hesitate to offer it a try to present suggestions—you are able to do so straight within the UI.

I hope you discovered this text useful, and thanks for studying!

Most Popular

To Top