Posted in

Monitoring Temperature Trends with Home Assistant

As I’m writing this article, we’re dealing with a heatwave over here. Every day we have to make a decision: do we open the windows to let fresh air in or keep them closed to maintain the cool indoor air?

Home Assistant has become my go-to tool for gathering all the data I need to make these decisions. With the right setup, I can track temperatures inside and outside and even determine whether the temperature is rising or falling.

Tracking Indoor and Outdoor Temperatures

To perform this analysis, I use several different integrations:

  • Netatmo: My Netatmo outdoor temperature module reliably reports the current outside temperature and whether it’s trending up or down.
  • Aqara Temperature Sensors and Tado Thermostats: Inside the house, I monitor temperatures in all rooms using Aqara sensors and Tado Thermostats and Radiator Valves.

Combining these sensors provides a complete picture of the temperature dynamics throughout the house.

The Importance of Trend Analysis

While Netatmo conveniently shows whether the temperature is increasing or decreasing, the indoor sensors don’t offer this out of the box. That’s where Home Assistant comes in handy.

By leveraging the Trend integration, you can analyze whether a temperature is trending upward or downward over a given time period.

Creating Trend Binary Sensors

Let’s look at a concrete example: tracking the temperature in my office using the entity sensor.office_temperature.

Here’s the YAML configuration to create two binary sensors — one for rising temperature and one for falling:

binary_sensor:
  - platform: trend
    sensors:
      office_temperature_rising:
        entity_id: sensor.office_temperature
        sample_duration: 3600 # 1 hour
        max_samples: 10
        min_gradient: 0.0001389 # ~0.5 °C increase
        device_class: heat
      office_temperature_falling:
        entity_id: sensor.office_temperature
        sample_duration: 3600 # 1 hour
        max_samples: 10
        min_gradient: -0.0001389 # ~0.5 °C decrease
        device_class: cold

This configuration checks over a 60-minute window to see if the temperature has changed by approximately 0.5 °C. The reason I went with these numbers, is mostly related to when Aqara sensors update themselves. Here is the explanation from their official website:

If the temperature, humidity and atmospheric pressure vary only a bit, data will be reported once an hour.
If the temperature variation exceeds 0.5℃ (1℉), the humidity variation exceeds 6% and the atmospheric pressure is no less than 25hPa, data will be reported instantly.

So overall, when no big change is being detected, no update is being reported, which means the trend is relatively stable.

Adding a Temperature Sensor with Trend Icon

To make this trend information visually clear, I created a Template Sensor. This sensor reuses the original temperature reading but changes the icon dynamically:

  • Thermometer Plus: Temperature rising (mdi:thermometer-plus)
  • Thermometer Minus: Temperature falling (mdi:thermometer-minus)
  • Thermometer: No significant trend (mdi:thermometer)

Here’s the YAML for the template sensor:

sensor:
  - platform: template
    sensors:
      office_temperature_with_trend:
        device_class: temperature
        value_template: "{{ states('sensor.office_temperature') | default(0) }}"
        icon_template: >
          {% if states('binary_sensor.office_temperature_falling') == "on" %}
            mdi:thermometer-minus
          {% elif states('binary_sensor.office_temperature_rising') == "on" %}
            mdi:thermometer-plus
          {% else %}
            mdi:thermometer
          {% endif %}

Displaying the Sensor in Your Dashboard

Office Temperature with Trend indication

Finally, you can add sensor.office_temperature_with_trend to your Home Assistant dashboard. This way, you not only see the current temperature but also at a glance whether it’s getting hotter or cooler.

Leave a Reply

Your email address will not be published. Required fields are marked *