Luftdaten.info local API sensors

There is an sensor for HASS called luftdaten, it queries the cloud based API and creates sensors in HASS.
The air quality open source sensor project is based upon a NodeMCU (ESP8266) and a SDS011 particle sensor.

You can if you want query the your local ESP8266 instead of the cloud API.

Access the local sensor is done via HTTP and the output is JSON. http://ip.adress/data.json is the URL to query.

More info can also be found (in german) on www.luftdaten.info and Swedish on www.luftdata.se

sensor:
  - platform: command_line
    name: "Luftdata PM10"
    command: 'curl http://192.168.21.47/data.json'
    value_template: "{{ value_json.sensordatavalues[0].value | round(2) }}"
    unit_of_measurement: "µg/m³"
  - platform: command_line
    name: "Luftdata PM2.5"
    command: 'curl http://192.168.21.47/data.json'
    value_template: "{{ value_json.sensordatavalues[1].value | round(2) }}"
    unit_of_measurement: "µg/m³"
  - platform: command_line
    name: "Luftdata Temperature DHT22"
    command: 'curl http://192.168.21.47/data.json'
    value_template: "{{ value_json.sensordatavalues[2].value | round(1) }}"
    unit_of_measurement: "°C"
  - platform: command_line
    name: "Luftdata Humidity DHT22"
    command: 'curl http://192.168.21.47/data.json'
    value_template: "{{ value_json.sensordatavalues[3].value | round(1) }}"
    unit_of_measurement: "%"
  
  - platform: statistics
    name: pm10 stats
    entity_id: sensor.luftdata_pm10
    max_age:
      minutes: 60
  - platform: statistics
    name: pm25 stats
    entity_id: sensor.luftdata_pm25
    max_age:
      minutes: 60
  
  - platform: template
    sensors:
      air_quality_pm10:
        friendly_name: 'Air quality PM10'
        value_template: >-
          {%if states.sensor.pm10_stats_mean.state | float<=25 %}EXCELLENT
          {% elif sensor.pm10_stats_mean.state | float<=50 | float>25 %}GOOD
          {% elif sensor.pm10_stats_mean.state | float<=90 | float>25 %}FAIR
          {% elif sensor.pm10_stats_mean.state | float<=180 | float>90 %}INFERIOR
          {% elif sensor.pm10_stats_mean.state | float>180 %}POOR
          {%- endif %}
  - platform: template
    sensors:
      air_quality_pm25:
        friendly_name: 'Air quality PM2.5'
        value_template: >-
          {%if states.sensor.pm25_stats_mean.state | float<=15 %}EXCELLENT
          {% elif sensor.pm25_stats_mean.state | float<=30 | float>15 %}GOOD
          {% elif sensor.pm25_stats_mean.state | float<=55 | float>30 %}FAIR
          {% elif sensor.pm25_stats_mean.state | float<=110 | float>55 %}INFERIOR
          {% elif sensor.pm25_stats_mean.state | float>110 %}POOR
          {%- endif %}
8 Likes

While you are technically correct, why not contribute to the Luftdaten info and register your sensor at their platform?

Done both, of course … Sorry for not being clear on that.

Love crowd sourced such as this one! <3

In the meantime I have built my own Luftdaten sensor, and have experimented with different ways of integrating this into HA without making a detour through the cloud, and decided to go with InfluxDB instead of rest.

If you are interested in reading more about this, take a look here:

3 Likes

Little late to answer but thanks for the tip! I was getting fed up with data not being fetched from the Luftdaten website, somehow the PM10 and PM2.5 rarely went through.

I would like to fetch sensor data as well but my sensor (data) is not available in hassio and also have error with “This entity does not have a unique ID” Can someone provide updated config in yaml please?
My JSON

{"software_version": "NRZ-2020-133", "age":"118", "sensordatavalues":[{"value_type":"SDS_P1","value":"37.28"},{"value_type":"SDS_P2","value":"13.68"},{"value_type":"BME280_temperature","value":"4.74"},{"value_type":"BME280_pressure","value":"99404.13"},{"value_type":"BME280_humidity","value":"86.27"},{"value_type":"samples","value":"5017387"},{"value_type":"min_micro","value":"28"},{"value_type":"max_micro","value":"20570"},{"value_type":"interval","value":"145000"},{"value_type":"signal","value":"-74"}]}