naofireblade / homebridge-weather-plus

A comprehensive weather plugin for homebridge.
MIT License
316 stars 63 forks source link

[Feature request] Integrate Air Pollution API from OpenWeatherMap. #198

Open DoWenzl94 opened 3 years ago

DoWenzl94 commented 3 years ago

Hi, is there a possibility that you can integrate the Air Pollution API from OpenWeatherMap to get all this datas?


Air Pollution API concept Air Pollution API provides current, forecast and historical air pollution data for any coordinates on the globe

Besides basic Air Quality Index, the API returns data about polluting gases, such as Carbon monoxide (CO), Nitrogen monoxide (NO), Nitrogen dioxide (NO2), Ozone (O3), Sulphur dioxide (SO2), Ammonia (NH3), and particulates (PM2.5 and PM10).

Air pollution forecast is available for 5 days with hourly granularity. Historical data is accessible from 27th November 2020.

Current air pollution data API call

http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={API key}

purofy commented 3 years ago

*push

problemss commented 3 years ago

Would love to see this as well. For the original creator of this, may want to change the label to new feature.

problemss commented 3 years ago

Not sure if you found a solution, but I ended up using another Homebridge plugin called HTTP-Advanced-Accessory and created an Air Quality Sensor using the OpenWeatherMap apis. The PM2.5 isn't being created in the plugin, but everything else is working. I put my config down below, just replace with your lon, lat, and id. Lastly Carbon Monoxide and some of the other values are not listed in the apple sensor characteristics, but are in other sensors, if you wanted them.

{
    "accessory": "HttpAdvancedAccessory",
    "service": "AirQualitySensor",
    "name": "Air Quality",
    "debug": true,
    "forceRefreshDelay": 1800,
    "optionCharacteristic": [
        "NitrogenDioxideDensity",
        "OzoneDensity",
        "PM10Density",
        "PM2_5Density",
        "SulphurDioxideDensity"
    ],
    "urls": {
        "getAirQuality": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].main.aqi",
                        "index": 0
                    }
                }
            ]
        },
        "getNitrogenDioxideDensity": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].components.no2",
                        "index": 0
                    }
                }
            ]
        },
        "getOzoneDensity": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].components.o3",
                        "index": 0
                    }
                }
            ]
        },
        "getPM10Density": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].components.pm10",
                        "index": 0
                    }
                }
            ]
        },
        "getPM2_5Density": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].components.pm2_5",
                        "index": 0
                    }
                }
            ]
        },
        "getSulphurDioxideDensity": {
            "url": "http://api.openweathermap.org/data/2.5/air_pollution?lat={lat}&lon={lon}&appid={appid}",
            "httpMedthod": "",
            "body": "",
            "mappers": [
                {
                    "type": "jpath",
                    "parameters": {
                        "jpath": "$.list[0].components.so2",
                        "index": 0
                    }
                }
            ]
        }
    }
}