Air Quality Index (AQI) in your city
Home Assistant

Air Quality Index (AQI) in your city

Air Quality Index (AQI) in your city
A flow by Dmytro Sudakevych (megadimich)

Go to automations Download flow Download assets

Flow Details

  1. You need to create a sensor in the configuration.yaml file or add a link to a file containing an AQI sensor and a sensor to change the color of the message text. In my case, I added the following lines to the configuration.yaml:

homeassistant:
packages: !include_dir_merge_named includes/packages

Place the api_waqi_info_sensors.yaml file in the packages folder. At https://aqicn.org/data-platform/token/ you must create your token according to the instructions on that site. Then you should enter this token in the file api_waqi_info_sensors.yaml in resource_template instead of YOURS_TOKEN and instead of A195973 enter your city, for example kyiv or better Air quality monitoring station: A + station code - mine is A195973.

  1. Create your automation. I added my automation to the automations.yaml file. In this file, set your AWTRIX MQTT prefix in topic: instead of awtrix_565c3c.

  2. Do not forget to download the icon mentioned in the project.

If you have any questions, please contact me on Discord at megadimich.

1. File api_waqi_info_sensors.yaml: #https://aqicn.org/api api_waqi_info_sensors: sensor: - platform: rest name: api_waqi_info resource_template: "https://api.waqi.info/feed/A195973/?token=YOURS_TOKEN" method: GET headers: content-type: 'application/json' value_template: "{{ value_json.data.iaqi.pm25.v }}" json_attributes: - "data" scan_interval: 600 # 10 Minutes - platform: template sensors: api_waqi_color_text: friendly_name: "api_waqi_color_text" value_template: > {% if ((states('sensor.api_waqi_info') | int) >= 0) and ((states('sensor.api_waqi_info') | int) <= 50) %}#009966 {% elif ((states('sensor.api_waqi_info') | int) >= 51) and ((states('sensor.api_waqi_info') | int) <= 100) %}#ffde33 {% elif ((states('sensor.api_waqi_info') | int) >= 101) and ((states('sensor.api_waqi_info') | int) <= 150) %}#ff9933 {% elif ((states('sensor.api_waqi_info') | int) >= 151) and ((states('sensor.api_waqi_info') | int) <= 200) %}#cc0033 {% elif ((states('sensor.api_waqi_info') | int) >= 201) and ((states('sensor.api_waqi_info') | int) <= 300) %}#660099 {% elif ((states('sensor.api_waqi_info') | int) > 300) %}#7e0023 {% else %}#ffffff {% endif %} 2. File automations.yaml: - id: '1703280435999' alias: AWTRIX Aqi description: '' trigger: - platform: time_pattern minutes: /2 condition: [] action: - service: mqtt.publish data: qos: '0' retain: false topic: awtrix_565c3c/custom/airquality payload: '{ "text": "pm:{{ states(''sensor.api_waqi_info'') }}", "color": "{{ states(''sensor.api_waqi_color_text'') }}", "textCase": 2, "icon": "56366", "repeat": 2, "duration": 5 }' mode: single
/flows/PjqGAXrjOYNK/56366.gif
-- Flow first published on January 24, 2024, last updated on January 24, 2024 at 14:37.