I have four air quality sensors in my home, each measuring different pollutants. I wanted to create a sensor that shows the highest value among these sensors to get a clear picture of the worst air quality condition in real-time. After some research and experimentation, I found a solution using a template sensor. Here’s how I set it up:
yaml
- platform: template
sensors:
air_max:
friendly_name: “Air Quality Maximum”
value_template: >
{% set values = [
states(‘sensor.air_pm_25’).state | int,
states(‘sensor.air_pm_10’).state | int,
states(‘sensor.air_co’).state | int,
states(‘sensor.air_no2’).state | int
] %}
{{ values | max }}
This configuration does the following:
- Collects the current state values of four air quality sensors.
- Converts them to integers to ensure proper comparison.
- Uses the
maxfilter to find the highest value. - Displays this maximum value as the state of the
air_maxsensor.
I also added a friendly name to make it more readable in the UI. Now, I can easily monitor the worst air quality condition in my home with a single glance. This setup has been working perfectly for me, providing real-time insights into my indoor air quality!
If you have similar sensors and want to track the maximum value, give this template sensor a try. It’s a simple yet effective way to consolidate data from multiple sources.