How To Integrate Home Assistant with Grafana

Learn how to connect your Home Assistant setup with Grafana for advanced data visualization. Perfect for Home Assistant users looking to take their smart home monitoring to the next level with real-time insights and enhanced data analysis capabilities.

How To Integrate Home Assistant with Grafana

If you're running a smart home setup using Home Assistant, you already know how powerful it is for managing devices and automating tasks. But when it comes to analyzing and visualizing your data, Home Assistant’s built-in graphs may not offer the flexibility you need. This is where pairing Home Assistant with Grafana can unlock endless possibilities, enabling you to build custom dashboards and gain deeper insights into your home automation system.

In this guide, we’ll cover everything you need to integrate Home Assistant with Grafana. We’ll also explore how you can use a middleware platform like Telemetry Harbor to securely collect and process data before it reaches Grafana.


Why Integrate Home Assistant with Grafana?

Home Assistant excels at managing and automating smart devices but lacks advanced visualization capabilities for historical data. Grafana, on the other hand, is designed for creating powerful, customizable dashboards. By connecting the two, you can:

  • Create dashboards with interactive graphs, heatmaps, and alerts.
  • Monitor trends over time, such as energy usage or temperature fluctuations.
  • Analyze data from sensors and devices to identify patterns.
  • Aggregate and compare data from multiple sources in one place.

By using a centralized data collector or middleware, you can streamline this process and make it easier to manage your smart home data without overloading your Home Assistant instance.


What You’ll Need

Before starting, make sure you have the following:

  1. Home Assistant installed and running.
  2. A working understanding of YAML configuration in Home Assistant.
  3. Sensors or devices already configured in Home Assistant that you wish to collect data from.

Step 1: Create an Account in Telemetry Harbor

First, you need to create an account in Telemetry Harbor to start sending and managing your data.

1.1 Sign Up for Telemetry Harbor

  • Go to the Sign Up page on Telemetry Harbor.
  • Fill in your details to create your account.
  • After registration, check your inbox for a verification email.
  • Click the verification link to activate your account.
  • Once activated, log in to your Telemetry Harbor account.

Step 2: Create a Harbor in Telemetry Harbor

Now that you have an account, you'll need to create a harbor to send your Home Assistant data.

2.1 Create Your Harbor

  • In the top-right corner of your Telemetry Harbor dashboard, click Create Harbor.
  • Choose a name for your harbor.
  • Select the General type for now (you can choose more specific types like GPS or temperature data later).
  • If you're using the free tier, select the Free plan for now.
  • Click Create Harbor to finalize your harbor creation.

2.2 Access Harbor Credentials

  • After creating your harbor, the harbor list will update.
  • Click View Details for the harbor you just created.
  • Note down the following credentials from the Harbor Details page:
    • API Endpoint
    • API Batch Endpoint
    • API Key
    • Grafana Endpoint
    • Grafana Username
    • Grafana Password

Step 3: Edit configuration.yaml in Home Assistant

Next, you’ll need to configure Home Assistant to push data to your new harbor.

3.1 Define a REST Command

Open your configuration.yaml file in Home Assistant and add the following REST command configuration:

rest_command:
  push_all_sensors_data:
    url: "YOUR API BATCH ENDPOINT"
    method: POST
    headers:
      X-API-Key: "YOUR API KEY"
      Content-Type: "application/json"
    payload: >
      [
        {% for sensor in states.sensor 
            | selectattr('state', 'is_number') 
            | list %}
        {
          "time": "{{ now().utcnow().isoformat() }}Z",
          "ship_id": "{{ sensor.entity_id.split('.')[1].replace('_', ' ').title() }}",
          "cargo_id": "{{ sensor.attributes.friendly_name | default(sensor.entity_id.split('.')[-1].replace('_', ' ').title()) }}",
          "value": {{ sensor.state }}
        }{% if not loop.last %},{% endif %}
        {% endfor %}
      ]

Be sure to replace API Key and API Batch Endpoint with the actual API key and batch endpoint from the Harbor Details page you obtained earlier.

3.2 Save the Configuration

Once you’ve edited the YAML file, save the changes.


Step 4: Add an Automation to Send Data

Now, you'll want to automate the process of sending data to Telemetry Harbor on a regular basis.

4.1 Define the Automation

In the same configuration.yaml file, add an automation to trigger the REST command every 5 minutes (or another interval of your choosing):

automation:
  - alias: Push Data to Telemetry Harbor
    trigger:
      - platform: time_pattern
        minutes: "/5"
    action:
      - service: rest_command.push_all_sensors_data
💡
Remember that if you exceed the free tier limits (which allow 10 data points per batch), you may need to upgrade to a higher tier depending on the number of sensors you have.

4.2 Save and Restart

After adding the automation, save the changes to the YAML file and restart Home Assistant to apply the changes.


Step 5: Log in to Grafana and View the Dashboard

Now that the data is being sent from Home Assistant to Telemetry Harbor, you can set up Grafana to visualize this data.

5.1 Access Grafana

  • Go to the Grafana Endpoint provided in your Harbor Details page.
  • Log in using your Grafana Username (this will be the same as your Telemetry Harbor email) and the Grafana Password.

5.2 View the Telemetry Dashboard

  • Once logged in, navigate to Dashboards in Grafana.
  • Select the Comprehensive Telemetry Dashboard (this is the demo dashboard provided by Telemetry Harbor).
  • You should now be able to see live telemetry data from your Home Assistant sensors.
  • You can use the filters to view data based on ship_id and cargo_id.
  • Feel free to customize the dashboard or create new panels based on your needs.

Conclusion

Integrating Home Assistant with Grafana takes your smart home setup to the next level, giving you powerful tools to analyze and visualize data. Whether you’re tracking energy usage, monitoring room temperatures, or analyzing device performance, this setup opens the door to smarter automation and better decision-making. Now it’s your turn to get started—configure your setup, experiment with dashboards, and unlock new insights from your smart home data!