~derf / projects / ESP8266/NodeMCU PM1006 driver
dark mode

ESP8266 Lua/NodeMCU module for Vindriktning / PM1006 PM sensors

esp8266-nodemcu-pm1006 contains an ESP8266 NodeMCU Lua module (pm1006.lua) as well as MQTT / HomeAssistant / InfluxDB integration example (init.lua) for the PM1006 particulate matter (PM2.5) sensor found in IKEA Vindriktning.

Dependencies

pm1006.lua has been tested with Lua 5.1 on NodeMCU firmware 3.0.1 (Release 202112300746, integer build). Most practical applications (such as the example in init.lua) require the following modules.

  • gpio
  • mqtt
  • node
  • softuart
  • tmr
  • uart
  • wifi

Setup

Connect the PM1006 sensor to your ESP8266/NodeMCU board as documented by Hypfer.

If you use a different UART pin, you need to adjust the softuart.setup call in the examples provided in this repository to reflect that change. Keep in mind that some ESP8266 pins must have well-defined logic levels at boot time and may therefore be unsuitable for PM1006 connection.

Usage

Copy pm1006.lua to your NodeMCU board and set it up as follows.

pm1006 = require("pm1006")
port = softuart.setup(9600, nil, 2)
port:on("data", 20, uart_callback)

function uart_callback(data)
    local pm2_5 = pm1006.parse_frame(data)
    if pm25i ~= nil then
        -- pm2_5 contains PM2.5 value in µg/m³
    else
        -- invalid frame header or checksum
    end
end

Application Example

init.lua is an example application with HomeAssistant integration. To use it, you need to create a config.lua file with WiFI and MQTT settings:

station_cfg.ssid = "..."
station_cfg.pwd = "..."
mqtt_host = "..."

Optionally, it can also publish readings to an InfluxDB. To do so, configure URL and attribute:

influx_url = "..."
influx_attr = "..."

Readings will be stored as vindriktning,[influx_attr] pm2_5_ugm3=...