Home Elements Boards Recipes

AM2320 Element

The AM2320Element allows retrieving temperature and humidity values and creates actions when new values are available.

The AM2320 sensor was created to be a drop-in replacement for the DHT22 but also support the i2c interface.

DHT and I2C support

The AM2320 sensor was created to be a drop-in replacement for the DHT22 but also support the i2c interface. There is a good article on comparing these two interfaces: See https://learn.adafruit.com/modern-replacements-for-dht11-dht22-sensors for the advantage of i2c over DHT22 Wire signals.

When using the DHT mode it is important to set pin 3 and 4 to permanent GND level. You can use the DHT Element to implement reading the temperature and humidity values.

When using the I2C mode pin 3 is used for GND and pin 4 is used for the i2c-clk signal. The device may not respond at the first request as it stays in an deactivated mode and must be waked up using a i2c read request without data.

The WireUtils do this when checking for a device to exist on a given address.

Web UI for the AM2320 Element

There is a dedicated card for sensors supporting temperature and humidity that shows the actual values.

T/H Sensor UI

Using the AM2320 Element

The AM2320 Element is not part of the core set of elements as it is not used very frequently. It can be registered and added to the firmware by including the definition of HOMEDING_INCLUDE_AM2320 in the sketch:

// Use some more Elements that need additional libraries
#define HOMEDING_INCLUDE_AM2320
#include <HomeDing.h>

Connecting a AM2320 Sensor

The sensor is using the I2C bus for communication and is usually placed on a adapter board giving access to the required pins.

Using the default I2C bus pins:

Signal ESP8266 ESP32 Sensor Description
GND GND GND 3 GND Ground for I2C and Power Supply
VCC 3.3v 3.3v 1 VCC/VDD Power Supply
SDA GPIO4(D2) IO21 2 SDA I2C Data Signal
SCL GPIO5(D1) IO22 4 SCL I2C Clock Signal

The required power for the sensor is low and the 3.3V from most CPU boards can be used.

For more details on using the i2c bus and specifying pins in the Device Element see I2C bus.

Element Configuration

The following properties are available for configuration of the element:

address - The i2c address of the sensor. The default value is 0x40.

onTemperature - These actions are emitted by the element when the temperature gets a new value. The action will not be sent when reading the sensor values that stay the same.

onHumidity - These actions are emitted by the element when the humidity gets a new value. The action will not be sent when reading ne sensor values that stay the same.

From the base Sensor Element implementation the following properties are available for configuration:

readTime – Time between 2 probes being fetched from the sensor. Default value is 1m.

resendTime – The current values of the probe are resent after this specified time even when not changing.

warmupTime – This time is waited after powering the sensor on the first start or after a reset before the first data is fetched. The default time is set to 3 seconds.

restart – This property can be set to true to enable an automated restart when the sensor was not responding data.

From the base element implementation the following properties are available for configuration:

title – Caption text for the element. Used by the element specific cards on the dash boards.

description – A line of text that gives a short description of the device used in the web UI.

room – The location of the device.

loglevel – This property holds the element specific log level. The default value is LOGGER_LEVEL_ERR == 1.

startup – This property can be used to start the element using a different initialization phase. Possible values are “sys”, “net”, “time”. See The Startup sequence.

Configuration Example

This example shows how to configure this element:

{
  "am2320": {
    "s": {
      "title": "AM2320",
      "description": "Temperature and Humidity sensor",
      "readtime": "30s",
      "onHumidity": "displaytext/h?value=$v",
      "onTemperature": "displaytext/t?value=$v"
    }
  }
}

Element State

The following properties are available with the current values at runtime

active - Is set to true when the element is active.

temperature - The last read temperature value from the sensor.

humidity - The last read humidity value from the sensor.

Example State

{
  "am2320/s": {
    "active":"true",
    "temperature":"27.30",
    "humidity":"50.50"
  }
}

See Also

Tags

Element Sensor