Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

Visualizing Thermostat/HVAC In Home Assistant With InfluxDB and Grafana

  1. Home

By Khalid on 2022/11/12 - 12:09, last updated 2022/11/14 - 14:50

If you already use Home Assistant, using the InfluxDB integration, coupled with Grafana will allow you to create very useful data visualizations that offers insight into your home over time. This includes things like: what are the humidity level fluctuations? What is the temperature indoors compared to outdoors? And much more ...

The Problem: Home Assistant Climate Integration

One question that took me many months of searching, is how to make a graph for the thermostat/HVAC, in order to see how long heating or cooling is running, versus indoor temperature and various other data points. The reason this is hard is that the thermostat uses the Climate integration in Home Assistant, which actually combines lots of data points into a single one entity, and making those data points attributes. As a result, it is not obvious how to get the data into InfluxDB. The Home Assistant forums have several questions on the topic that are either unanswered or involve convoluted partial solutions, such as using template sensors (example 1, example 2).

The rest of this article outlines how to solve the above problem, and get everything from Home Assistant to InfluxDB/Grafana.

Configure InfluxDB in Home Assistant

A minimal InfluxDB configuration in Home Assistant would not send an entity's attributes, or convert an entity into an InfluxDB measurement automatically.

To get over this limitation, you need to add the last four lines from the configuration snippet below:

influxdb:
  host: 127.0.0.1
  max_retries: 3
  tags_attributes:
    - entity_id
    - friendly_name
    - device_class

What this does is have each entity as a measurement and put the attributes as fields in there.

Side note: While you are at it, add the following, in order to get InfluxDB to better compress historical data:

  precision: ms

Once you add the above, and restart Home Assistant, you should be able to have queries like the ones below.

Create The Grafana Queries

Now you need to know what your thermostat entity name in Home Assistant, for example "climate.my_thermostat".

The following will show what desired temperature you have set the thermostat to.

SELECT last("temperature") 
FROM "climate.my_thermostat"
WHERE $timeFilter
GROUP BY time($__interval)
fill(previous)

And the following will show what actual temperature the thermostat is measuring from your indoor air.

SELECT last("current_temperature") 
FROM "climate.my_thermostat"
WHERE $timeFilter
GROUP BY time($__interval)
fill(previous)

And finally, you can create a graph of how long the thermostat is heating or cooling, per the following query.
Since the value for the hvac_action in Home Assistant is a string, the graph has to be a State Timeline in Grafana.

And while you are there, you may want to use the Value mapping option to assign colours to the various values (off, heating, cooling).

SELECT last("hvac_action_str") 
FROM "climate.my_thermostat"
WHERE $timeFilter
GROUP BY time($__interval)
fill(previous)

The Result: Everything Visualized

When you have completed all of the above steps, you can now see a graph like this one:

Acknowledgements

Thanks to Andrew Berry for his advice on the tag_attributes setting in Home Assistant YAML. Without this advice, this article would not have been possible.

Contents: 
Software
Tags: 
InfluxDB
Grafana
Home Assistant
HVAC
  • Add comment

Comments

garrett (not verified)

not working for me

Mon, 2023/08/28 - 17:30

I modified my influxdb configuration in configuration.yaml with the tags_attributes setting as prescribed.

influxdb:
    max_retries: 5
    precision: ms
    default_measurement: state
    tags_attributes:
      - entity_id
      - friendly_name
      - device_class

My climate entity as shown by hass-cli:

# hass-cli -o json state get climate.hallway
[
  {
    "entity_id": "climate.hallway",
    "state": "cool",
    "attributes": {
      "hvac_modes": [
        "heat",
        "cool",
        "off",
        "auto"
      ],
      "min_temp": 44.5,...

I still cannot access those values from grafana or influxdb command line.

SELECT last("temperature") FROM "autogen"."°F" WHERE ("entity_id"::tag = 'hallway') AND $timeFilter GROUP BY time($__interval) fill(null) ... 

or

>  select last("temperature") from "climate.hallway";

Nothing shows up.

  • reply

Khalid

Differences ...

Mon, 2023/08/28 - 18:00

One thing that is different in my case is that I don't have this line for influxDB:

default_measurement: state

As for values, this is the query that returns values to Grafana:

SELECT last("current_temperature") FROM "climate.mytherm" 
WHERE time >= now() - 1h and time <= now()
GROUP BY time(1m) fill(previous);

Returns this:

1693259760000000000 22.6
1693259820000000000 22.6
1693259880000000000 22.6
...
  • reply

garrett (not verified)

Thank you

Wed, 2023/08/30 - 09:39

Thanks for your response. That was it. I removed the default_measurement line from my configuration.yaml file and my queries work as you indicated. Now I just need to get the status visualization and temperature graph overlaid somehow so that the times line-up. My two graphs are a little "off". I really appreciate you sharing, though. I've been trying to get this status view worked out for a long time.

  • reply

Urban Olsson (not verified)

Thanks!

Wed, 2023/12/27 - 14:38

Exactly what I was looking for. Couldn't have done it on my own

  • reply

Current

Pandemic

  • COVID-19
  • Coronavirus

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • Origin Of COVID-19: Natural Spillover, Lab Leak Or Biological Weapon?
  • Kamal Salibi and the "Israel from Yemen" theory
  • How To Upgrade HomeAssistant Core In A Python Venv Using uv
  • Ancestry - Paternal Side
  • Review of Wait Water Saver For Whole House Humidifiers
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

Android Mobile Ubuntu Sony OnStep OpenWRT Router Ericsson COVID-19 Rogers Coronavirus Arabic Kubuntu Home Assistant GSM Telescope tablet Spectrum Scam Python 419 Laptop Firefox DIY CPU Conspiracy Comet Balkanization backup App
More

© Copyright 1999-2025 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.