Skip to content

Device with multiple temperature sensors #31172

@Jan-WillemArnold

Description

@Jan-WillemArnold

What happened?

Hi, I am building an ESP device (with Arduino code) that provides data from three different temperature sensors. Each sensor is on its own endpoint. I am using ModernExtend to define the external converter. I have declared the endpoints by 'deviceEndpoints', giving them a friendly name and the numeric ID.

When I look into the 'exposes' screen from the device in Z2MQTT I see the first device updating its temperature automatically as expected. The second and third device however are not being updated.

Looking into the code of ModernExtend.ts it becomes clear that in several places only the first occurrence of the corresponding cluster is being used. So that seems to explain that it does not work.

Unfortunately the code of modern extend.ts is not easy to understand completely and difficult to adapt.

Thanks,

Jan-Willem

What did you expect to happen?

I expect that as I have declared the endpoints with a name, corresponding to the numeric ID, that provides enough information to update all three sensors automatically.

How to reproduce it (minimal and precise)

The external converter:

import * as m from 'zigbee-herdsman-converters/lib/modernExtend';

export default {
    zigbeeModel: ['delarte-fancontroller'],
    model: 'delarte-fancontroller',
    vendor: 'delArte',
    description: 'ESP32-C6 fan controller',
    meta: { multiEndpoint: true },
    extend: [
        m.deviceEndpoints({
            "endpoints":{
                "environment_temperature":11,
                "inflow_temperature":12,
                "outflow_temperature":13,
                "fan":10}
        }),
        m.temperature({
            "endpointNames": ["environment_temperature"],
            "description": "Environment temperature",
        }),
        m.temperature({
            "endpointNames": ["inflow_temperature"],
            "description": "Inflowing water temperature",
        }),
        m.temperature({
            "endpointNames": ["outflow_temperature"],
            "description": "Outflowing water temperature",
        }),
    ],
};

Arduino code

#ifndef ZIGBEE_MODE_ZCZR
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
#endif

// Zigbee
#include "ZigbeeCore.h"
#include "ep/ZigbeeTempSensor.h"

#define LED_PIN RGB_BUILTIN
#define BUTTON_PIN 9  // ESP32-C6/H2 Boot button

#define ENV_TEMP_SENSOR_ENDPOINT_NUMBER 11
#define INFLOW_TEMP_SENSOR_ENDPOINT_NUMBER 12
#define OUTFLOW_TEMP_SENSOR_ENDPOINT_NUMBER 13

#define TEMP_SENSOR_ENDPOINT_NUMBER 10

#ifdef RGB_BUILTIN
uint8_t led = RGB_BUILTIN;  // To demonstrate the current fan control mode
#else
uint8_t led = 2;
#endif

uint8_t button = BOOT_PIN;

ZigbeeTempSensor zbEnvTempSensor = ZigbeeTempSensor(ENV_TEMP_SENSOR_ENDPOINT_NUMBER);
ZigbeeTempSensor zbInFlowTempSensor = ZigbeeTempSensor(INFLOW_TEMP_SENSOR_ENDPOINT_NUMBER);
ZigbeeTempSensor zbOutFlowTempSensor = ZigbeeTempSensor(OUTFLOW_TEMP_SENSOR_ENDPOINT_NUMBER);

const char* manufacturer = "delArte";
const char* model = "delarte-fancontroller";

float counter = 10;

/************************ Temp sensor *****************************/
static void temp_sensor_value_update(void* arg) {
  for (;;) {
    // a counter is being used for testing instead of a temp sensor.
     counter = counter + 0.1;
    Serial.print("Temp sensor value update: ");
    Serial.println(counter);
   vTaskDelay(1000);
   zbEnvTempSensor.setTemperature(counter);
   zbInFlowTempSensor.setTemperature(counter);
   zbOutFlowTempSensor.setTemperature(counter);

  }
}

void registerTempSensor(ZigbeeTempSensor zbTempSensor) {
  // Optional: set Zigbee device name and model
  zbTempSensor.setManufacturerAndModel(manufacturer, model);

  zbTempSensor.setPowerSource(ZB_POWER_SOURCE_MAINS);

  // Set minimum and maximum temperature measurement value (10-50°C is default range for chip temperature measurement)
  zbTempSensor.setMinMaxValue(10, 50);

  // Optional: Set default (initial) value for the temperature sensor to 10.0°C to match the minimum temperature measurement value
  zbTempSensor.setDefaultValue(11.0);

  // Optional: Set tolerance for temperature measurement in °C (lowest possible value is 0.01°C)
  zbTempSensor.setTolerance(0.1);

  //zbTempSensor.setManualBinding(true);

  // Optional: Time cluster configuration (default params, as this device will revieve time from coordinator)
  zbTempSensor.addTimeCluster();

  // Add endpoint to Zigbee Core
  Serial.println("Adding ZigbeeTempSensor endpoint to Zigbee Core");
  Zigbee.addEndpoint(&zbTempSensor);

}


void setup() {

  Serial.begin(115200);
  Serial.println("Initalizing Fan Controller");


  // Init LED that will be used to indicate the current fan control mode
  rgbLedWrite(led, 1, 1, 1);

  // Init button for factory reset
  pinMode(button, INPUT_PULLUP);

  registerTempSensor(zbEnvTempSensor);
  registerTempSensor(zbInFlowTempSensor);
  registerTempSensor(zbOutFlowTempSensor);

  // When all EPs are registered, start Zigbee in ROUTER mode
  if (!Zigbee.begin(ZIGBEE_ROUTER)) {
    Serial.println("Zigbee failed to start!");
    Serial.println("Rebooting...");
    ESP.restart();
  }
  Serial.println("Connecting to network");
  while (!Zigbee.connected()) {
    Serial.print(".");
    delay(100);
  }
  if (Zigbee.connected()) {
    Serial.println("Connection established");
    Serial.print("Role in network: ");
    Serial.println(Zigbee.getRole());
    Serial.print("manufacturer: ");
    Serial.println(manufacturer);
    Serial.print("model: ");
    Serial.println(model);
  }
  Serial.println();

  // Start Temperature sensor reading task
  xTaskCreate(temp_sensor_value_update, "temp_sensor_value_update", 2048, NULL, 10, NULL);
  delay(200);
  zbEnvTempSensor.setReporting(2, 5, 1);
  zbInFlowTempSensor.setReporting(2, 5, 1);
  zbOutFlowTempSensor.setReporting(2, 5, 1); 

  rgbLedWrite(led, 20, 20, 0);
}

void loop() {
  // Checking button for factory reset
  if (digitalRead(button) == LOW) {  // Push button pressed
    // Key debounce handling
    delay(100);
    int startTime = millis();
    while (digitalRead(button) == LOW) {
      delay(50);
      if ((millis() - startTime) > 3000) {
        // If key pressed for more than 3secs, factory reset Zigbee and reboot
        Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
        delay(1000);
        Zigbee.factoryReset();
      }
    }
  }
  delay(100);

    // aggressively updating the sensors
    // with a small delay to avoid possible congestion
    delay(200);
    zbEnvTempSensor.reportTemperature();
    delay(200);
    zbInFlowTempSensor.reportTemperature();
    delay(200);
    zbOutFlowTempSensor.reportTemperature();

}

Zigbee2MQTT version

2.8.0

Adapter firmware version

Revision: 7.4.4 [GA]

Adapter

ZBT-2

Setup

  • Home Assistant on Odroid M1 8GB
  • Modbus RS485 converter on USB
  • P1 meter on USB
  • about 30 wireless device Zigbee
  • ZB2 Zigbee
  • Z2MQTT as add-on
  • ESP32 C6

Device database.db entry

No response

Debug log

None.

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    problemSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions