Skip to content

Commit dceabb7

Browse files
committed
Enhance SEN6x driver with CO2 light control (SO18)
1 parent 6895d24 commit dceabb7

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

tasmota/tasmota_support/support.ino

100755100644
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ void TasAutoMutex::take() {
239239
/*********************************************************************************************\
240240
* Miscellaneous
241241
\*********************************************************************************************/
242+
243+
void PowerOnDelay(uint32_t msecs) {
244+
if (ResetReasonPowerOn()) {
245+
while (millis() < msecs) {
246+
delay(1);
247+
}
248+
}
249+
}
250+
242251
/*
243252
String GetBinary(const void* ptr, size_t count) {
244253
uint32_t value = *(uint32_t*)ptr;

tasmota/tasmota_xsns_sensor/xsns_119_sen6x.ino

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
xsns_119_sen6x.ino - SEN6X environmental sensor node support for Tasmota
2+
xsns_119_sen6x.ino - Sensirion SEN6X environmental sensor node support for Tasmota
33
44
SPDX-FileCopyrightText: 2026 Theo Arends
55
@@ -123,6 +123,7 @@ bool CmndSen6xError(int error) {
123123
/********************************************************************************************/
124124

125125
void Sen6xInit(void) {
126+
PowerOnDelay(100); // Sensor startup time (Time after power-on until I2C communication can be started)
126127
for (uint32_t bus = 0; bus < 2; bus++) {
127128
if (!I2cSetDevice(SEN6X_I2C_ADDR_6B, bus)) {
128129
// Sen6xError("Scan", bus +1);
@@ -155,12 +156,10 @@ void Sen6xInit(void) {
155156
SEN6XDATA->major = major;
156157
SEN6XDATA->minor = minor;
157158
SEN6XDATA->state = SEN6X_STATE_START_MEASUREMENT;
158-
strlcpy(SEN6XDATA->name, (char*)product_name, sizeof(SEN6XDATA->name));
159-
char stemp[8];
160-
uint32_t model = GetCommandCode(stemp, sizeof(stemp), SEN6XDATA->name, mSenNames);
161-
SEN6XDATA->model = model +62;
159+
uint32_t model = GetCommandCode(SEN6XDATA->name, sizeof(SEN6XDATA->name), (char*)product_name, mSenNames);
162160
uint8_t features[] = { 0, 2, 0, 1, 3, 0, 6, 7 }; // x x x x x hcho co2 voc
163161
SEN6XDATA->features = features[model];
162+
SEN6XDATA->model = model +62;
164163

165164
I2cSetActiveFound(SEN6X_I2C_ADDR_6B, SEN6XDATA->name, bus);
166165

@@ -459,21 +458,22 @@ void Sen6xShow(bool json) {
459458
abs_humidity = CalcTempHumToAbsHum(ambientTemperature, ambientHumidity);
460459
}
461460

461+
#ifdef USE_LIGHT
462+
LightSetSignal(CO2_LOW, CO2_HIGH, co2); // SetOption18 - Pair light signal with CO2 sensor
463+
#endif // USE_LIGHT
464+
462465
if (json) {
463466
ResponseAppend_P(PSTR(",\"%s\":{\"PM1\":%1_f,\"PM2.5\":%1_f,\"PM4\":%1_f,\"PM10\":%1_f"),
464467
SEN6XDATA->name,
465468
&massConcentrationPm1p0, &massConcentrationPm2p5, &massConcentrationPm4p0, &massConcentrationPm10p0);
466-
if (!isnan(co2)) {
469+
if (SEN6XDATA->features & SEN6X_CO2) {
467470
ResponseAppend_P(PSTR(",\"" D_JSON_CO2 "\":%0_f"), &co2);
468471
}
469-
if (!isnan(hcho)) {
472+
if (SEN6XDATA->features & SEN6X_HCHO) {
470473
ResponseAppend_P(PSTR(",\"" D_JSON_HCHO "\":%0_f"), &hcho);
471474
}
472-
if (!isnan(noxIndex)) {
473-
ResponseAppend_P(PSTR(",\"NOx\":%0_f"), &noxIndex);
474-
}
475-
if (!isnan(vocIndex)) {
476-
ResponseAppend_P(PSTR(",\"VOC\":%0_f"), &vocIndex);
475+
if (SEN6XDATA->features & SEN6X_VOCNOX) {
476+
ResponseAppend_P(PSTR(",\"NOx\":%0_f,\"VOC\":%0_f"), &noxIndex, &vocIndex);
477477
}
478478
if (ahum_available) {
479479
ResponseAppend_P(PSTR(","));
@@ -487,16 +487,14 @@ void Sen6xShow(bool json) {
487487
WSContentSend_PD(HTTP_SNS_F_ENVIRONMENTAL_CONCENTRATION, SEN6XDATA->name, "2.5", &massConcentrationPm2p5);
488488
WSContentSend_PD(HTTP_SNS_F_ENVIRONMENTAL_CONCENTRATION, SEN6XDATA->name, "4", &massConcentrationPm4p0);
489489
WSContentSend_PD(HTTP_SNS_F_ENVIRONMENTAL_CONCENTRATION, SEN6XDATA->name, "10", &massConcentrationPm10p0);
490-
if (!isnan(co2)) {
490+
if (SEN6XDATA->features & SEN6X_CO2) {
491491
WSContentSend_PD(HTTP_SNS_F_CO2, SEN6XDATA->name, &co2);
492492
}
493-
if (!isnan(hcho)) {
493+
if (SEN6XDATA->features & SEN6X_HCHO) {
494494
WSContentSend_PD(HTTP_SNS_F_HCHO, SEN6XDATA->name, &hcho);
495495
}
496-
if (!isnan(noxIndex)) {
496+
if (SEN6XDATA->features & SEN6X_VOCNOX) {
497497
WSContentSend_PD(HTTP_SNS_F_NOX, SEN6XDATA->name, &noxIndex);
498-
}
499-
if (!isnan(vocIndex)) {
500498
WSContentSend_PD(HTTP_SNS_F_VOC, SEN6XDATA->name, &vocIndex);
501499
}
502500
if (ahum_available) {

0 commit comments

Comments
 (0)