forked from jackkitley/geyserwise_max_iot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geyser_v2.ino
675 lines (580 loc) · 19.5 KB
/
geyser_v2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <PubSubClient.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
// JSON configuration file
#define JSON_CONFIG_FILE "/config.json"
char mqtt_server[20] = "";
char mqtt_port[10] = "1883";
char mqtt_user[50] = "admin";
char mqtt_pass[50] = "";
#define pump_topic "stat/geyser/PUMP"
#define temp_topic "stat/geyser/TEMP"
#define collector_temp_topic "stat/geyser/COLLECTOR"
#define geyser_topic "stat/geyser/RESULT"
#define heat_topic "stat/geyser/POWER"
#define away_topic "stat/geyser/AWAY"
#define solar_diff_topic "stat/geyser/SOLARDIFF"
#define anti_freeze_topic "stat/geyser/ANTIFREEZE"
#define block1_topic "stat/geyser/BLOCK1"
#define block2_topic "stat/geyser/BLOCK2"
#define block3_topic "stat/geyser/BLOCK3"
#define block4_topic "stat/geyser/BLOCK4"
WiFiClient espClient;
PubSubClient client(espClient);
WiFiManager wifiManager;
//String header;
bool shouldSaveConfig = false;
bool gotMCUResponse = false;
void saveConfigCallback () {
Serial.println("Should save config");
shouldSaveConfig = true;
}
#define TUYA_MAX_LEN 98 // Max length of message value
#define TUYA_BUFFER_LEN 6 // Length of serial buffer for header + type + length
#define TUYA_HEADER_LEN 2 // Length of fixed header
//Wifi modes (AP-pairing, connected status, disconnected status)
#define NETWORK_CONNECTION_MODE_PAIRING { 0x01 }
#define NETWORK_CONNECTION_MODE_DISCONNECTED { 0x02 }
#define NETWORK_CONNECTION_MODE_CONNECTED { 0x04 }
/**
All the commands to set geyser
*/
#define HEAT { 0x01, 0x01, 0x00, 0x01, 0x00 } //dpid = 1, type = enum, len = 1, value = HEAT
#define HOLIDAY_MODE { 0x02, 0x04, 0x00, 0x01, 0x00 }
/**
Need to make degrees dynamic, last byte
*/
#define SOLAR_DIFF { 0x66, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //+ 1 byte (0x00)
#define ANTI_FREEZE { 0x6b, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //Set to 0 degrees
#define BLOCK_1 { 0x67, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //+ 1 byte (0x00)
#define BLOCK_2 { 0x68, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //+ 1 byte (0x00)
#define BLOCK_3 { 0x69, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //+ 1 byte (0x00)
#define BLOCK_4 { 0x6a, 0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00} //+ 1 byte (0x00)
uint8_t pump = 0;
uint8_t heating = 0;
uint8_t activeMode = 0;
uint8_t geyserTemp = 0;
uint8_t solarDiffTemp = 0;
uint8_t block1 = 0;
uint8_t block2 = 0;
uint8_t block3 = 0;
uint8_t block4 = 0;
uint8_t antiFreezeTemp = 0;
uint8_t collectorTemp = 0;
uint8_t elementHours = 0;
String geyserErrorCode = "";
static const uint16_t TUYA_HEADER = 0x55AA;
static const uint16_t TUYA_VERSION = 0x00;
static uint8_t heat[] = HEAT;
static uint8_t holiday_mode[] = HOLIDAY_MODE;
static uint8_t solar_diff[] = SOLAR_DIFF;
static uint8_t anti_freeze[] = ANTI_FREEZE;
static uint8_t block_1[] = BLOCK_1;
static uint8_t block_2[] = BLOCK_2;
static uint8_t block_3[] = BLOCK_3;
static uint8_t block_4[] = BLOCK_4;
static uint8_t network_connection_mode_pairing[] = NETWORK_CONNECTION_MODE_PAIRING;
static uint8_t network_connection_mode_connected[] = NETWORK_CONNECTION_MODE_CONNECTED;
static uint8_t network_connection_mode_disconnected[] = NETWORK_CONNECTION_MODE_DISCONNECTED;
#define HEARTBEAT_INTERVAL_MS 10000
unsigned long previousHeartbeatMillis = 0;
#define QUERY_INTERVAL_MS 1000
unsigned long previousQueryMillis = 0;
#define WIFI_CHECK_INTERVAL_MS 120000
unsigned long previousWifiCheckMillis = 0;
struct TuyaCommand
{
uint16_t header;
uint8_t version;
uint8_t command;
uint16_t length;
uint8_t value[TUYA_MAX_LEN];
uint8_t checksum;
};
enum TuyaCommandType
{
TUYA_HEARTBEAT = 0x00,
TUYA_WORKING_MODE = 0x02,
TUYA_NETWORK_STATUS = 0x03,
TUYA_PAIRING_MODE = 0x04,
TUYA_PAIRING_MODE_OPTION = 0x05,
TUYA_COMMAND = 0x06,
TUYA_RESPONSE = 0x07,
TUYA_QUERY_STATUS = 0x08
};
TuyaCommand command_{TUYA_HEADER, TUYA_VERSION, 0, 0, {}, 0};
uint8_t uart_buffer_[TUYA_BUFFER_LEN] {0};
bool readCommand();
void writeCommand(TuyaCommandType command, const uint8_t *value, uint16_t length);
uint8_t checksum();
//Safe guard for the temp drops in graphs.
uint8_t previousGeyserTemp = 0;
uint8_t previousCollectorTemp = 0;
char checksumStore;
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
loadConfigFile();
setupWifiManager();
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
isWifiConnected();
reconnectMqtt();
//Starts a web portal so that you can connect to your DHCP IP and still be able to upload new firmware or change wifi settings.
wifiManager.startWebPortal();
wifiManager.process();
unsigned long currentQueryMillis = millis();
if (currentQueryMillis - previousQueryMillis >= QUERY_INTERVAL_MS)
{
previousQueryMillis += QUERY_INTERVAL_MS;
Serial.println("Send QUERY");
writeCommand(TUYA_QUERY_STATUS, 0, 0);
}
unsigned long currentHeartbeatMillis = millis();
if (currentHeartbeatMillis - previousHeartbeatMillis >= HEARTBEAT_INTERVAL_MS)
{
previousHeartbeatMillis += HEARTBEAT_INTERVAL_MS;
Serial.println("Send HEARTBEAT");
writeCommand(TUYA_HEARTBEAT, 0, 0);
}
bool haveMessage = readCommand();
if (haveMessage) {
Serial.println("Read Command:");
Serial.println(command_.command);
}
if (haveMessage && command_.command == TUYA_HEARTBEAT)
{
Serial.println("HEARTBEAT_RESPONSE:");
Serial.println((command_.value[0] == 0) ? "FIRST_HEARTBEAT" : "HEARTBEAT");
} else if (haveMessage && command_.command == TUYA_RESPONSE && command_.length <= TUYA_MAX_LEN)
{
gotMCUResponse = true;
if (checksumStore != command_.checksum) {
setAndPublishGeyserData(command_.value);
publishGeyserTemps(command_.value);
checksumStore = command_.checksum;
}
} else if (haveMessage && (command_.command == TUYA_PAIRING_MODE || command_.command == TUYA_PAIRING_MODE_OPTION))
{
wifiManager.resetSettings();
ESP.restart();
}
digitalWrite(LED_BUILTIN, LOW);
}
void writeCommand(TuyaCommandType command, const uint8_t *value, uint16_t length)
{
// Copy params into command struct
command_.header = TUYA_HEADER;
command_.version = TUYA_VERSION;
command_.command = command;
command_.length = length;
Serial.println("COMMAND:");
Serial.println("Header:");
Serial.println(command_.header);
Serial.println("Version:");
Serial.println(command_.version);
Serial.println("Command:");
Serial.println(command_.command);
Serial.println("Data length:");
Serial.println(command_.length);
memcpy(&command_.value, value, length);
Serial.println("TX_RAW:");
for (size_t i = 0; i < command_.length; i++)
{
Serial.println(command_.value[i]);
}
// Copy struct values into buffer, converting longs to big-endian
uart_buffer_[0] = command_.header >> 8;
uart_buffer_[1] = command_.header & 0xFF;
uart_buffer_[2] = command_.version;
uart_buffer_[3] = command_.command;
uart_buffer_[4] = command_.length >> 8;
uart_buffer_[5] = command_.length & 0xFF;
command_.checksum = checksum();
Serial.println("Checksum:");
Serial.println(command_.checksum);
// Send buffer out via UART
Serial.write(uart_buffer_, TUYA_BUFFER_LEN);
Serial.write(command_.value, command_.length);
Serial.write(command_.checksum);
// Clear buffer contents to avoid re-reading our own payload
memset(uart_buffer_, 0, TUYA_BUFFER_LEN);
}
bool readCommand()
{
// Shift bytes through until we find a valid header
bool valid_header = false;
while (Serial.available() > 0)
{
uart_buffer_[0] = uart_buffer_[1];
uart_buffer_[1] = Serial.read();
command_.header = (uart_buffer_[0] << 8) + uart_buffer_[1];
if (command_.header == TUYA_HEADER)
{
valid_header = true;
break;
}
}
// Read the next 4 bytes (Version, Command, Data length)
// Read n bytes (Data length)
// Read the checksum byte
if (valid_header)
{
Serial.readBytes(uart_buffer_ + TUYA_HEADER_LEN, TUYA_BUFFER_LEN - TUYA_HEADER_LEN);
command_.version = uart_buffer_[2];
command_.command = uart_buffer_[3];
command_.length = (uart_buffer_[4] << 8) + uart_buffer_[5];
Serial.println("Command Length:");
Serial.println(command_.length);
if (command_.length <= TUYA_MAX_LEN)
{
Serial.readBytes(command_.value, command_.length);
// Serial.println("RX_RAW:");
// for (size_t i = 0; i < command_.length; i++)
// {
// Serial.println(command_.value[i]);
// }
while (Serial.available() == 0) // Dirty
{
//Wait
}
command_.checksum = Serial.read();
uint8_t calc_checksum = checksum();
if (calc_checksum == command_.checksum)
{
// Clear buffer contents to start with beginning of next command
memset(uart_buffer_, 0, TUYA_BUFFER_LEN);
return true;
}
else
{
memset(uart_buffer_, 0, TUYA_BUFFER_LEN);
}
}
else
{
memset(uart_buffer_, 0, TUYA_BUFFER_LEN);
}
}
// Do not clear buffer to allow for resume in case of reading partway through header RX
return false;
}
uint8_t checksum()
{
uint8_t checksum = 0;
for (size_t i = 0; i < TUYA_BUFFER_LEN; i++)
{
checksum += uart_buffer_[i];
}
for (size_t i = 0; i < command_.length; i++)
{
checksum += command_.value[i];
}
return checksum;
}
String errorCode(int error) {
switch (error) {
case 128:
return "E8"; //Collector probe error
case 64:
return "E7"; //Comm error
case 32:
return "E6"; //Water leak
case 16:
return "E5"; //Over temp
case 8:
return "E4"; //Heat failure
case 4:
return "E3"; //Water tank sensor error
case 2:
return "E2"; //Dry burn protection
case 1:
return "E1"; //Earth leakage
default:
return "";
}
}
void isWifiConnected() {
unsigned long currentWifiCheckMillis = millis();
if (currentWifiCheckMillis - previousWifiCheckMillis >= WIFI_CHECK_INTERVAL_MS)
{
if (WiFi.status() == WL_CONNECTED) {
writeCommand(TUYA_NETWORK_STATUS, network_connection_mode_connected, sizeof(network_connection_mode_connected));
} else {
writeCommand(TUYA_NETWORK_STATUS, network_connection_mode_disconnected, sizeof(network_connection_mode_disconnected));
}
previousWifiCheckMillis += WIFI_CHECK_INTERVAL_MS;
}
}
void setupWifiManager()
{
wifiManager.setDarkMode(true);
wifiManager.setScanDispPerc(true);
wifiManager.setHostname("GEYSER_CONTROLLER");
std::vector<const char *> menu = {"wifi", "info", "custom", "sep", "erase", "update", "restart"};
wifiManager.setMenu(menu);
WiFiManagerParameter custom_mqtt_server("server", "mqtt server", mqtt_server, 20);
WiFiManagerParameter custom_mqtt_port("port", "mqtt port", mqtt_port, 10);
WiFiManagerParameter custom_mqtt_user("user", "mqtt user", mqtt_user, 50);
WiFiManagerParameter custom_mqtt_pass("pass", "mqtt pass", mqtt_pass, 50, "type='password'");
//set config save notify callback
wifiManager.setSaveConfigCallback(saveConfigCallback);
//add all your parameters here
wifiManager.addParameter(&custom_mqtt_server);
wifiManager.addParameter(&custom_mqtt_port);
wifiManager.addParameter(&custom_mqtt_user);
wifiManager.addParameter(&custom_mqtt_pass);
bool res;
wifiManager.setConnectTimeout(180);
wifiManager.setConnectRetries(100);
if (wifiManager.getWiFiIsSaved()) wifiManager.setEnableConfigPortal(false);
res = wifiManager.autoConnect("AP_GEYSER");
if (res) {
writeCommand(TUYA_NETWORK_STATUS, network_connection_mode_connected, sizeof(network_connection_mode_connected));
} else {
writeCommand(TUYA_NETWORK_STATUS, network_connection_mode_pairing, sizeof(network_connection_mode_pairing));
}
strncpy(mqtt_server, custom_mqtt_server.getValue(), sizeof(mqtt_server));
strncpy(mqtt_port, custom_mqtt_port.getValue(), sizeof(mqtt_port));
strncpy(mqtt_user, custom_mqtt_user.getValue(), sizeof(mqtt_user));
strncpy(mqtt_pass, custom_mqtt_pass.getValue(), sizeof(mqtt_pass));
//save the custom parameters to FS
if (shouldSaveConfig) {
saveConfigFile();
}
Serial.println("local ip");
Serial.println(WiFi.localIP());
}
void saveConfigFile()
{
Serial.println(F("Saving configuration..."));
// Create a JSON document
StaticJsonDocument<512> json;
json["mqtt_server"] = mqtt_server;
json["mqtt_port"] = mqtt_port;
json["mqtt_user"] = mqtt_user;
json["mqtt_pass"] = mqtt_pass;
// Open config file
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "w");
if (!configFile)
{
// Error, file did not open
Serial.println("failed to open config file for writing");
}
// Serialize JSON data to write to file
serializeJsonPretty(json, Serial);
if (serializeJson(json, configFile) == 0)
{
// Error writing file
Serial.println(F("Failed to write to file"));
}
// Close file
configFile.close();
}
bool loadConfigFile()
// Load existing configuration file
{
// Read configuration from FS json
Serial.println("Mounting File System...");
// May need to make it begin(true) first time you are using SPIFFS
if (SPIFFS.begin()) {
Serial.println("mounted file system");
if (SPIFFS.exists(JSON_CONFIG_FILE))
{
// The file exists, reading and loading
Serial.println("reading config file");
File configFile = SPIFFS.open(JSON_CONFIG_FILE, "r");
if (configFile)
{
Serial.println("Opened configuration file");
StaticJsonDocument<512> json;
DeserializationError error = deserializeJson(json, configFile);
serializeJsonPretty(json, Serial);
if (!error)
{
Serial.println("Parsing JSON");
strcpy(mqtt_server, json["mqtt_server"]);
strcpy(mqtt_port, json["mqtt_port"]);
strcpy(mqtt_user, json["mqtt_user"]);
strcpy(mqtt_pass, json["mqtt_pass"]);
return true;
}
else
{
// Error loading JSON data
Serial.println("Failed to load json config");
}
}
}
} else {
Serial.println("** Failed to mount FS **");
}
return false;
}
void setAndPublishGeyserData(const uint8_t *geyserValues)
{
pump = geyserValues[33];
heating = geyserValues[4];
activeMode = geyserValues[9];
geyserErrorCode = errorCode(geyserValues[28]);
solarDiffTemp = geyserValues[41];
antiFreezeTemp = geyserValues[81];
block1 = geyserValues[49];
block2 = geyserValues[57];
block3 = geyserValues[65];
block4 = geyserValues[73];
elementHours = geyserValues[97];
StaticJsonDocument<200> doc;
doc["error"] = geyserErrorCode;
doc["solar_diff_temp"] = solarDiffTemp;
doc["anti_freeze_temp"] = antiFreezeTemp;
doc["block1_temp"] = block1;
doc["block2_temp"] = block2;
doc["block3_temp"] = block3;
doc["block4_temp"] = block4;
doc["element_hours"] = elementHours;
char buffer[256];
size_t n = serializeJson(doc, buffer);
client.publish(geyser_topic, buffer, n);
client.publish(heat_topic, heating ? "ON" : "OFF");
client.publish(away_topic, activeMode ? "OFF" : "ON");
client.publish(pump_topic, pump ? "ON" : "OFF");
}
void publishGeyserTemps(const uint8_t *geyserValues)
{
geyserTemp = geyserValues[17];
if ((previousGeyserTemp - geyserTemp) < 3) {
char tempAsString[32] = {0};
snprintf(tempAsString, sizeof(tempAsString), "%d", geyserTemp);
client.publish(temp_topic, tempAsString);
}
if (previousGeyserTemp != geyserTemp) {
previousGeyserTemp = geyserTemp;
}
collectorTemp = geyserValues[89];
if ((previousCollectorTemp - collectorTemp) < 3) {
char collectorTempAsString[32] = {0};
snprintf(collectorTempAsString, sizeof(collectorTempAsString), "%d", collectorTemp);
client.publish(collector_temp_topic, collectorTempAsString);
}
if (previousCollectorTemp != collectorTemp) {
previousCollectorTemp = collectorTemp;
}
}
void reconnectMqtt() {
// Loop until we're reconnected
while (!client.connected()) {
if (WiFi.status() == WL_CONNECTED) {
Serial.print("Attempting MQTT connection...");
Serial.println("Saved MQTT username:");
Serial.println(mqtt_user);
Serial.println("Saved MQTT password:");
Serial.println(mqtt_pass);
Serial.println("Saved MQTT server:");
Serial.println(mqtt_server);
Serial.println("Saved MQTT port:");
Serial.println(mqtt_port);
String clientId = "Client-";
clientId += String(random(0xffff), HEX);
client.setServer(mqtt_server, atoi(mqtt_port));
if (client.connect(clientId.c_str(), mqtt_user, mqtt_pass)) {
Serial.println("MQTT Connected");
client.setCallback(callback);
client.subscribe("cmnd/geyser/+");
client.publish("tele/geyser/LWT", "ONLINE");
} else {
Serial.println("Failed to connect to MQTT");
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
} else {
delay(5000);
}
}
client.loop();
}
char* toCharArray(String str) {
return &str[0];
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.println("Got a command from home assistant");
Serial.println();
payload[length] = '\0';
String message = (char*)payload;
int tempVal = message.toInt();
//Only enable writing commands if the MCU has responded after initial query else it throws everything out of sync with bad request order.
if (gotMCUResponse) {
if (strcmp(topic, "cmnd/geyser/solar_diff") == 0) {
if (tempVal >= 7 && tempVal <= 15) {
solar_diff[7] = tempVal;
client.publish(solar_diff_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, solar_diff, sizeof(solar_diff));
}
}
if (strcmp(topic, "cmnd/geyser/anti_freeze") == 0) {
if (tempVal >= 0 && tempVal <= 10) {
anti_freeze[7] = tempVal;
client.publish(anti_freeze_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, anti_freeze, sizeof(anti_freeze));
}
}
if (strcmp(topic, "cmnd/geyser/block1") == 0) {
if (tempVal >= 30 && tempVal <= 65) {
block_1[7] = tempVal;
client.publish(block1_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, block_1, sizeof(block_1));
}
}
if (strcmp(topic, "cmnd/geyser/block2") == 0) {
if (tempVal >= 30 && tempVal <= 65) {
block_2[7] = tempVal;
client.publish(block2_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, block_2, sizeof(block_2));
}
}
if (strcmp(topic, "cmnd/geyser/block3") == 0) {
if (tempVal >= 30 && tempVal <= 65) {
block_3[7] = tempVal;
client.publish(block3_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, block_3, sizeof(block_3));
}
}
if (strcmp(topic, "cmnd/geyser/block4") == 0) {
if (tempVal >= 30 && tempVal <= 65) {
block_4[7] = tempVal;
client.publish(block4_topic, toCharArray(message));
writeCommand(TUYA_COMMAND, block_4, sizeof(block_4));
}
}
if (strcmp(topic, "cmnd/geyser/power") == 0) {
if (message == "ON") {
heat[4] = 1;
writeCommand(TUYA_COMMAND, heat, sizeof(heat));
}
if (message == "OFF") {
heat[4] = 0;
writeCommand(TUYA_COMMAND, heat, sizeof(heat));
}
}
if (strcmp(topic, "cmnd/geyser/away") == 0) {
if (message == "ON") {
holiday_mode[4] = 0;
client.publish(away_topic, "ON");
writeCommand(TUYA_COMMAND, holiday_mode, sizeof(holiday_mode));
}
if (message == "OFF") {
holiday_mode[4] = 1;
client.publish(heat_topic, "OFF");
writeCommand(TUYA_COMMAND, holiday_mode, sizeof(holiday_mode));
}
}
if (strcmp(topic, "cmnd/geyser/wifi") == 0) {
wifiManager.resetSettings();
ESP.restart();
}
}
}