Open utterances-bot opened 1 year ago
Thanks! How are you able to separate the Outdoor and Indoor AQI measurements?
The outdoor AQI comes from a separate integration, like AirNow.
If you're asking about how to visually separate them on the dashboard, you can use a Horizontal Stack card with two gauges.
I mean, I've got 2 sensors (indoor and outdoor). I can get 1 working but when I try to put 2 and modify the code (entity_id) it doesn't work.
This is what I have in my configuration.yaml file.
sensor:
- platform: statistics
unique_id: pm25_24hr_avg
name: "Outdoor PM2.5 24-hour Average"
entity_id: sensor.particulate_matter_2_5um_concentration
state_characteristic: mean
sampling_size: 15000
max_age:
hours: 24
- platform: statistics
unique_id: pm25_24hr_avg
name: "Indoor PM2.5 24-hour Average"
entity_id: sensor.wellbeing_pure_a9_mu_pm2_5
state_characteristic: mean
sampling_size: 15000
max_age:
hours: 24
template:
- sensor:
- name: "Outdoor AQI"
unique_id: outdoor_aqi
state_class: measurement
device_class: aqi
unit_of_measurement: AQI
state: >
{% macro aqi(val, val_l, val_h, aqi_l, aqi_h) -%}
{{(((aqi_h-aqi_l)/(val_h - val_l) * (val - val_l)) + aqi_l)|round(0)}}
{%- endmacro %}
{% set v = states('sensor.pm2_5_24_hour_average')|round(1) %}
{% if v <= 12.0 %}
{{aqi(v, 0, 12.0, 0, 50)}}
{% elif 12.0 < v <= 35.4 %}
{{aqi(v, 12.1, 35.4, 51, 100)}}
{% elif 35.4 < v <= 55.4 %}
{{aqi(v, 35.5, 55.4, 101, 150)}}
{% elif 55.4 < v <= 150.5 %}
{{aqi(v, 55.5, 150.4, 151, 200)}}
{% elif 150.4 < v <= 250.4 %}
{{aqi(v, 150.4, 250.4, 201, 300)}}
{% elif 250.5 < v <= 500.4 %}
{{aqi(v, 250.5, 500.4, 301, 500)}}
{% else %}
500
{% endif %}
- name: "Indoor AQI"
unique_id: indoor_aqi
state_class: measurement
device_class: aqi
unit_of_measurement: AQI
state: >
{% macro aqi(val, val_l, val_h, aqi_l, aqi_h) -%}
{{(((aqi_h-aqi_l)/(val_h - val_l) * (val - val_l)) + aqi_l)|round(0)}}
{%- endmacro %}
{% set v = states('sensor.pm2_5_24_hour_average')|round(1) %}
{% if v <= 12.0 %}
{{aqi(v, 0, 12.0, 0, 50)}}
{% elif 12.0 < v <= 35.4 %}
{{aqi(v, 12.1, 35.4, 51, 100)}}
{% elif 35.4 < v <= 55.4 %}
{{aqi(v, 35.5, 55.4, 101, 150)}}
{% elif 55.4 < v <= 150.5 %}
{{aqi(v, 55.5, 150.4, 151, 200)}}
{% elif 150.4 < v <= 250.4 %}
{{aqi(v, 150.4, 250.4, 201, 300)}}
{% elif 250.5 < v <= 500.4 %}
{{aqi(v, 250.5, 500.4, 301, 500)}}
{% else %}
500
{% endif %}
You need to change the unique_id
for one of the pm25_24hr_avg
statistics entities
Adding PM2.5-based Indoor AQI to Home Assistant
Add indoor AQI to your Home Assistant instance with an existing PM2.5 sensor.
https://blog.horner.tj/indoor-aqi-home-assistant/