In another tutorial I’ve shown how to integrate, read and display a humidity and temperature sensor ENS21x from ScioSense into a Webserver and also in HomeAssistant (Article link).
This time I’ve built a webserver, which is reading from a ENS16x air quality sensor based on MOX sensor. The air quality give a feedback, how “good” the air is, mean if it smells bad or is even polluted by some unwanted gas compounds. In short, it does sense VOC (volatile organic compounds) in the air. What a MOX can’t: providing information of every single gas around, as the sensor always reacting on the bouquet of gases reaching the sensor. Big advantage, the sensor is quick, very quick!
The ScioSense MOX sensors ENS160 and ENS161 making the use of the same MEMS sensor, however are different in firmware which provides additional readings and sleep modes. In my project I’ve used the ENS161 as this sensor is offering in addition AQI-S, an additional information about air quality index with values between 0-500 also reflecting if the air becomes better or worse (see for closer description the datasheet section 5.4)
For easier sensor access, I’ve built a pcb hosting not only ENS16x but also ENS21x as well as the pressure sensor ENS220. As the sensors are intended to be used at 1.8V, an additional LDO plus interface level shifter is integrated.
Alternatively you can check for the ENS161 EvalKit (Mouser/Digikey) which combines already ENS161 with ENS210 (RHT) – the combination with humidity sensor provides higher accuracy as those two parameters also have impact on MOX working principles and therefor can be easily compensated.
HardwareOnce more I’ve used my EPS32-S2 mini carrier board, providing also RGB LED, four buttons, LiPo battery management and much more.
Aside from my board, of course all ESP32 derivates can be used instead, of course you have to adapt to the board of your choice then.
WebserverThe webserver allows easy access to all data read from the sensor cluster. Those are displayed as stationary values (next step to create interactive graphs).
- Temperature
- Relative Humidity
- AQI-U: Air quality index normed by the German Umweltbundesamt; values can be between 1-5 where 1 is very good, 5 is poor
- AQI-S: extended information of air quality, values between 0-500. Below 100 means better than the (average 24h) air before, values >100 indicating worse air quality up to pretty bad level of 500
- TVOC: total volatile organic compounds, all gases the sensor reacts on. As higher the value, as worse you might feel in a room
- eCO2: equivalent CO2 concentration. This is NOT real CO2, but calculated out of TVOC. Advantage: this is pretty accurate (see examples in the datasheet) and also indicates impact for wellbeing not only based on CO2 - so even better than pure CO2
- Rs3: the raw value of the MOX MEMS device
- Battery: once you’re using my proposed board, this will feedback the battery status
- MAC: MAC address of the used ESP
I like this tool for my housecontrol hence I also implemented the sensor to one of the dashboards. All data are provides as JSON message and can be used as individual entities.
The configuration.yaml needs to be updated as shown below.
#ENS16x sensor
- platform: rest
name: "ENS16x RH"
unique_id: ENS16x_RH
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.humidity | float | round(1) }}"
device_class: humidity
unit_of_measurement: "%rH"
scan_interval: 15
- platform: rest
name: "ENS16x T"
unique_id: ENS16x_T
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.temperature | float | round(1) }}"
device_class: temperature
unit_of_measurement: "°C"
scan_interval: 15
- platform: rest
name: "ENS16x Battery"
unique_id: ENS16x_bat
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.battery | float | round(2) }}"
device_class: battery
unit_of_measurement: "V"
scan_interval: 15
- platform: rest
name: "ENS16x AQIU"
unique_id: ENS16x_AQIU
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.AQIU | float | round(0) }}"
device_class: AQI
unit_of_measurement: ""
scan_interval: 15
- platform: rest
name: "ENS16x AQIS"
unique_id: ENS16x_AQIS
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.AQIS | float | round(0) }}"
device_class: AQI
unit_of_measurement: ""
scan_interval: 15
- platform: rest
name: "ENS16x TVOC"
unique_id: ENS16x_TVOC
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.TVOC | float | round(0) }}"
device_class: VOLATILE_ORGANIC_COMPOUNDS_PARTS
unit_of_measurement: "ppb"
scan_interval: 15
- platform: rest
name: "ENS16x eCO2"
unique_id: ENS16x_eCO2
resource: http://192.168.178.98/readings
method: GET
value_template: "{{value_json.eCO2 | float | round(0) }}"
device_class: VOLATILE_ORGANIC_COMPOUNDS_PARTS
#device_class: CO2
unit_of_measurement: "ppm"
scan_interval: 15
Obviously you need to adjust the IP address accordingly. After restarting HASS you'll have the entities ready to implement in your dashboard; making use of various widgets brings more colour in your life!
The code is written on Arduino IDE.
Important once you're uploading the code
- board: use the "LOLIN S2 Mini" (included in the esp32 board library provided by Espressif Systems
- as the Code uses SPIFFS for holding the web content, you need a data upload add-on called "ESP32 Sketch Data upload" -> currently only supported in Arduino IDE 1.x
In case you're interested in the KiCad data or the Fusion360 housing, drop me a PM
Comments
Please log in or sign up to comment.