Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {# pollutant: VOC #}
- {% set pollutant = states('sensor.apollo_air_1_2d2ee4_sen55_voc') | float %}
- {% set aqi = namespace(value=0) %}
- {# Set Breakpoints for pollutant #}
- {% set good_low = 0.0 | float %}
- {% set good_high = 79 | float %}
- {% set moderate_low = 80 | float %}
- {% set moderate_high = 119 | float %}
- {% set sensitive_low = 120 | float %}
- {% set sensitive_high = 199 | float %}
- {% set unhealthy_low = 200 | float %}
- {% set unhealthy_high = 299 | float %}
- {% set very_low = 300 | float %}
- {% set very_high = 399 | float %}
- {% set hazard_low = 400 | float %}
- {% set hazard_high = 599 | float %}
- {# Calculate AQI #}
- {% if pollutant <= good_high %}
- {% set aqi = ((pollutant - good_low) * (50-0)/(good_high - good_low)) %}
- {% elif pollutant <= moderate_high %}
- {% set aqi = ((pollutant - moderate_low) * (100-51)/(moderate_high-moderate_low)) + 51 %}
- {% elif pollutant <= sensitive_high %}
- {% set aqi = ((pollutant - sensitive_low) * (150-101)/(sensitive_high - sensitive_low)) + 101 %}
- {% elif pollutant <= unhealthy_high %}
- {% set aqi = ((pollutant - unhealthy_low) * (200-151)/(unhealthy_high - unhealthy_low)) + 151 %}
- {% elif pollutant <= very_high %}
- {% set aqi = ((pollutant - very_low) * (300-201)/(very_high - very_low)) + 201 %}
- {% else %}
- {% set aqi = ((pollutant - hazard_low) * (500-301)/(hazard_high - hazard_low)) + 301 %}
- {% endif %}
- {{ aqi | round(0) }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement