From 12f603cc59fb94c121d91a63b36f7e781e7b8d90 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 6 Feb 2020 12:42:31 +0100 Subject: [PATCH] Add support for sensor DHT family using Shelly Add-On - Fix Hass sensor discovery part 1/4 by Federico Leoni (#7582, #7548) - Add support for sensor DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) --- RELEASENOTES.md | 2 ++ tasmota/CHANGELOG.md | 2 ++ tasmota/tasmota_template.h | 4 +++- tasmota/xsns_06_dht.ino | 42 +++++++++++++++++++++++++++++++------- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 381bea521..f4a02d9f0 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -70,6 +70,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Fix ``PowerDelta`` zero power detection (#7515) - Fix ``RGBWWTable`` ignored (#7572) - Fix PWM flickering at low levels (#7415) +- Fix Hass sensor discovery part 1/4 by Federico Leoni (#7582, #7548) - Add command ``SetOption79 0/1`` to enable reset of counters at teleperiod time by Andre Thomas (#7355) - Add command ``SetOption82 0/1`` to limit the CT range for Alexa to 200..380 - Add command ``SetOption84 1`` to send AWS IoT device shadow updates (alternative to retained) @@ -90,3 +91,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add optional parameter to command ``Scheme , `` to control initial start color - Add rule trigger on one level deeper using syntax with two ``#`` like ``on zigbeereceived#vibration_sensor#aqaracubeside=0 do ...`` - Add support for sensor DS18x20 on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) +- Add support for sensor DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 008a8460c..3ea8c832c 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -2,7 +2,9 @@ ### 8.1.0.6 20200205 +- Fix Hass sensor discovery part 1/4 by Federico Leoni (#7582, #7548) - Add support for sensor DS18x20 on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) +- Add support for sensor DHT family on Shelly 1 and Shelly 1PM using Shelly Add-On adapter (#7469) ### 8.1.0.5 20200126 diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 0067b628f..59c09e177 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -217,6 +217,7 @@ enum UserSelectablePins { GPIO_GPS_RX, // GPS serial interface GPIO_GPS_TX, // GPS serial interface GPIO_DSB_OUT, // Pseudo Single wire DS18B20 or DS18S20 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 GPIO_SENSOR_END }; // Programmer selectable GPIO functionality @@ -298,7 +299,7 @@ const char kSensorNames[] PROGMEM = D_SENSOR_SLAVE_TX "|" D_SENSOR_SLAVE_RX "|" D_SENSOR_SLAVE_RESET "|" D_SENSOR_SLAVE_RESET "i|" D_SENSOR_HPMA_RX "|" D_SENSOR_HPMA_TX "|" D_SENSOR_GPS_RX "|" D_SENSOR_GPS_TX "|" - D_SENSOR_DS18X20 "o|" + D_SENSOR_DS18X20 "o|" D_SENSOR_DHT11 "o|" ; const char kSensorNamesFixed[] PROGMEM = @@ -561,6 +562,7 @@ const uint8_t kGpioNiceList[] PROGMEM = { GPIO_DHT11, // DHT11 GPIO_DHT22, // DHT21, DHT22, AM2301, AM2302, AM2321 GPIO_SI7021, // iTead SI7021 + GPIO_DHT11_OUT, // Pseudo Single wire DHT11, DHT21, DHT22, AM2301, AM2302, AM2321 #endif #ifdef USE_DS18x20 GPIO_DSB, // Single wire DS18B20 or DS18S20 diff --git a/tasmota/xsns_06_dht.ino b/tasmota/xsns_06_dht.ino index 1c45a550e..c8c3dccd7 100644 --- a/tasmota/xsns_06_dht.ino +++ b/tasmota/xsns_06_dht.ino @@ -34,7 +34,9 @@ uint32_t dht_max_cycles; uint8_t dht_data[5]; uint8_t dht_sensors = 0; +uint8_t dht_pin_out = 0; // Shelly GPIO00 output only bool dht_active = true; // DHT configured +bool dht_dual_mode = false; // Single pin mode struct DHTSTRUCT { uint8_t pin; @@ -49,7 +51,11 @@ struct DHTSTRUCT { void DhtReadPrep(void) { for (uint32_t i = 0; i < dht_sensors; i++) { - digitalWrite(Dht[i].pin, HIGH); + if (!dht_dual_mode) { + digitalWrite(Dht[i].pin, HIGH); + } else { + digitalWrite(dht_pin_out, HIGH); + } } } @@ -77,11 +83,19 @@ bool DhtRead(uint8_t sensor) if (Dht[sensor].lastresult > DHT_MAX_RETRY) { Dht[sensor].lastresult = 0; - digitalWrite(Dht[sensor].pin, HIGH); // Retry read prep + if (!dht_dual_mode) { + digitalWrite(Dht[sensor].pin, HIGH); // Retry read prep + } else { + digitalWrite(dht_pin_out, HIGH); + } delay(250); } - pinMode(Dht[sensor].pin, OUTPUT); - digitalWrite(Dht[sensor].pin, LOW); + if (!dht_dual_mode) { + pinMode(Dht[sensor].pin, OUTPUT); + digitalWrite(Dht[sensor].pin, LOW); + } else { + digitalWrite(dht_pin_out, LOW); + } if (GPIO_SI7021 == Dht[sensor].type) { delayMicroseconds(500); @@ -90,9 +104,14 @@ bool DhtRead(uint8_t sensor) } noInterrupts(); - digitalWrite(Dht[sensor].pin, HIGH); - delayMicroseconds(40); - pinMode(Dht[sensor].pin, INPUT_PULLUP); + if (!dht_dual_mode) { + digitalWrite(Dht[sensor].pin, HIGH); + delayMicroseconds(40); + pinMode(Dht[sensor].pin, INPUT_PULLUP); + } else { + digitalWrite(dht_pin_out, HIGH); + delayMicroseconds(40); + } delayMicroseconds(10); if (-1 == DhtExpectPulse(sensor, LOW)) { AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE)); @@ -109,6 +128,7 @@ bool DhtRead(uint8_t sensor) } } interrupts(); + if (error) { return false; } for (uint32_t i = 0; i < 40; ++i) { @@ -187,6 +207,13 @@ void DhtInit(void) if (dht_sensors) { dht_max_cycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor. + if (pin[GPIO_DHT11_OUT] < 99) { + dht_pin_out = pin[GPIO_DHT11_OUT]; + dht_dual_mode = true; // Dual pins mode as used by Shelly + dht_sensors = 1; // We only support one sensor in pseudo mode + pinMode(dht_pin_out, OUTPUT); + } + for (uint32_t i = 0; i < dht_sensors; i++) { pinMode(Dht[i].pin, INPUT_PULLUP); Dht[i].lastreadtime = 0; @@ -196,6 +223,7 @@ void DhtInit(void) snprintf_P(Dht[i].stype, sizeof(Dht[i].stype), PSTR("%s%c%02d"), Dht[i].stype, IndexSeparator(), Dht[i].pin); } } + AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_SENSORS_FOUND " %d"), dht_sensors); } else { dht_active = false; }