Zigbee soil moisture sensor (ZG-303Z by HOBEIAN)

Hello,

Recently i got myself some zigbee soil moisture sensors from AliExpress.
https://www.aliexpress.com/item/1005009760936017.html

Devices paired successfully with ZHA and exposed two sensors, humidity and temperature, as well as battery.

I placed two of them in some indoor flowerpots and started monitoring. The temperature sensor is supposed to measure ambient temperature and they look OK. The humidity sensor is supposed to measure soil humidity, and it is behaving weird. The spike on the yellow line is me watering the plants. The red sensor was placed the following morning, but both pots were watered at the same time. It doesn’t seem right to me that the soil is still saturated with water even after all those hours. Furthermore, it is constantly rising. Something is very odd here.

The blue lines are from another ambient temperature/humidity sensor in the same room, for reference.

I have two of those still unopened and i can use them for testing

I don’t believe the Humidity means soil Humidity, it seems to me to mean air humidity.
There should be a sensor that tells you moisture, and it appears to be missing.

These are likely Tuya based sensors, so you would have to ask the Tuya Spirits where that sensor is, but that is my guess. Does the Tuya smart life app show a moisture sensor on these?

1 Like

I got this to work using this zha quirk. The only thing that is off is that the Humidity and the Soil moisture are swapped. Could be worse.
Reference to this to how to install zha quirks.

"""HOBEIAN ZG-303Z Soil Moisture Sensor quirk."""

from zigpy.profiles import zha
from zigpy.quirks import CustomDevice
from zigpy.zcl.clusters.general import Basic, Identify, PowerConfiguration
from zigpy.zcl.clusters.measurement import RelativeHumidity, SoilMoisture, TemperatureMeasurement

from zhaquirks.const import (
    DEVICE_TYPE,
    ENDPOINTS,
    INPUT_CLUSTERS,
    MODELS_INFO,
    OUTPUT_CLUSTERS,
    PROFILE_ID,
)
from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.mcu import (
    DPToAttributeMapping,
    TuyaMCUCluster,
)


class TuyaSoilMoistureCluster(TuyaLocalCluster, SoilMoisture):
    """Tuya Soil Moisture cluster."""

    cluster_id = SoilMoisture.cluster_id


class SoilMoistureMCUCluster(TuyaMCUCluster):
    """Tuya MCU Cluster for ZG-303Z Soil Moisture Sensor."""

    dp_to_attribute: dict[int, DPToAttributeMapping] = {
        109: DPToAttributeMapping(
            TuyaSoilMoistureCluster.ep_attribute,
            "measured_value",
            converter=lambda x: x * 100,
        ),
    }

    data_point_handlers = {
        109: "_dp_2_attr_update",
    }


class HobeianZG303Z(CustomDevice):
    """HOBEIAN ZG-303Z Soil Moisture Sensor."""

    signature = {
        MODELS_INFO: [("HOBEIAN", "ZG-303Z")],
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: 0x0302,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    TemperatureMeasurement.cluster_id,
                    RelativeHumidity.cluster_id,
                    0xEF00,
                ],
                OUTPUT_CLUSTERS: [
                    Identify.cluster_id,
                ],
            }
        },
    }

    replacement = {
        ENDPOINTS: {
            1: {
                PROFILE_ID: zha.PROFILE_ID,
                DEVICE_TYPE: 0x0302,
                INPUT_CLUSTERS: [
                    Basic.cluster_id,
                    PowerConfiguration.cluster_id,
                    Identify.cluster_id,
                    TemperatureMeasurement.cluster_id,
                    RelativeHumidity.cluster_id,
                    TuyaSoilMoistureCluster,
                    SoilMoistureMCUCluster,
                ],
                OUTPUT_CLUSTERS: [
                    Identify.cluster_id,
                ],
            }
        }
    }
2 Likes

Haven’t tried the Tuya app as i don’t have a Tuya zigbee gateway. I will try the quirk suggested by @pluggedinn. I don’t think that the sensor is measuring ambient humidity as it doesn’t correspond at all with the humidity measured by the other humidity sensor i have in the room. Maybe the devices are just broken, or they require a quirk to function properly.

I re-paired the devices with the coordinator yesterday and the measurements looked kind of normalized. The red one required two attempts. I also added another one in a third pot for comparison. There is a spike this morning from watering (just slightly, for testing).

I have a fourth one that i will try to use as a testing device. Move it from pot to pot, submerging it in water directly, leaving it in the open…

I will try this later. Is re-pairing of the devices required or just a HA restart is enough?

UPDATE

  • Applied the quirk provided by @pluggedinn
  • Restarted HA
  • Devices received one additional sensor named Soil Moisture

The values are still funny

I’ll give it some time

1 Like

I had to delete the device and re-pair it yes. My values are pretty accurate for my room humidity (in this case showed as Soil temperature :roll_eyes:). Probably off by 2% from my other humidity sensors in my room.

1 Like

This quirk seems to be working better for me:
https://raw.githubusercontent.com/nschimme/zha-device-handlers/a9059575d5ec1ad1c43535f8fcec69830b38b15f/zhaquirks/tuya/tuya_sensor.py

Found Here:

It seems to get the humidity and soil moisture sensors correct.
It also adds a moisture alarm, and a bunch of configuration to calibrate the sensors.

I had to remove and re-pair after installing the quirk.