Last active
February 23, 2018 15:15
-
-
Save Naesstrom/768598a20e61d8fe79700933db738940 to your computer and use it in GitHub Desktop.
luftdaten_quality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sensors created in HASS | |
- sensor.luftdaten_pm10 | |
- sensor.luftdaten_pm25 | |
##HASS template: | |
## Calculate AirQUality: | |
## average percentage of values below thesholds defined by WHO | |
## <=40% -> EXCELLENT | |
## <=60% -> GOOD | |
## <=80% -> FAIR | |
## <=100% -> INFERIOR | |
## >100% -> POOR Since poor quality can be used as a trigger. | |
value_pm10: '{{ (sensor.luftdaten_pm10/50) | float(2) }}? | |
##Code from homebridge | |
// Calculate AirQUality: | |
// average percentage of values below thesholds defined by WHO | |
// <=40% -> EXCELLENT | |
// <=60% -> GOOD | |
// <=80% -> FAIR | |
// <=100% -> INFERIOR | |
// >100% -> POOR Since poor quality can be used as a trigger. | |
if (pm10 && pm25) { | |
// PM10: 50 µg/m³ daily limit | |
let percentPm10 = parseFloat(pm10) / 50.0; | |
// PM2.5: 25 µg/m³ daily limit | |
let percentPm25 = parseFloat(pm25) / 25.0; | |
let qualityPercentage = (percentPm10 + percentPm25) / 2.0; | |
let absChange = Math.abs(this.qualityPercentage - qualityPercentage); | |
let wasNotSet = this.qualityPercentage == undefined || this.qualityPercentage == null; | |
this.qualityPercentage = qualityPercentage; | |
// Only set new quality level if there was a significant change | |
if (wasNotSet || absChange >= 0.05) { | |
if (qualityPercentage <= 0.4) { | |
this.airQuality = Characteristic.AirQuality.EXCELLENT; | |
} else if (qualityPercentage <= 0.6) { | |
this.airQuality = Characteristic.AirQuality.GOOD; | |
} else if (qualityPercentage <= 0.8) { | |
this.airQuality = Characteristic.AirQuality.FAIR; | |
} else if (qualityPercentage <= 1.0) { | |
this.airQuality = Characteristic.AirQuality.INFERIOR; | |
} else if (qualityPercentage > 1.0) { | |
this.airQuality = Characteristic.AirQuality.POOR; | |
} else { | |
this.airQuality = Characteristic.AirQuality.UNKNOWN; | |
} | |
this.airQualityService.setCharacteristic( | |
Characteristic.AirQuality, | |
this.airQuality |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment