Awair Local Sensors

Their current production Element supports realtime local LAN access to sensor data, they even explicitly call out Home Assistant in their support page for the feature, but offer no code.

So I made some. Obviously you need to change the IP Address and sensor names, and possibly the friendly name, but the rest should stay the same. Add to sensors.yaml

  - platform: rest
    name: awair_livingroom_sensors
    resource: http://192.168.0.210/air-data/latest
    json_attributes:
      - timestamp
      - score
      - dew_point
      - temp
      - humid
      - abs_humid
      - co2
      - co2_est
      - voc
      - voc_baseline
      - voc_h2_raw
      - voc_ethanol_raw
      - pm25
      - pm10_est
    value_template: 'OK'
  - platform: template
    sensors:
      awair_lr_score:
        friendly_name: "Quality Score"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["score"] }}'
        unit_of_measurement: '%'
      awair_lr_temp:
        friendly_name: "Temperature"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["temp"] }}'
        device_class: temperature
        unit_of_measurement: '°C'
      awair_lr_humid:
        friendly_name: "Relative Humidity"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["humid"] }}'
        device_class: humidity
        unit_of_measurement: '%'
      awair_lr_co2:
        friendly_name: "Carbon Dioxide"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["co2"] }}'
        unit_of_measurement: 'ppm'
      awair_lr_voc:
        friendly_name: "Total VOC"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["voc"] }}'
        unit_of_measurement: 'ppb'
      awair_lr_pm25:
        friendly_name: "Particulate Matter 2.5"
        value_template: '{{ states.sensor.awair_livingroom_sensors.attributes["pm25"] }}'
        unit_of_measurement: 'μg/m³'
14 Likes

Just got an Awair Element and tried this - it works great! Would love for this to be the default way to access Awair, as going through the REST API requires a developer account and approval, and violates the “sensors should be accessed locally” principle…

unfortunately the Glow C does not support local sensors, and the feature is still listed as “beta” and may be subject to change, it is ported from their enterprise Omni product, which is hilariously expensive

FYI there is a pull request open for adding local sensors to the Awair integration, so this wont be needed soon

1 Like

Just wanted to say thanks for this. The recent outage with awair (due to certificates expiring) is the kind of reason why I dislike cloud reliance. Well, that and companies shutting down after after a couple years.

any idea how to change the Awair score from % to “score”

I think just removing the unit of measurement will do it. Since it is a number from 0 to 100, with higher being better, % makes much more sense, as it is NOT an AQI score where it gets higher as quality gets worse

Curious what the status is on the Awair integration?

Also, I’m ordering an AirThings Wave Plus (Black Friday sale) to use in addition to my Awair (I want the radon detection) and I’m thinking about taking the work from here https://github.com/gkreitz/homeassistant-airthings and making it into an integration. Any pointers?

Nothing yet, dev can be slow if there is not consensus on how to implement. Soon may not be soon. Luckily the level of complexity here is minimal, and a native integration does not give any new features relative to this

My advice would be to use that work to read the values and publish them to MQTT, then use that in HA, since the HA server may not be in proximity to read the bluetooth signal

Just wanted to say thanks, the YAML worked great with minimal modification. I’m always happy when a device makes a simple local API - it isn’t hard, and it enables clean simple integrations like this. Looking forward to Local being added to the official integration, but in the meantime this is getting me what I wanted - indoor air quality without a cloud API!

Thank you for sharing! It’s a pity HA’s default integration for Awair Element is via Cloud when local is available!

In any case, I have implemented the solution above. I’m able to successfully see the metrics in the HA Overview screen

However, As a HA Noob, I’m having two problems:

  1. There doesn’t seem to be a Device created for the Airwair. I’m trying to create some automations based on Awair readings, but can’t see the Awair Element as a Device, therefore can’t create an automation
  2. If I try edit an Awair Element entity (E.g. edit CO2 entity), I get an error saying there is no unique ID for the entity. See below.

If someone could point me in the right direction, would be great. Thx

For automations you need to create it based on the numeric state of the entity. This is one I use that sends an alert if the CO2 is above 0.1% for 15 minutes:

alias: 'Alert CO₂ Elevated'
description: ''
trigger:
  - above: '1000'
    entity_id: sensor.awair_lr_co2
    for: '00:15:00'
    platform: numeric_state
condition:
  - condition: state
    entity_id: input_boolean.alert_co2
    state: 'off'
action:
  - data:
      title: Elevated CO₂
      message: You should get some fresh air
      display_time_ms: 120000
      icon: warning
      persistent: 'yes'
      id: co2_alert
    service: script.generate_alert_notification
  - data: {}
    entity_id: input_boolean.alert_co2
    service: input_boolean.turn_on
  - service: script.script_alert_bulbs_flash
    data:
      color: Yellow
      seconds: 30
mode: single

Since I am using a condition for an active alert, there is another automation that turns that off once CO2 has dropped to a nominal value, and that will also dismiss the persistent notification I created. I also have other automations with shorter timeframes and larger concentrations to detect things like sudden dry ice leaks (which is a concern for me)

As for editing the sensor, that needs to be done in the initial code, then you reload the sensors

2 Likes

would you care to share “script.generate_alert_notification”, looks appealing and above my pay grade.
TIA

The deal with that is that the Android and iOS notification parameters are not the same, and I want all notifications on my phone, but wife wants minimal notifications (only important stuff).

So that is a complex wrapper that takes a common parameter set, then will chose based on a given priority what to send to the Android and iOS notification services, as well as to Kodi to display on the tv, and to a persistent notification in the HA UI.

With the last couple of releases of both HA and the mobile apps there have been a lot of changes to the code, I am done with the Android part, but redoing the iOS and priority control part, then I will post it to the shared projects and let you know.

The basic structure is:

generate_alert_notification  >> 
    select service by priority x >> 
        android_service_x_priority >>
            android_x_notification_group
        ios_service_x_priority >>
            ios_x_notification_group

So there will be 2 device specific scripts, 3 services in each script and 3 notification groups per device type, and it will select the right one based on the specified priority, and if I want to change a devices notification priority, I just have to add it to the right groups

Cool. Really appreciate it.
Lurnin-as-i-go

Thanks for posting this. The cloud Awair integration has been constantly going down for me over the past few days despite the elements themselves having connectivity. Driving me crazy.

Enabling and using the local API solves this since it no longer relies on the cloud.

1 Like

I don’t understand. If they have a local API available… Why is the home assistant component page still talking about the cloud pollng version?

2 Likes

Because the local API is not handled by the integration.

The main reason for that is the local API did not exist when that code was developed, and the most probable reason it has not been added is that not all Awair devices support the local API, and for the devices that do it needs to be enabled as an “experimental” feature.

I am sorry for bumping an old thread but I was hoping someone would take some pity on me and help me use the original above code for multiple Awairs. I have tried taking the original code and inserting it into my .yaml file but only the first awair in the file gets picked up by HA. I am sure I am doing something wrong but after multiple different configuration attempts, I just can’t seem to figure it out.

I have three Awair’s (livingroom, bedroom and office) and any assistance anyone could provide me would be very much appreciated.

I can post my code snippet if that will help as well.

I have two. Works great. Here is the code from my sensors.yaml. I’m sure there is a better way to do this, but I just ended up using duplicate code blocks. Obviously those are my IPs and device names, but you get the idea.


# Cafe Awair
  - platform: rest
    name: awair_cafe_sensors
    resource: http://192.168.123.68/air-data/latest
    scan_interval: 60
    json_attributes:
      - timestamp
      - score
      - dew_point
      - temp
      - humid
      - abs_humid
      - co2
      - co2_est
      - voc
      - voc_baseline
      - voc_h2_raw
      - voc_ethanol_raw
      - pm25
      - pm10_est
    value_template: 'OK'

  - platform: template
    sensors:
      awair_cafe_score:
        unique_id: aw-c-s
        friendly_name: "Cafe Awair Score"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["score"] }}'
        unit_of_measurement: '%'
      awair_cafe_temp:
        unique_id: aw-c-t
        friendly_name: "Cafe Awair Temperature"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["temp"] }}'
        device_class: temperature
        unit_of_measurement: '°C'
      awair_cafe_humid:
        unique_id: aw-c-h
        friendly_name: "Cafe Awair Humidity"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["humid"] }}'
        device_class: humidity
        unit_of_measurement: '%'
      awair_cafe_co2:
        unique_id: aw-c-co2
        friendly_name: "Cafe Awair CO2"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["co2"] }}'
        unit_of_measurement: 'ppm'
      awair_cafe_voc:
        unique_id: aw-c-voc
        friendly_name: "Cafe Awair VOC"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["voc"] }}'
        unit_of_measurement: 'ppb'
      awair_cafe_pm25:
        unique_id: aw-c-pm
        friendly_name: "Cafe Awair PM2.5"
        value_template: '{{ states.sensor.awair_cafe_sensors.attributes["pm25"] }}'
        unit_of_measurement: 'μg/m³'
        
# Bedroom Awair
  - platform: rest
    name: awair_bedroom_sensors
    resource: http://192.168.123.69/air-data/latest
    scan_interval: 60
    json_attributes:
      - timestamp
      - score
      - dew_point
      - temp
      - humid
      - abs_humid
      - co2
      - co2_est
      - voc
      - voc_baseline
      - voc_h2_raw
      - voc_ethanol_raw
      - pm25
      - pm10_est
    value_template: 'OK'
  
  - platform: template
    sensors:
      awair_bedroom_score:
        unique_id: aw-b-s
        friendly_name: "Bedroom Awair Score"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["score"] }}'
        unit_of_measurement: '%'
      awair_bedroom_temp:
        unique_id: aw-b-t
        friendly_name: "Bedroom Awair Temperature"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["temp"] }}'
        device_class: temperature
        unit_of_measurement: '°C'
      awair_bedroom_humid:
        unique_id: aw-b-h
        friendly_name: "Bedroom Awair Humidity"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["humid"] }}'
        device_class: humidity
        unit_of_measurement: '%'
      awair_bedroom_co2:
        unique_id: aw-b-co2
        friendly_name: "Bedroom Awair CO2"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["co2"] }}'
        unit_of_measurement: 'ppm'
      awair_bedroom_voc:
        unique_id: aw-b-voc
        friendly_name: "Bedroom Awair VOC"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["voc"] }}'
        unit_of_measurement: 'ppb'
      awair_bedroom_pm25:
        unique_id: aw-b-pm
        friendly_name: "Bedroom Awair PM2.5"
        value_template: '{{ states.sensor.awair_bedroom_sensors.attributes["pm25"] }}'
        unit_of_measurement: 'μg/m³'

1 Like