OK - I'm not sure what's actually wrong here, but I'm very tired of going around in circles.
The project - use an ESP32 C6 as a zigbee remote.
The method - use the Zigbee.h library to send a code via the temperature broadcast so that a keypress can be determined. A converter at the Home Assistant/Z2M end turns it into a slightly different entity.
It did work yesterday, but doesn't now.
The partition is Zigbee 4MS with SPIFFS, Zigbee mode is end device.
What works ... the program pairs with HA and the conversion is loaded. Keypresses on the device itself work.
What doesn't work... packets don't seem to be transmitted to HA. The Z2M log doesn't show anything coming in. Most likely that the C6 is sending packets, but HA is likely ignoring them, or some form of formatting error.
I'm lost now.
Converter...
import * as exposes from 'zigbee-herdsman-converters/lib/exposes';
import * as fz from 'zigbee-herdsman-converters/converters/fromZigbee';
const e = exposes.presets;
const ea = exposes.access;
const keypadState = {
cluster: 'msTemperatureMeasurement',
type: ['attributeReport', 'readResponse'],
convert: (model, msg) => {
const raw = msg.data?.measuredValue;
if (raw === undefined) return {};
return { keypad_state: raw / 100 };
},
};
export default {
zigbeeModel: ['RS10_Remote'],
model: 'RS10_Remote',
vendor: 'SeeedC6-RS10',
description: 'RS10 keypad remote',
fromZigbee: [keypadState],
toZigbee: [],
exposes: [
e.numeric('keypad_state', ea.STATE)
.withDescription('Last pressed key index'),
],
};
Current Arduino code...
#include "Arduino.h"
#include "Zigbee.h"
const char* DEVICE_NAME = "RS10_Remote";
const int ROWS = 5;
const int COLS = 4;
int rowPins[ROWS] = {16, 17, 19, 20, 18};
int colPins[COLS] = {2, 21, 22, 23};
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'},
{'E','F','G','H'}
};
const int LED_PIN = 1;
const uint8_t ENDPOINT = 10;
ZigbeeTempSensor zbTempSensor(ENDPOINT);
const char keyList[20] = {
'1','2','3','A',
'4','5','6','B',
'7','8','9','C',
'*','0','#','D',
'E','F','G','H'
};
uint8_t keyToIndex(char key) {
for (uint8_t i = 0; i < 20; i++) {
if (keyList[i] == key) return i + 1;
}
return 0;
}
void sendKey(char key)
{
uint8_t idx = keyToIndex(key);
if (idx == 0) return;
Serial.print("Key: ");
Serial.print(key);
Serial.print(" idx: ");
Serial.println(idx);
zbTempSensor.setTemperature((float)idx);
zbTempSensor.reportTemperature();
delay(100);
}
void factoryResetAndReboot() {
Serial.println("Factory reset requested");
digitalWrite(LED_PIN, LOW);
Zigbee.factoryReset();
delay(1000);
ESP.restart();
}
void setup() {
Serial.begin(115200);
delay(1000);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
for (int r = 0; r < ROWS; r++) {
pinMode(rowPins[r], OUTPUT);
digitalWrite(rowPins[r], HIGH);
}
for (int c = 0; c < COLS; c++) {
pinMode(colPins[c], INPUT_PULLUP);
}
zbTempSensor.setManufacturerAndModel("SeeedC6-RS10", "RS10_Remote");
zbTempSensor.setMinMaxValue(1, 20);
zbTempSensor.setDefaultValue(1.0);
zbTempSensor.setTolerance(1.0);
zbTempSensor.setPowerSource(ZB_POWER_SOURCE_BATTERY, 100, 35);
zbTempSensor.addTimeCluster();
Zigbee.addEndpoint(&zbTempSensor);
Serial.println("Starting Zigbee...");
if (!Zigbee.begin()) {
Serial.println("Zigbee failed to start!");
ESP.restart();
}
Serial.println("Connecting to network");
while (!Zigbee.connected()) {
Serial.print(".");
delay(100);
}
Serial.println();
Serial.println("Successfully connected to Zigbee network");
}
void loop() {
for (int r = 0; r < ROWS; r++) {
digitalWrite(rowPins[r], LOW);
for (int c = 0; c < COLS; c++) {
if (digitalRead(colPins[c]) == LOW) {
delay(20);
if (digitalRead(colPins[c]) == LOW) {
char key = keys[r][c];
bool isOneKey = (key == '1');
digitalWrite(LED_PIN, HIGH);
sendKey(key);
unsigned long pressedAt = millis();
while (digitalRead(colPins[c]) == LOW) {
if (isOneKey && (millis() - pressedAt >= 5000)) {
factoryResetAndReboot();
}
delay(10);
}
digitalWrite(LED_PIN, LOW);
}
}
}
digitalWrite(rowPins[r], HIGH);
}
delay(10);
}

