PM1006 Particulate Matter Sensor
================================

.. seo::
    :description: Instructions for setting up PM1006 Particulate matter sensors, such as in the IKEA VINDRIKTNING
    :image: pm1006.jpg
    :keywords: pm1006, IKEA VINDRIKTNING

The ``pm1006`` sensor platform allows you to use Cubic PM1006 particulate matter sensors (`datasheet <http://www.jdscompany.co.kr/download.asp?gubun=07&filename=PM1006_LED_PARTICLE_SENSOR_MODULE_SPECIFICATIONS.pdf>`__)
with ESPHome.

.. figure:: images/ikea-vindriktning.jpg
    :align: center
    :width: 50.0%

    IKEA VINDRIKTNING Particulate Matter Sensor with PM1006 inside

As the communication with the PM1006 is done using UART, you need to have an :ref:`UART bus <uart>` in your configuration with the ``rx_pin`` connected to the TX pin of the PM1006.
The baud rate needs to be set to 9600.

.. code-block:: yaml

    # Example configuration entry
    uart:
      rx_pin: D2
      baud_rate: 9600

    sensor:
      - platform: pm1006
        pm_2_5:
          name: "Particulate Matter 2.5µm Concentration"

In common usage, with the IKEA VINDRIKTNING still controlling the pm1006 sensor, there is no update interval, and this implementation will passively pick up whatever the VINDRIKTNING MCU has requested from the sensor.

The implementation was inspired by https://github.com/Hypfer/esp8266-vindriktning-particle-sensor; you can also see the pinout there.
However, we recommend mounting your ESP below the fan (which blows out the front) so you do not obstruct the airflow.
`This discussion thread on the HA forum <https://community.home-assistant.io/t/ikea-vindriktning-air-quality-sensor/324599>`__ has several examples of how people have connected their ESP device to the IKEA sensor.

Configuration variables:
------------------------

- **pm_2_5** (*Optional*): Use the concentration of particulates of size less than 2.5µm in µg per cubic meter.
  All options from :ref:`Sensor <config-sensor>`.

- **uart_id** (*Optional*, :ref:`config-id`): Manually specify the ID of the :ref:`UART Component <uart>` if you want
  to use multiple UART buses.

- **update_interval** (*Optional*, :ref:`config-time`): If you need to actively request measurements to the sensor, set this to some sensible interval. The IKEA VINDRIKTNING does measurements every 20 seconds. Defaults to never.

Using this component standalone
-------------------------------

If you acquired a pm1006 outside of an IKEA VINDRIKTNING, or if you removed the IKEA MCU or replaced the whole PCB, you will need to actively request measurements.
In that case, you need a TX pin, and you need to set an update interval.

Example config:

.. code-block:: yaml

    # Example configuration entry
    uart:
      rx_pin: D2
      tx_pin: D1
      baud_rate: 9600

    sensor:
      - platform: pm1006
        pm_2_5:
          name: "Particulate Matter 2.5µm Concentration"
        update_interval: 20s


If you run the PM1006 (2.5µm) or PM1006K (1, 2.5, 10µm) independent from the original MCU you need to send a serial command in the first 5 seconds after power is applied to the sensor. Otherwise the sensor will switch to PWM mode and does not repond to UART requests. A possibility to do this in ESPhome is to use an automation. `Source <https://community.home-assistant.io/t/ikea-vindriktning-air-quality-sensor/324599/300>`_

Example config:

.. code-block:: yaml

    # Example configuration entry
    on_boot:
      priority: 240
      then:
        - uart.write:
            id: ikea #id of the uart bus used for the PM1006
            data: [0x11, 0x02, 0x0B, 0x01, 0xE1]


See Also
--------

- :doc:`/components/sensor/pmsx003`
- :ref:`sensor-filters`
- :apiref:`pm1006/pm1006.h`
- :ghedit:`Edit`
