0Air Quality in Home Assistant

I recently wrote about how to show bin col­lec­tion inform­a­tion in Home Assist­ant, and my next pro­ject was to pull some air qual­ity inform­a­tion. For­tu­nately I have a ‘Tado’ account which meant I could pull this inform­a­tion from their API using the fol­low­ing code


Much of the inform­a­tion for this was taken from a thread on the home assist­ant for­ums, but I was able to add pol­lu­tion as well as pol­len inform­a­tion, and I also had to tweak the code to resolve an issue with “none” being treated as “unknown” rather than as a string of text. Lots of cred­it to Drillbit on the for­ums though.

Tado account details

  • You will need some inform­a­tion for your Tado account
  • Vis­it https://my.tado.com/api/v2/me?username=you@emailaddress.tld&password=yourpassword
  • Near the top of the out­put you need the numer­ic ID that is lis­ted under homes: 0: id:
  • Next, go to https://www.latlong.net/ and loc­ate your home and make a note of the lat­it­ude and longitude
  • Next vis­it https://acme.tado.com/v1/homes/your-home-ID/airComfort?latitude=12.34&longitude=12.34&username=your@email&password=your-pass­word to make sure it loads

Code for home assistant

  • Add the fol­low­ing code to your configuration.yaml
    sensor:
     - platform: rest
       # API call to get air quality
       # Result goes into outdoorQuality attribute in JSON format
       name: TadoAir
       verify_ssl: true
       scan_interval: 1800
       resource: https://acme.tado.com/v1/homes/your-home-ID/airComfort?latitude=12.34&longitude=12.34&username=your@email&password=your-password
       headers:
         User-Agent: Home Assistant
         Content-Type: application/json
       method: GET
       json_attributes:
         - roomMessages
         - outdoorQuality
       value_template: 'Tado airComfort'
    
     # Enumerate JSON to populate various template sensors
     - platform: template
       sensors:
         air_quality:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["aqi"]["level"] | capitalize }}'
           friendly_name: "Air Quality"
           icon_template: mdi:air-filter
           unique_id: "air_quality"
    
         # Pollen sensors
         air_pollen_level:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["dominant"]["level"] | capitalize }}'
           friendly_name: "Pollen Level"
           icon_template: mdi:flower
           unique_id: "pollen_level"
    
         air_pollen_level_grass:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][0]["forecast"][0]["level"] | capitalize }}.'
           friendly_name: "Grass Pollen"
           icon_template: mdi:flower
           unique_id: "grass_pollen_level"
    
         air_pollen_level_grass_tomorrow:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][0]["forecast"][1]["level"] | capitalize  }}.'
           friendly_name: "Grass Pollen Tomo."
           icon_template: mdi:flower
           unique_id: "grass_pollen_level_tomorrow"
    
         air_pollen_level_weed:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][1]["forecast"][0]["level"] | capitalize  }}.'
           friendly_name: "Plant Pollen"
           icon_template: mdi:sprout
           unique_id: "plant_pollen_level"
    
         air_pollen_level_weed_tomorrow:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][1]["forecast"][1]["level"] | capitalize  }}.'
           friendly_name: "Plant Pollen Tomo."
           icon_template: mdi:sprout
           unique_id: "plant_pollen_level_tomorrow"
    
         air_pollen_level_tree:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][2]["forecast"][0]["level"] | capitalize  }}.'
           friendly_name: "Tree Pollen "
           icon_template: mdi:tree
           unique_id: "tree_pollen_level"
    
         air_pollen_level_tree_tomorrow:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollens"]["types"][2]["forecast"][1]["level"] | capitalize }}.'
           friendly_name: "Tree Pollen Tomo."
           icon_template: mdi:tree
           unique_id: "tree_pollen_level_tomorrow"
    
         air_pollution_level_pm10:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][0]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][0]["concentration"]["value"]}}μg/m³'
           friendly_name: "PM 10"
           icon_template: mdi:tree
           unique_id: "pollution_pm10"
    
         air_pollution_level_pm25:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][1]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][1]["concentration"]["value"]}}μg/m³'
           friendly_name: "PM 2.5"
           icon_template: mdi:tree
           unique_id: "pollution_pm25"
    
         air_pollution_level_ozone:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][2]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][2]["concentration"]["value"]}}ppb'
           friendly_name: "Ozone"
           icon_template: mdi:tree
           unique_id: "pollution_ozone"
    
         air_pollution_level_sulphur:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][3]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][3]["concentration"]["value"]}}ppb'
           friendly_name: "Sulphur Dioxide"
           icon_template: mdi:tree
           unique_id: "pollution_sulphur"
    
         air_pollution_level_carbon:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][4]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][4]["concentration"]["value"]}}ppb'
           friendly_name: "Carbon Monoxide"
           icon_template: mdi:tree
           unique_id: "pollution_carbon"
    
         air_pollution_level_nitrogen:
           value_template: '{{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][5]["level"] | capitalize }}: {{ states.sensor.tadoair.attributes["outdoorQuality"]["pollutants"][5]["concentration"]["value"]}}ppb'
           friendly_name: "Nitrogen Dioxide"
           icon_template: mdi:tree
           unique_id: "pollution_nitrogen"
    

Got some thoughts of your own? Indulge yourself below by commenting! If you would like to subscribe please use the subscribe link on the menu at the top right. You can also share this with your friends by using the social links below. Cheers.

Leave a Reply