Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add humidity measurement #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/WThermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <DHT.h>
#include "WTuyaDevice.h"
#include "WClock.h"

Expand All @@ -17,6 +18,7 @@
#define MODEL_CALYPSOW 7
#define MODEL_DLX_LH01 8
#define PIN_STATE_HEATING_RELAY 5
#define PIN_DHT22 4 // DHT support
#define NOT_SUPPORTED 0x00

const char* SCHEDULES = "schedules";
Expand All @@ -28,6 +30,9 @@ const char* STATE_HEATING = "heating";
const char SCHEDULES_PERIODS[] = "123456";
const char SCHEDULES_DAYS[] = "wau";

DHT dht(PIN_DHT22, DHT22); // init DHT class


class WThermostat : public WTuyaDevice {
public :
WThermostat(WNetwork* network, WProperty* thermostatModel, WClock* wClock)
Expand Down Expand Up @@ -124,6 +129,14 @@ public :
this->state->addEnumString(STATE_HEATING);
this->addProperty(state);
}
this->humidity = nullptr;
this->supportingDHT22 = network()->settings()->setBoolean("supportingDHT22", true);
if (this->supportingDHT22->asBool()) {
dht.begin();
this->humidity = new WProperty("humidity", "Humidity", DOUBLE, TYPE_HUMIDITY_PROPERTY);
this->humidity->readOnly(true);
this->addProperty(humidity);
}
}

virtual void printConfigPage(AsyncWebServerRequest* request, Print* page) {
Expand Down Expand Up @@ -157,6 +170,8 @@ public :
page->printf(HTTP_CHECKBOX_OPTION, "am", "am", (this->notifyAllMcuCommands->asBool() ? HTTP_CHECKED : ""), "", "Send all MCU commands via MQTT");
//Checkbox with support for relay
page->printf(HTTP_CHECKBOX_OPTION, "rs", "rs", (this->supportingHeatingRelay->asBool() ? HTTP_CHECKED : ""), "", "Relay at GPIO 5 (not working without hw mod)");
//Checkbox for DHT22
page->printf(HTTP_CHECKBOX_OPTION, "dt", "dt", (this->supportingDHT22->asBool() ? HTTP_CHECKED : ""), "", "DHT22 at GPIO 4 (not working without hw mod)");

printConfigPageCustomParameters(request, page);

Expand All @@ -174,6 +189,7 @@ public :
this->completeDeviceState->asBool(request->arg("cr") != HTTP_TRUE);
this->notifyAllMcuCommands->asBool(request->arg("am") == HTTP_TRUE);
this->supportingHeatingRelay->asBool(request->arg("rs") == HTTP_TRUE);
this->supportingDHT22->asBool(request->arg("dt") == HTTP_TRUE);
submitConfigPageCustomParameters(request, page);
}

Expand Down Expand Up @@ -308,6 +324,13 @@ public :
}
this->state->asString(heating ? STATE_HEATING : STATE_OFF);
}
if (humidity != nullptr) {
double humidity = 1.0;
if (this->supportingDHT22->asBool()) {
humidity = dht.readHumidity(); //FEHLER !!!
}
this->humidity->asDouble(humidity);//String(humidity, 1));
}
WTuyaDevice::loop(now);
updateCurrentSchedulePeriod();
if (receivedSchedules()) {
Expand Down Expand Up @@ -351,7 +374,9 @@ protected :
WProperty* switchBackToAuto;
WProperty* locked;
WProperty* state;
WProperty* humidity;
WProperty* supportingHeatingRelay;
WProperty* supportingDHT22;
byte schedules[54];

void sendActualTimeToBeca() {
Expand Down