How to Install and Configure Cloudflare Tunnel on Home Assistant (2024)

In this tutorial, we will guide you through the steps on how to install and configure Cloudflare Tunnel on Home Assistant. If you require external access to your Home Assistant installation, Cloudflare Tunnel is an excellent free option. It allows you to securely route traffic from your internal private network and expose it to the internet, without the need to open ports on your router. This setup helps protect your device from direct exposure to the internet. However, please note that Cloudflare has limitations on the usage of heavy data, such as video.

Prerequisites

Before we begin, there are a few things you need to have set up:

  1. Domain Name: You will need to own a domain name or use a subdomain to access your Home Assistant setup. If you don't already own a domain, you can purchase one from reputable domain name providers like Cloudflare Register or Namecheap.

  2. Cloudflare Account: Set up a Cloudflare account with your chosen domain. You can point a domain from another provider to Cloudflare. Familiarize yourself with the Cloudflare dashboard and available services, especially the Zero Trust Dashboard.

  3. Home Assistant: Ensure that Home Assistant is set up on a local device, such as the Raspberry Pi. Make sure add-ons are available on your setup. If not, consider setting up Cloudflare tunnels on a different device and using that to access your Home Assistant installation.

Installing the Cloudflare Tunnel Add-on on Home Assistant

Installing the Cloudflare Tunnel add-on is relatively straightforward. Follow these steps:

  1. Inside your Home Assistant web UI, click on "Settings" and select the "Add-ons" menu item.

  2. Click on the add-on store button.

  3. On the add-on store page, click the kebab menu icon and select "Repositories".

  4. In the add field, enter the following URL: https://github.com/brenner-tobias/ha-addons. This URL points to the add-on repository for the unofficial Cloudflared add-on.

  5. First, refresh the page to ensure the new repository is viewable. Search for "Cloudflared" or look for it in the add-on list. Once you find it, click on it.

  6. On the Cloudflared add-on page, click on "Install".

  7. Once the add-on is installed, several options will appear. It is recommended to turn on the "Start on boot", "Watchdog", and "Auto update" options. Before starting the add-on, you may want to do the basic configuration first, as described in the next section.

Connecting the Add-on to Cloudflare

To connect the add-on to Cloudflare and access your Home Assistant externally without opening ports, follow these steps:

Local Method:

  1. In your preferred code editor, open the configuration.yaml file. Enter the following configuration lines to allow the Cloudflare Tunnel to communicate correctly with Home Assistant:

    http:
     use_x_forwarded_for: true
     trusted_proxies:
       - 172.30.33.0/24
  2. Restart Home Assistant to load the new configuration. Go to Developer Tools, click on "Restart", and select the "Restart Home Assistant" option.

  3. Set the hostname you wish to use externally. For example, it could be ha.mydomain.com if you're using a subdomain or mydomain.com if you're not using a subdomain. Go to "Settings" and then click on the Cloudflared add-on. Next, click on the "Configuration" tab.

  4. Enter the domain or subdomain you wish to use externally for Home Assistant. Once entered, click on "Save".

  5. Start the add-on by going back to the "Info" tab and clicking on "Start".

  6. Once the add-on has started, go to the "Log" tab. Inside the log list, you will find a URL that you need to copy and paste into your browser. Follow the steps to authenticate with Cloudflare, making sure to select the same domain you specified in the add-on.

  7. If you navigate to the domain you specified, you should now be able to access and navigate your Home Assistant installation.

Remote Method:

  1. In your preferred code editor, open the configuration.yaml file. Enter the following configuration lines to allow the Cloudflare Tunnel to communicate correctly with Home Assistant:

    http:
     use_x_forwarded_for: true
     trusted_proxies:
       - 172.30.33.0/24
  2. Restart Home Assistant to load the new configuration. Go to Developer Tools, click on "Restart", and select the "Restart Home Assistant" option.

  3. Go to the Cloudflare Zero Trust Dashboard and log in. Navigate to "Access" and then "Tunnels". Click on "Create a Tunnel".

  4. Select an identifying name for your tunnel, such as "home-assistant-tunnel". After entering the name, click on "Save Tunnel".

  5. On the "Install Connector" screen, you will see instructions for installing the tunnel on different operating systems. Ignore the instructions and extract the token from the code snippet. The token is a long string of numbers and characters.

    Save the token in a safe place for now. Scroll down the page and click "Next".

  6. Enter the hostname you wish to use for accessing your Home Assistant. For example, set it to be ha.pimylifeup.com.

    In the "Service" field, specify the details of your Home Assistant installation. It is recommended to specify the IP and port for stability. For example, if your Home Assistant URL is http://192.168.0.40:8123, enter http and 192.168.0.40:8123 in the "Service" field.

  7. On the tunnel page, you will notice that the tunnel is inactive. To activate it, enter your details within the Cloudflared add-on on Home Assistant. If you need to make any changes to the tunnel, click on the three dots and select "Configure".

  8. Load Home Assistant in your browser, go to "Settings", and then click on the Cloudflared add-on. Next, click on the "Configuration" tab.

  9. Toggle the "Show Unused Optional Configuration Options" and enter the token you saved earlier into the "Cloudflare Tunnel Token" field. Once done, click on "Save".

  10. Start the add-on by going to the "Info" tab and clicking on "Start".

  11. You can verify that the tunnel is correctly set up by navigating to the "Log" tab within Home Assistant. Alternatively, you can check the Cloudflare Zero Trust Dashboard to see that the tunnel is now showing as "Healthy" instead of inactive.

Conclusion

By following the steps outlined in this tutorial, you should have successfully installed and configured Cloudflare Tunnel on your Home Assistant installation. This will allow you to securely access your Home Assistant externally without the need to open ports on your router. Remember to consider the limitations of Cloudflare, such as avoiding heavy data usage, and explore additional security options like the Cloudflare Zero Trust feature. Enjoy the benefits of remote access to your Home Assistant setup!

How to Install and Configure Cloudflare Tunnel on Home Assistant (2024)
Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 6402

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.