Does setting the scan_interval
of a RESTful sensor component still work? Or did it ever work?
This has become an issue because Purple Air is changing their API to charging based point system. I need to control the frequency that the the sensor polls so I don’t eat up all my points. I set the scan_interval
, but the reporting on the API dashboard doesn’t seem to match that set frequency. The docs for the RESTful sensor component don’t include scan_interval
as a config option. But there is an example of using scan_interval
for the RESTful component. Am I just using REST wrong now?
sensor:
- platform: rest
name: 'PurpleAir'
# Substitute in the URL of the sensor you care about. To find the URL, go
# to purpleair.com/map, find your sensor, click on it, click on "Get This
# Widget" then click on "JSON".
resource: https://api.purpleair.com/v1/sensors/11111?fields=pm2.5_10minute
headers:
X-API-KEY: MY-API-KEY
scan_interval: 300
# Set this sensor to be the AQI value.
#
# Code translated from JavaScript found at:
# https://docs.google.com/document/d/15ijz94dXJ-YAZLi9iZ_RaBwrZ4KtYeCy08goGBwnbCU/edit#
value_template: >
{% macro calcAQI(Cp, Ih, Il, BPh, BPl) -%}
{{ (((Ih - Il)/(BPh - BPl)) * (Cp - BPl) + Il)|round }}
{%- endmacro %}
{% set pm25 = value_json.sensor.stats["pm2.5_10minute"] %}
{% if (pm25|float(0)) > 1000 %}
invalid
{% elif (pm25|float(0)) > 350.5 %}
{{ calcAQI((pm25|float(0)), 500.0, 401.0, 500.0, 350.5) }}
{% elif (pm25|float(0)) > 250.5 %}
{{ calcAQI((pm25|float(0)), 400.0, 301.0, 350.4, 250.5) }}
{% elif (pm25|float(0)) > 150.5 %}
{{ calcAQI((pm25|float(0)), 300.0, 201.0, 250.4, 150.5) }}
{% elif (pm25|float(0)) > 55.5 %}
{{ calcAQI((pm25|float(0)), 200.0, 151.0, 150.4, 55.5) }}
{% elif (pm25|float(0)) > 35.5 %}
{{ calcAQI((pm25|float(0)), 150.0, 101.0, 55.4, 35.5) }}
{% elif (pm25|float(0)) > 12.1 %}
{{ calcAQI((pm25|float(0)), 100.0, 51.0, 35.4, 12.1) }}
{% elif (pm25|float(0)) >= 0.0 %}
{{ calcAQI((pm25|float(0)), 50.0, 0.0, 12.0, 0.0) }}
{% else %}
invalid
{% endif %}
unit_of_measurement: "AQI"