2018-08-22 22:05:28 +02:00
|
|
|
MH-Z19 CO_2 and Temperature Sensor
|
|
|
|
==================================
|
|
|
|
|
2018-11-14 22:12:27 +01:00
|
|
|
.. seo::
|
|
|
|
:description: Instructions for setting up MH-Z19 CO2 and temperature sensors
|
|
|
|
:image: mhz19.jpg
|
|
|
|
:keywords: mh-z19
|
|
|
|
|
2018-08-22 22:05:28 +02:00
|
|
|
The ``mhz19`` sensor platform allows you to use MH-Z19 CO_2 and temperature sensors
|
2023-05-17 15:43:17 +02:00
|
|
|
(`Revspace`_) with ESPHome.
|
2023-03-05 14:49:01 +01:00
|
|
|
The CO_2 measurement also works with the MH-Z16 and MH-Z14 sensors.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
.. figure:: images/mhz19-full.jpg
|
|
|
|
:align: center
|
|
|
|
:width: 50.0%
|
|
|
|
|
|
|
|
MH-Z19 CO_2 and Temperature Sensor.
|
|
|
|
|
2023-05-17 15:43:17 +02:00
|
|
|
.. _Revspace: https://revspace.nl/MHZ19
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
As the communication with the MH-Z19 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
|
|
|
|
MH-Z19 and the ``tx_pin`` connected to the RX Pin of the MH-Z19 (it's switched because the
|
|
|
|
TX/RX labels are from the perspective of the MH-Z19). Additionally, you need to set the baud rate to 9600.
|
|
|
|
|
2018-11-19 18:32:16 +01:00
|
|
|
.. code-block:: yaml
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
# Example configuration entry
|
|
|
|
uart:
|
2021-12-22 07:39:13 +01:00
|
|
|
rx_pin: GPIO3
|
|
|
|
tx_pin: GPIO1
|
2018-08-22 22:05:28 +02:00
|
|
|
baud_rate: 9600
|
2018-08-24 22:44:01 +02:00
|
|
|
|
2018-08-22 22:05:28 +02:00
|
|
|
sensor:
|
|
|
|
- platform: mhz19
|
|
|
|
co2:
|
|
|
|
name: "MH-Z19 CO2 Value"
|
|
|
|
temperature:
|
|
|
|
name: "MH-Z19 Temperature"
|
2019-01-06 18:56:14 +01:00
|
|
|
update_interval: 60s
|
2019-08-27 19:40:52 +02:00
|
|
|
automatic_baseline_calibration: false
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
Configuration variables:
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
|
|
|
|
- **co2** (**Required**): The CO_2 data from the sensor in parts per million (ppm).
|
|
|
|
|
|
|
|
- **name** (**Required**, string): The name for the CO_2 sensor.
|
|
|
|
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas.
|
2019-02-17 12:28:17 +01:00
|
|
|
- All other options from :ref:`Sensor <config-sensor>`.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
- **temperature** (**Required**): The information for the temperature sensor. Please note that this is
|
|
|
|
not officially documented in the datasheet and seems to be quite inaccurate.
|
|
|
|
|
|
|
|
- **name** (**Required**, string): The name for the temperature sensor.
|
|
|
|
- **id** (*Optional*, :ref:`config-id`): Set the ID of this sensor for use in lambdas.
|
2019-02-17 12:28:17 +01:00
|
|
|
- All other options from :ref:`Sensor <config-sensor>`.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
- **update_interval** (*Optional*, :ref:`config-time`): The interval to check the
|
2019-01-06 18:56:14 +01:00
|
|
|
sensor. Defaults to ``60s``.
|
2018-08-22 22:05:28 +02:00
|
|
|
|
|
|
|
- **uart_id** (*Optional*, :ref:`config-id`): Manually specify the ID of the :ref:`UART Component <uart>` if you want
|
|
|
|
to use multiple UART buses.
|
|
|
|
|
2019-08-27 19:40:52 +02:00
|
|
|
- **id** (*Optional*, :ref:`config-id`): Manually specify the ID used for actions.
|
|
|
|
|
|
|
|
- **automatic_baseline_calibration** (*Optional*, boolean): MH-Z19 has automatic calibration procedure.
|
|
|
|
The automatic calibration cycle is every 24 hours after powered on.
|
|
|
|
Set this value to ``false`` to disable ABC on boot (it's better if you use sensor indoor).
|
|
|
|
Set this value to ``true`` to enable ABC on boot.
|
|
|
|
Doesn't send calibration command if not set (default sensor logic will be used).
|
|
|
|
|
2018-08-22 22:05:28 +02:00
|
|
|
.. figure:: images/mhz19-pins.jpg
|
|
|
|
:align: center
|
|
|
|
:width: 80.0%
|
|
|
|
|
|
|
|
Pins on the MH-Z19. Only the ones marked with a red circle need to be connected.
|
|
|
|
|
2019-08-27 19:40:52 +02:00
|
|
|
.. _mhz19-calibrate_zero_action:
|
|
|
|
|
|
|
|
``mhz19.calibrate_zero`` Action
|
|
|
|
-------------------------------
|
|
|
|
|
|
|
|
This :ref:`action <config-action>` executes zero point calibration command on the sensor with the given ID.
|
|
|
|
|
|
|
|
If you want to execute zero point calibration, the MH-Z19 sensor must work in stable gas environment (400ppm)
|
|
|
|
for over 20 minutes and you execute this function.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
|
|
|
- mhz19.calibrate_zero: my_mhz19_id
|
|
|
|
|
|
|
|
You can provide :ref:`service <api-services>` to call it from Home Assistant
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
api:
|
|
|
|
services:
|
|
|
|
- service: mhz19_calibrate_zero
|
|
|
|
then:
|
|
|
|
- mhz19.calibrate_zero: my_mhz19_id
|
|
|
|
|
|
|
|
.. _mhz19-abc_enable_action:
|
|
|
|
|
|
|
|
``mhz19.abc_enable`` Action
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
This :ref:`action <config-action>` enables automatic baseline calibration on the sensor with the given ID.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
|
|
|
- mhz19.abc_enable: my_mhz19_id
|
|
|
|
|
|
|
|
.. _mhz19-abc_disable_action:
|
|
|
|
|
|
|
|
``mhz19.abc_disable`` Action
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
This :ref:`action <config-action>` disables automatic baseline calibration on the sensor with the given ID.
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
on_...:
|
|
|
|
then:
|
|
|
|
- mhz19.abc_disable: my_mhz19_id
|
|
|
|
|
|
|
|
You can provide switch and control ABC from Home Assistant
|
|
|
|
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
switch:
|
|
|
|
- platform: template
|
|
|
|
name: "MH-Z19 ABC"
|
|
|
|
optimistic: true
|
|
|
|
on_turn_on:
|
|
|
|
mhz19.abc_enable: my_mhz19_id
|
|
|
|
on_turn_off:
|
|
|
|
mhz19.abc_disable: my_mhz19_id
|
|
|
|
|
2018-08-22 22:05:28 +02:00
|
|
|
See Also
|
|
|
|
--------
|
|
|
|
|
|
|
|
- :ref:`sensor-filters`
|
2018-08-24 22:44:01 +02:00
|
|
|
- `MH-Z19 library <https://github.com/nara256/mhz19_uart>`__ by `@nara356 <https://github.com/nara256>`__
|
2019-05-12 22:44:59 +02:00
|
|
|
- :apiref:`mhz19/mhz19.h`
|
2019-02-07 13:54:45 +01:00
|
|
|
- :ghedit:`Edit`
|