Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it compatible with WAQI. #35

Closed
Ndrinta opened this issue Nov 8, 2020 · 19 comments
Closed

Make it compatible with WAQI. #35

Ndrinta opened this issue Nov 8, 2020 · 19 comments

Comments

@Ndrinta
Copy link

Ndrinta commented Nov 8, 2020

Given the recent issues with the AirVisual API (#42776), I'd be nice to have a backup when stuff like this happen.
WAQI looks like the only alternative for home assistant right now.

Is this feasible?

@dnguyen800
Copy link
Owner

thanks for letting me know about WAQI. I'll see what sensors are available from this integration.

@Ndrinta
Copy link
Author

Ndrinta commented Nov 9, 2020

Super-quick fix if you don't want to wait.
These sensors make WAQI compatible with AirVisual Card.

# === Sensors
sensor:

    # World Air Quality Index (WAQI) - [https://www.home-assistant.io/integrations/waqi/]
  - platform: waqi
    token: !secret waqi_api_key
    locations:
      - Coventry # YOUR_LOCATION
    stations: 
      - "Coventry Allesley, United Kingdom" # STATION_OF_INTEREST_1
      - "Coventry Memorial Park, United Kingdom" # STATION_OF_INTEREST_2

    # Pollution Level (from WAQI)
  - platform: template
    sensors:
      waqi_air_pollution_level:
        friendly_name: WAQI Pollution Level
        value_template: >-
          {% set level = ((states('sensor.waqi_coventry_allesley_united_kingdom')|int + states('sensor.waqi_coventry_memorial_park_united_kingdom')|int) / 2 )|int %}
          {% if level <= 50 %}
            Good
          {% elif level <= 100 %}
            Moderate
          {% elif level <= 200 %}
            Unhealty
          {% elif level <= 300 %}
            Very Unhealty
          {% else %}
            Hazardous
          {% endif %}
        icon_template: >-
          {% set level = ((states('sensor.waqi_coventry_allesley_united_kingdom')|int + states('sensor.waqi_coventry_memorial_park_united_kingdom')|int) / 2 )|int %}
          {% if level <= 50 %}
            mdi:emoticon-excited
          {% elif level <= 100 %}
            mdi:emoticon-happy
          {% elif level <= 150 %}
            mdi:emoticon-neutral
          {% elif level <= 200 %}
            mdi:emoticon-sad
          {% elif level <= 300 %}
            mdi:emoticon-dead
          {% else %}
            mdi:biohazard
          {% endif %}
#        attribute_templates:
#          latitude:  >-
#            {{ state_attr('sensor.u_s_air_pollution_level','latitude') }}
#          longitude:  >-
#            {{ state_attr('sensor.u_s_air_pollution_level','longitude') }}

    # Quality Index (from WAQI)
  - platform: template
    sensors:
      waqi_air_quality_index:
        friendly_name: WAQI Quality Index
        value_template: >-
          {{ ((states('sensor.waqi_coventry_allesley_united_kingdom')|int + states('sensor.waqi_coventry_memorial_park_united_kingdom')|int) / 2 )|int}}
        unit_of_measurement: 'AQI'
          
    # Main Pollutant (from WAQI)
  - platform: template
    sensors:
      waqi_main_pollutant:
        friendly_name: WAQI Main Pollutant
        value_template: >-
          {% set main_pollutant = state_attr('sensor.waqi_coventry_allesley_united_kingdom','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            PM2.5
          {% elif main_pollutant == "pm10" %}
            PM10
          {% elif main_pollutant == "o3" %}
            Ozone
          {% elif main_pollutant == "no2" %}
            Nitrogen Dioxide
          {% elif main_pollutant == "so2" %}
            Sulfur Dioxide
          {% else %}
            Unknown
          {% endif %}
        attribute_templates:
          pollutant_unit: >-
            {% set main_pollutant = state_attr('sensor.waqi_coventry_allesley_united_kingdom','dominentpol') %}
            {% if main_pollutant == "pm25" %}
              µg/m³
            {% elif main_pollutant == "pm10" %}
              µg/m³
            {% elif main_pollutant == "o3" %}
              ppb
            {% elif main_pollutant == "no2" %}
              ppb
            {% elif main_pollutant == "so2" %}
              ppb
            {% else %}
              Unknown
            {% endif %}

    # Outside Temperature (from WAQI)
  - platform: template
    sensors:
      waqi_temperature:
        friendly_name: WAQI Temperature
        unit_of_measurement: '°C'
        value_template: >-
          {{ state_attr('sensor.waqi_coventry_allesley_united_kingdom','temperature') }}
        device_class: temperature

This is a bodge; there are surely shortcuts and errors but for the moment it works on my config, so I am happy with this. I did my best; I am sure that my code will be gross to watch for some of the experienced chaps in here and I am open to suggestions!

I left my Location and Stations of interest in, so for you to quickly try the config with a working configuration; change it accordingly to your location.
I decided to select those 2 stations because (in my specific case) the integration populates a 3rd sensor which is not of interest (somewhere in US I think), and I thought it was a waste of resources.
I chose to make the average of the 2 sensors (for a try) but to take in consideration only the closest station for the main pollutant.

In the declaration of sensor.waqi_air_pollution_level, the attributes latitude and longitude are commented out. This because I found out these are not strictly necessary for the functionality of AirVisual Card.

@dnguyen800
Copy link
Owner

Thanks. I started implementing it but ran into some issues. I'm pretty slow so it's good you wrote a template sensor instead. Thanks for figuring out the values for main pollutant, I will add that to the code.

@Ndrinta
Copy link
Author

Ndrinta commented Nov 13, 2020

I'll leave this with you. Shout if you need any help, closing this now. Cheers

@Ndrinta Ndrinta closed this as completed Nov 13, 2020
@dnguyen800 dnguyen800 reopened this Nov 13, 2020
@dnguyen800
Copy link
Owner

Hey @Ndrinta , I'm almost done adding WAQI support, but wanted your help on calculating this value (see red circle)

image

Do you know how this value is calculated? Is it possible to calculate with the data from the WAQI sensors?

@dnguyen800
Copy link
Owner

I've added in WAQI support, but I'm not going to publish a new release due to insufficient testing. It technically works, and if Airvisual has problems again, I'll probably pick this up again.

You can put the .js file in your /www/community/air-visual-card directory
https://github.com/dnguyen800/air-visual-card/blob/master/dist/air-visual-card.js

@Ndrinta
Copy link
Author

Ndrinta commented Nov 15, 2020

Amazing, thanks!
I'll give it a go early next week and let you know if anything odd.

Do you know how this value is calculated? Is it possible to calculate with the data from the WAQI sensors?

As far as I know, the AQI is "calculated" in this way:
Raw concentration (pollutant) = Reference value (pollutant) * AQI }(pollutant) / 50
The main pollutant raw value isn't provided by the AirVisual integration but it's available with the WAQI integration instead. And not only the main one, but all (super cool). (Note: The value for 'Sulfur' is missing from WAQI)

image

Also, if I can say, the way in which IQAir derives the Air Quality Index (AQI) is a bit of a mystery:

The index formula usually considers up to 6 main pollutants (PM2.5, PM10, carbon monoxide, sulfur dioxide, nitrogen dioxide and ground level ozone), and calculates the respective health risk (or AQI number) for each one at any given time. The overall AQI number at a given moment is dictated by the "riskiest" pollutant, with the highest AQI number.

While WAQI is pretty simple and open (US EPA standard).
Sweet article you might be interdireste in (https://aqicn.org/faq/2015-07-16/air-quality-scale-in-quebec-and-montreal/faq/2015-03-20/a-comparison-of-worldwide-air-quality-scales-part-1/faq/2015-03-20/a-comparison-of-worldwide-air-quality-scales-part-1/), check the bottom of the page (Note: This article is part of a series on Worlwide Air Quality scales.), more in there. Furthermore, IQAir use data not only from certified stations but also from their (indoor) AirVisual Pro sensors they sell all around the world. I'm not sure how that impacts the data but I would't trust data coming from end users (never ever, ahah).

@jokerigno
Copy link

Hi all,

I've setup a air visual card using WAQI from a year or so.

I worked great but starting from few days values are always shown in english even if my template sensor use my native language:

CARD:

air_pollution_level: sensor.aqicn
air_quality_index: sensor.waqi_rebaudengo_torino_piemonte_italy 
main_pollutant: sensor.dominentpol
hide_face: true
type: 'custom:air-visual-card'

SENSOR

  - platform: waqi
    token: xxxxxxxxxxxxxxxxxxxxxxxxx
    locations:
      - Rebaudengo, Torino, Piemonte
        
  - platform: template
    sensors:  
      aqicn:
        friendly_name: "Qualità dell'aria a Torino" 
        value_template: >-
          {% if states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 50 %}
          Buona
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 100%}
          Moderata
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 150%}
          Insalubre per alcuni
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 200 %}
          Insalubre
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 300 %}
          Molto insalubre
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int >= 300 %}
          Pericolosa
          {% endif %}
        icon_template: >-
          {% if states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 50 %}
            mdi:emoticon-excited
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 100%}
            mdi:emoticon-happy
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 150%}
            mdi:emoticon-neutral
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 200 %}
            mdi:emoticon-sad
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int <= 300 %}
            mdi:emoticon-dead
          {% elif states('sensor.waqi_rebaudengo_torino_piemonte_italy')|int >= 300 %}
            mdi:biohazard
          {% endif %}


  - platform: template
    sensors:
      dominentpol:
        friendly_name: Inquinante principale
        value_template: >-
          {% set main_pollutant = state_attr('sensor.waqi_rebaudengo_torino_piemonte_italy','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            PM2.5
          {% elif main_pollutant == "pm10" %}
            PM10
          {% elif main_pollutant == "o3" %}
            Ozono
          {% elif main_pollutant == "no2" %}
            Diossido di azoto
          {% elif main_pollutant == "so2" %}
            Anidride solforosa
          {% else %}
            Sconosciuto
          {% endif %}
        attribute_templates:
          pollutant_unit: >-
            {% set main_pollutant = state_attr('sensor.waqi_rebaudengo_torino_piemonte_italy','dominentpol') %}
            {% if main_pollutant == "pm25" %}
              µg/m³
            {% elif main_pollutant == "pm10" %}
              µg/m³
            {% elif main_pollutant == "o3" %}
              ppb
            {% elif main_pollutant == "no2" %}
              ppb
            {% elif main_pollutant == "so2" %}
              ppb
            {% else %}
              Sconosciuto
            {% endif %}

Has something changed?

@walkercz
Copy link

walkercz commented Oct 26, 2021

Hello trying the same thing

I get AQI value, face, and main pollutant unit right

but I miss air quality "text value", main pollutant and main pollutant value

any help appreciated

image

- type: custom:air-visual-card
        hide_weather: 1
        hide_title: 1
        hide_face: 0
        air_quality_index: sensor.waqi_prerov_olomoucky_czech_republic
        air_pollution_level: sensor.waqi_pollution_level_prerov
        main_pollutant: sensor.waqi_main_pollutant_prerov
        country: Prerov

 - platform: template
    sensors:  
      waqi_pollution_level_prerov:
        friendly_name: WAQI Pollution Level Prerov
        value_template: >-
          {% if states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 50 %}
            Good
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 100%}
            Moderate
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 150%}
            Unhealty
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 200 %}
            Unhealty
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 300 %}
            Very Unhealty
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int >= 300 %}
            Hazardous
          {% endif %}
        icon_template: >-
          {% if states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 50 %}
            mdi:emoticon-excited
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 100%}
            mdi:emoticon-happy
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 150%}
            mdi:emoticon-neutral
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 200 %}
            mdi:emoticon-sad
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int <= 300 %}
            mdi:emoticon-dead
          {% elif states('sensor.waqi_prerov_olomoucky_czech_republic')|int >= 300 %}
            mdi:biohazard
          {% endif %}


  - platform: template
    sensors:
      waqi_main_pollutant_prerov:
        friendly_name: WAQI Main Pollutant
        value_template: >-
          {% set main_pollutant = state_attr('sensor.waqi_prerov_olomoucky_czech_republic','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            PM 2,5 {{ state_attr('sensor.waqi_prerov_olomoucky_czech_republic','pm_2_5') }}
          {% elif main_pollutant == "pm10" %}
            PM 10 {{ state_attr('sensor.waqi_prerov_olomoucky_czech_republic','pm_10') }}
          {% elif main_pollutant == "o3" %}
            O3 {{ state_attr('sensor.waqi_prerov_olomoucky_czech_republic','ozone') }}
          {% elif main_pollutant == "no2" %}
            NO2 {{ state_attr('sensor.waqi_prerov_olomoucky_czech_republic','nitrogen_dioxide') }}
          {% elif main_pollutant == "so2" %}
            SO2 {{ state_attr('sensor.waqi_prerov_olomoucky_czech_republic','sulfur_dioxide') }}
          {% else %}
            Unknown
          {% endif %}
        attribute_templates:
          pollutant_unit: >-
            {% set main_pollutant = state_attr('sensor.waqi_prerov_olomoucky_czech_republic','dominentpol') %}
            {% if main_pollutant == "pm25" %}
              µg/m³
            {% elif main_pollutant == "pm10" %}
              µg/m³
            {% elif main_pollutant == "o3" %}
              ppb
            {% elif main_pollutant == "no2" %}
              ppb
            {% elif main_pollutant == "so2" %}
              ppb
            {% else %}
              Unknown
            {% endif %}

@Swampen
Copy link
Contributor

Swampen commented Oct 27, 2021

@walkercz Do you see any errors in the developer console in your browser (F12) when the card is rendered?

@walkercz
Copy link

walkercz commented Oct 27, 2021

OK SORRY GUYS - I realize that I just need to use default waqi value.. 🤦‍♂️

cards:
      - type: custom:air-visual-card
        hide_weather: 1
        hide_title: 1
        hide_face: 0
        air_quality_index: sensor.waqi_prerov_olomoucky_czech_republic
        air_pollution_level: sensor.waqi_prerov_olomoucky_czech_republic
        main_pollutant: sensor.waqi_prerov_olomoucky_czech_republic
        country: Prerov

image


Do not get me wrong .. the output of the custom sensors is accurate, but the output is displayed only partially in the card itself

maybe the card expect different input?

image
image

i see no error in chrome dev console regarding the card
image

image

@Swampen
Copy link
Contributor

Swampen commented Oct 28, 2021

Could you try to set your template to match these sensors sensors.en.json?
After changing to localized values, the sensors must match exactly one of these to be able to translate it.

@Swampen
Copy link
Contributor

Swampen commented Oct 28, 2021

I got it working with this config:
image

cards:
  - type: custom:air-visual-card
    weather: weather.home
    hide_weather: true
    hide_title: 1
    hide_face: 0
    air_quality_index: sensor.waqi_hjortnes_oslo_norway
    air_pollution_level: sensor.waqi_pollution_level_oslo
    main_pollutant: sensor.waqi_main_pollutant_oslo

sensor:
  - platform: template
    sensors:  
      waqi_pollution_level_oslo:
        friendly_name: WAQI Pollution Level Oslo
        value_template: >-
          {% if states('sensor.waqi_hjortnes_oslo_norway')|int <= 50 %}
            good
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 100%}
            moderate
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 150%}
            unhealthy_sensitive
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 200 %}
            unhealthy
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 300 %}
            very_unhealthy
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int >= 300 %}
            hazardous
          {% endif %}
        icon_template: >-
          {% if states('sensor.waqi_hjortnes_oslo_norway')|int <= 50 %}
            mdi:emoticon-excited
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 100%}
            mdi:emoticon-happy
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 150%}
            mdi:emoticon-neutral
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 200 %}
            mdi:emoticon-sad
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int <= 300 %}
            mdi:emoticon-dead
          {% elif states('sensor.waqi_hjortnes_oslo_norway')|int >= 300 %}
            mdi:biohazard
          {% endif %}


  - platform: template
    sensors:
      waqi_main_pollutant_oslo:
        friendly_name: WAQI Main Pollutant Oslo
        value_template: >-
          {% set main_pollutant = state_attr('sensor.waqi_hjortnes_oslo_norway','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            p2
          {% elif main_pollutant == "pm10" %}
            p1
          {% elif main_pollutant == "co" %}
            co
          {% elif main_pollutant == "o3" %}
            o3
          {% elif main_pollutant == "no2" %}
            n2
          {% elif main_pollutant == "so2" %}
            s2
          {% else %}
            Unknown
          {% endif %}
        attribute_templates:
          pollutant_unit: >-
            {% set main_pollutant = state_attr('sensor.waqi_hjortnes_oslo_norway','dominentpol') %}
            {% if main_pollutant == "pm25" %}
              µg/m³
            {% elif main_pollutant == "pm10" %}
              µg/m³
            {% elif main_pollutant == "co" %}
              ppm
            {% elif main_pollutant == "o3" %}
              ppb
            {% elif main_pollutant == "no2" %}
              ppb
            {% elif main_pollutant == "so2" %}
              ppb
            {% else %}
              Unknown
            {% endif %}

@ranrinc
Copy link

ranrinc commented Jun 22, 2022

Need help on AirVisual since I try to follow everyone's guide here.

However, it seems to not be able to show its value_template

Any help?

The View which missing PM2.5 value and Status
Screen Shot 2022-06-22 at 9 28 28 AM

The value from both sensor is working fine
Screen Shot 2022-06-22 at 9 29 12 AM

MySetup

- type: custom:air-visual-card
  air_pollution_level: sensor.waqi_pollution_level_jakarta
  air_quality_index: sensor.waqi_jakarta_indonesia
  main_pollutant: sensor.waqi_main_pollutant_jakarta
  weather: weather.home
  hide_weather: 1
  hide_title: 1
  hide_face: 0

- platform: template
  sensors:  
    waqi_pollution_level_jakarta:
      friendly_name: WAQI Pollution Level Jakarta
      value_template: >-
        {% if states('sensor.waqi_jakarta_indonesia')|int <= 50 %}
          good
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 100%}
          moderate
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 150%}
          unhealthy_sensitive
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 200 %}
          unhealthy
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 300 %}
          very_unhealthy
        {% elif states('sensor.waqi_jakarta_indonesia')|int >= 300 %}
          hazardous
        {% endif %}
      icon_template: >-
        {% if states('sensor.waqi_jakarta_indonesia')|int <= 50 %}
          mdi:emoticon-excited
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 100%}
          mdi:emoticon-happy
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 150%}
          mdi:emoticon-neutral
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 200 %}
          mdi:emoticon-sad
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 300 %}
          mdi:emoticon-dead
        {% elif states('sensor.waqi_jakarta_indonesia')|int >= 300 %}
          mdi:biohazard
        {% endif %}

- platform: template
  sensors:
    waqi_main_pollutant_jakarta:
      friendly_name: WAQI Main Pollutant Jakarta
      value_template: >-
        {% set main_pollutant = state_attr('sensor.waqi_jakarta_indonesia','dominentpol') %}
        {% if main_pollutant == "pm25" %}
          p2
        {% elif main_pollutant == "pm10" %}
          p1
        {% elif main_pollutant == "co" %}
          co
        {% elif main_pollutant == "o3" %}
          o3
        {% elif main_pollutant == "no2" %}
          n2
        {% elif main_pollutant == "so2" %}
          s2
        {% else %}
          Unknown
        {% endif %}
      attribute_templates:
        pollutant_unit: >-
          {% set main_pollutant = state_attr('sensor.waqi_jakarta_indonesia','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            µg/m³
          {% elif main_pollutant == "pm10" %}
            µg/m³
          {% elif main_pollutant == "co" %}
            ppm
          {% elif main_pollutant == "o3" %}
            ppb
          {% elif main_pollutant == "no2" %}
            ppb
          {% elif main_pollutant == "so2" %}
            ppb
          {% else %}
            Unknown
          {% endif %}

@jukkaphat
Copy link

Need help on AirVisual since I try to follow everyone's guide here.

However, it seems to not be able to show its value_template

Any help?

The View which missing PM2.5 value and Status Screen Shot 2022-06-22 at 9 28 28 AM

The value from both sensor is working fine Screen Shot 2022-06-22 at 9 29 12 AM

MySetup

- type: custom:air-visual-card
  air_pollution_level: sensor.waqi_pollution_level_jakarta
  air_quality_index: sensor.waqi_jakarta_indonesia
  main_pollutant: sensor.waqi_main_pollutant_jakarta
  weather: weather.home
  hide_weather: 1
  hide_title: 1
  hide_face: 0

- platform: template
  sensors:  
    waqi_pollution_level_jakarta:
      friendly_name: WAQI Pollution Level Jakarta
      value_template: >-
        {% if states('sensor.waqi_jakarta_indonesia')|int <= 50 %}
          good
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 100%}
          moderate
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 150%}
          unhealthy_sensitive
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 200 %}
          unhealthy
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 300 %}
          very_unhealthy
        {% elif states('sensor.waqi_jakarta_indonesia')|int >= 300 %}
          hazardous
        {% endif %}
      icon_template: >-
        {% if states('sensor.waqi_jakarta_indonesia')|int <= 50 %}
          mdi:emoticon-excited
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 100%}
          mdi:emoticon-happy
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 150%}
          mdi:emoticon-neutral
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 200 %}
          mdi:emoticon-sad
        {% elif states('sensor.waqi_jakarta_indonesia')|int <= 300 %}
          mdi:emoticon-dead
        {% elif states('sensor.waqi_jakarta_indonesia')|int >= 300 %}
          mdi:biohazard
        {% endif %}

- platform: template
  sensors:
    waqi_main_pollutant_jakarta:
      friendly_name: WAQI Main Pollutant Jakarta
      value_template: >-
        {% set main_pollutant = state_attr('sensor.waqi_jakarta_indonesia','dominentpol') %}
        {% if main_pollutant == "pm25" %}
          p2
        {% elif main_pollutant == "pm10" %}
          p1
        {% elif main_pollutant == "co" %}
          co
        {% elif main_pollutant == "o3" %}
          o3
        {% elif main_pollutant == "no2" %}
          n2
        {% elif main_pollutant == "so2" %}
          s2
        {% else %}
          Unknown
        {% endif %}
      attribute_templates:
        pollutant_unit: >-
          {% set main_pollutant = state_attr('sensor.waqi_jakarta_indonesia','dominentpol') %}
          {% if main_pollutant == "pm25" %}
            µg/m³
          {% elif main_pollutant == "pm10" %}
            µg/m³
          {% elif main_pollutant == "co" %}
            ppm
          {% elif main_pollutant == "o3" %}
            ppb
          {% elif main_pollutant == "no2" %}
            ppb
          {% elif main_pollutant == "so2" %}
            ppb
          {% else %}
            Unknown
          {% endif %}

I having the same problem here.

@ngseer
Copy link

ngseer commented Jul 9, 2022

Hi guys. I've made a little tweak to show main pollutant value when using WAQI sensor (it still doesn't work for AirVisual tho). Can't tell if I did it 100% right (this is my first time tinkering with Lovelace cards tbh) but you all are very welcome to take a look at the code.

image

@fcastilloec
Copy link

I'm using only WAQI and I have the same problem. Only AQI is shown and nothing else, no text, no pollutant.

@jurgenweber
Copy link

jurgenweber commented Oct 13, 2022

@ngseer even using your repo; I still get:

image

Is this still working for people?

@c0bra99
Copy link

c0bra99 commented Oct 17, 2022

AirVisual suddenly stopped working for my city for some reason (returns city_not_found) so I switched to the WAQI integration. I was pleasantly surprised that this air-visual-card worked just fine with no extra sensors or modifications required, I just put the same waqi sensor for all 3 air quality entities.

image

@Ndrinta Ndrinta closed this as completed Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests