├── hacs.json
├── images
├── example.PNG
├── add-card.png
├── card-editor.png
└── airvisual_sensors.JPG
├── dist
├── ic-wind.svg
├── ic-humidity.svg
├── ic-w-scattered-clouds.svg
├── ic-w-rain.svg
├── ic-w-clear-sky.svg
├── ic-w-night-clear-sky.svg
├── ic-w-new-clouds.svg
├── ic-w-snow.svg
├── ic-face-2.svg
├── ic-face-4.svg
├── ic-face-1.svg
├── ic-face-3.svg
├── ic-face-6.svg
├── ic-face-5.svg
├── air-visual-card-editor.js
└── air-visual-card.js
├── info.md
├── LICENSE
└── README.md
/hacs.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Air Visual Card"
3 | }
4 |
--------------------------------------------------------------------------------
/images/example.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnguyen800/air-visual-card/HEAD/images/example.PNG
--------------------------------------------------------------------------------
/images/add-card.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnguyen800/air-visual-card/HEAD/images/add-card.png
--------------------------------------------------------------------------------
/images/card-editor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnguyen800/air-visual-card/HEAD/images/card-editor.png
--------------------------------------------------------------------------------
/images/airvisual_sensors.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dnguyen800/air-visual-card/HEAD/images/airvisual_sensors.JPG
--------------------------------------------------------------------------------
/dist/ic-wind.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-humidity.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-w-scattered-clouds.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/info.md:
--------------------------------------------------------------------------------
1 | # Air Visual Card
2 |
3 | 
4 |
5 | This is a Home Assistant Lovelace card that uses the [AirVisual Sensor](https://www.home-assistant.io/components/sensor.airvisual/) to provide air quality index (AQI) data and creates a card like the ones found on [AirVisual website](https://www.airvisual.com). Requires the [AirVisual Sensor](https://www.home-assistant.io/components/sensor.airvisual/) to be setup. Tested with Yahoo and Darksky Weather component.
6 |
7 | ## Features
8 | - Card color and icons change depending on AQI level
9 | - Icons can be locally hosted or defaults to jsdelivr.net
10 |
--------------------------------------------------------------------------------
/dist/ic-w-rain.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-w-clear-sky.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-w-night-clear-sky.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dan Nguyen
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/dist/ic-w-new-clouds.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-w-snow.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-2.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-4.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-1.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-3.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-6.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/dist/ic-face-5.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Air Visual Card
2 |
3 | 
4 |
5 | This is a Home Assistant Lovelace card that uses the [AirVisual component](https://www.home-assistant.io/integrations/airvisual/) or [World Air Quality Index (WAQI) component](https://www.home-assistant.io/integrations/waqi/) to provide air quality index (AQI) data and creates a card like the ones found on [AirVisual website](https://www.airvisual.com). Requires the [AirVisual component](https://www.home-assistant.io/integrations/airvisual/) or [World Air Quality Index (WAQI) component](https://www.home-assistant.io/integrations/waqi/). Tested with Yahoo and Darksky Weather component.
6 |
7 | ## Features
8 | - Card colors and icons change depending on AQI level
9 |
10 |
11 | ## Options
12 |
13 | ### Main Options
14 |
15 | | Name | Type | Default | Supported options | Description |
16 | | --------------------- | ------- | ---------------------------- | -------------------------------- | ------------------------------------------------------------ |
17 | | `type` | string | **Required** | `custom:air-visual-card` | Type of the card |
18 | | `air_pollution_level` | string | **Required** | `sensor.u_s_air_pollution_level` | Name of the Air Pollution Level sensor. |
19 | | `air_quality_index` | string | optional | `sensor.u_s_air_quality_index` | Name of the Air Quality Index sensor. If sensor does not exist, do not add this config value. |
20 | | `main_pollutant` | string | optional | `sensor.u_s_main_pollutant` | Name of the Main Pollutant sensor. If sensor does not exist, do not add this config value. |
21 | | `weather` | string | optional | `weather.dark_sky` | Name of the weather entity if you wish to display temperature, humidity and wind information on the card. |
22 | | `country` | string | `US` | `mdi:air-conditioner` | Name of the country that Airvisual is collecting AQI data from. |
23 | | `city` | string | optional | `San Francisco` | Name of the city that AirVisual is collecting AQI data from. |
24 | | `unit_of_measurement` | string | optional | `AQI` | Unit of measurement |
25 | | `icons` | string | `/hacsfiles/air-visual-card` | `/hacsfiles/air-visual-card` | The local directory where the .svg files are located. For example, 'icons: "/hacsfiles/air-visual-card"' is appropriate if this plugin is installed using HACS. If left blank, icons will be loaded from default location. |
26 | | `hide_title` | boolean | `true` | `true` | `false` | Set to `true` if you want to hide the title that includes the city name. Useful for minimalists or those using dark themes. |
27 | | `hide_face` | boolean | `false` | `true` | `false` | Set to `true` if you want to hide the face icon. |
28 | | `hide_weather` | boolean | `true` | `true` | `false` | Set to `false` if you want to show the weather information from the weather entity. |
29 |
30 |
31 |
32 | ## HACS Installation
33 | 1. Open the HACS on your Home Assistant instance.
34 | 2. Open the Plugins section and click on the Air Visual Card.
35 | 3. Click on Install, then click on "Add to Lovelace"
36 |
37 | ## Manual Installation
38 | 1. Download the [AirVisual Card](https://raw.githubusercontent.com/dnguyen800/air-visual-card/master/dist/air-visual-card.js)
39 | 2. Place the file in your `config/www` folder
40 | 3. Include the card code in the Resources section of your `ui-lovelace-card.yaml` like below:
41 |
42 | ```yaml
43 | resources:
44 | - url: /local/air-visual-card/air-visual-card.js
45 | type: js
46 | ```
47 | 4. **Optional:** If you wish to store the Airvisual icons locally, then download the icons [here](https://github.com/dnguyen800/air-visual-card/tree/master/dist).
48 |
49 | 5. Save the icons in a directory in Home Assistant, such as `/local/air-visual-card`
50 |
51 | 6. Update the card configuration in `ui-lovelace.yaml` to include the following (use directory name in step #7):
52 |
53 | ```yaml
54 | icons: "/local/air-visual-card"
55 | ```
56 |
57 | ## Instructions
58 | 1. Install the [AirVisual sensor](https://www.home-assistant.io/components/sensor.airvisual/) and confirm AQI, APL, and Main Pollutant sensors are created, like below.
59 |
60 | 
61 |
62 | 2. Add a card in the Lovelace UI.
63 | 3. Search for `air-visual-card` and click the search result. 
64 | 4. Fill out the card editor. 
65 |
66 |
67 |
68 |
69 | ## FAQ
70 | - The card doesn't show the temperature properly.
71 |
72 | Let me know which weather provider you are using and I'll try to fix the issue. I have only tested with the Yahoo! Weather component. Optionally, if you create a template sensor that reports the temperature as its state, you can use that sensor as for the temp config.
73 |
74 | - This card doesn't work in Fully Kiosk Browser on Amazon Fire tablets. Why?
75 |
76 | This card uses a new CSS function, CSS Grid Layout, which was implemented in October 2018, and isn't compatible with browsers using old versions of Android WebView. That's my guess anyways.
77 |
78 | - The card is showing the word 'unavailable' instead of the AQI data!
79 |
80 | Most likely your Airvisual key expired (it has a one-year expiration) and needs to be recreated. Delete and recreate a new key on airvisual.com and save the key in your HA config file.
81 |
82 | ## Support
83 | I am studying programming as a hobby and this is my first set of Home Assistant projects. Unfortunately, I know nothing about Javascript and relied on studying other Lovelace custom cards to write this. Suggestions are welcome but no promises if I can fix anything! If you're familiar with CSS, then you can edit the CSS style in the .js file directly.
84 |
85 | ## Credits
86 | - All the custom HA cards and components I studied from, including [@Arsaboo's Animated Weather card](https://github.com/arsaboo/homeassistant-config/blob/master/www/custom_ui/weather-card.js) and [Mini Media Player](https://github.com/kalkih/mini-media-player)
87 | - [airvisual.com](https://www.airvisual.com/) - For the card design and data
88 | - [Home Assistant Air Visual sensor](https://www.home-assistant.io/components/sensor.airvisual/)
89 | - [Weather Card](https://github.com/bramkragten/weather-card) by @bramkragten - for the visual card editor
90 |
91 |
--------------------------------------------------------------------------------
/dist/air-visual-card-editor.js:
--------------------------------------------------------------------------------
1 | // I Used weather-card-editor.js from Weather Card as template
2 | // https://github.com/bramkragten/weather-card
3 | // 2023-02-25 card editor is likely broken as it doesn't show entities,
4 |
5 | const fireEvent = (node, type, detail, options) => {
6 | options = options || {};
7 | detail = detail === null || detail === undefined ? {} : detail;
8 | const event = new Event(type, {
9 | bubbles: options.bubbles === undefined ? true : options.bubbles,
10 | cancelable: Boolean(options.cancelable),
11 | composed: options.composed === undefined ? true : options.composed,
12 | });
13 | event.detail = detail;
14 | node.dispatchEvent(event);
15 | return event;
16 | };
17 |
18 | if (
19 | !customElements.get("ha-switch") &&
20 | customElements.get("paper-toggle-button")
21 | ) {
22 | customElements.define("ha-switch", customElements.get("paper-toggle-button"));
23 | }
24 |
25 | const LitElement = customElements.get("hui-masonry-view") ? Object.getPrototypeOf(customElements.get("hui-masonry-view")) : Object.getPrototypeOf(customElements.get("hui-view"));
26 | const html = LitElement.prototype.html;
27 | const css = LitElement.prototype.css;
28 |
29 | const HELPERS = window.loadCardHelpers();
30 |
31 | export class AirVisualCardEditor extends LitElement {
32 | setConfig(config) {
33 | this._config = { ...config };
34 | }
35 |
36 | static get properties() {
37 | return { hass: {}, _config: {} };
38 | }
39 |
40 | get _air_pollution_level() {
41 | return this._config.air_pollution_level || "sensor.u_s_air_pollution_level";
42 | }
43 |
44 | get _air_quality_index() {
45 | return this._config.air_quality_index || "sensor.u_s_air_quality_index";
46 | }
47 |
48 | get _main_pollutant() {
49 | return this._config.main_pollutant || "sensor.u_s_main_pollutant";
50 | }
51 |
52 | get _country() {
53 | return this._config.country || "";
54 | }
55 |
56 | get _city() {
57 | return this._config.city || "";
58 | }
59 |
60 | get _icons() {
61 | return this._config.icons || "/hacsfiles/air-visual-card";
62 | }
63 |
64 | get _weather() {
65 | return this._config.weather || "weather.home";
66 | }
67 |
68 | get _speed_unit() {
69 | return this._config.speed_unit || "mp/h";
70 | }
71 | get _unit_of_measurement() {
72 | return this._config.unit_of_measurement || "AQI";
73 | }
74 | get _hide_title() {
75 | return this._config.hide_title !== false;
76 | }
77 |
78 | get _hide_face() {
79 | return this._config.hide_face !== true;
80 | }
81 | get _hide_weather() {
82 | return this._config.hide_weather !== false;
83 | }
84 |
85 | // WHAT DOES THIS DO?
86 | firstUpdated() {
87 | HELPERS.then(help => {
88 | if (help.importMoreInfoControl) {
89 | help.importMoreInfoControl("fan");
90 | }
91 | })
92 | }
93 |
94 | render() {
95 | if (!this.hass) {
96 | return html``;
97 | }
98 |
99 | // WHAT DOES THIS DO?
100 | const entities = Object.keys(this.hass.states).filter(
101 | (eid) => eid.substr(0, eid.indexOf(".")) === "sensor"
102 | );
103 |
104 | return html`
105 |