@@ -49,6 +49,7 @@ unsigned long last_mqtt_connected = 0;
49
49
// transitioning variables
50
50
float transition_time_s_standard = transition_time_s_conf;
51
51
float transition_time_s = transition_time_s_conf;
52
+ unsigned long now;
52
53
unsigned long last_transition_publish = 0 ;
53
54
unsigned long start_transition_loop_ms = 0 ;
54
55
unsigned long transition_ms = 0 ;
@@ -459,7 +460,7 @@ void publishJsonDiscovery() {
459
460
460
461
void publishJsonDiscovery_entity (const char type[], bool sup_color_temp, bool sup_rgb) {
461
462
StaticJsonDocument<JSON_BUFFER_SIZE> root;
462
- char idendifier[15 ], unique_id[27 ], entity_name[14 ], stat_t [27 ], cmd_t [27 ];
463
+ char idendifier[15 ], unique_id[29 ], entity_name[16 ], stat_t [29 ], cmd_t [29 ];
463
464
char conf_url[strlen (OTA_update_path)+25 ];
464
465
sprintf (idendifier, " H801_%s" , chip_id);
465
466
sprintf (unique_id, " H801_%s_%s" , chip_id, type);
@@ -514,7 +515,7 @@ void publishJsonDiscovery_entity(const char type[], bool sup_color_temp, bool su
514
515
char buffer[measureJson (root) + 1 ];
515
516
serializeJson (root, buffer, sizeof (buffer));
516
517
517
- char mqtt_discovery_topic[strlen (MQTT_HOMEASSISTANT_DISCOVERY_PREFIX) + 45 ];
518
+ char mqtt_discovery_topic[strlen (MQTT_HOMEASSISTANT_DISCOVERY_PREFIX) + 50 ];
518
519
sprintf (mqtt_discovery_topic, " %s/light/H801_%s/%s/config" , MQTT_HOMEASSISTANT_DISCOVERY_PREFIX, chip_id, type);
519
520
client.publish (mqtt_discovery_topic, buffer, true );
520
521
}
@@ -555,10 +556,11 @@ void callback(char* p_topic, byte* p_payload, unsigned int p_length) {
555
556
}
556
557
if (transition_time_s <= 0 ) {
557
558
setColor ();
559
+ publishRGBJsonState ();
558
560
} else {
559
561
Transition ();
562
+ // Let transition publish each 15s and @end
560
563
}
561
- publishRGBJsonState ();
562
564
}
563
565
564
566
// Handle White commands
@@ -569,10 +571,11 @@ void callback(char* p_topic, byte* p_payload, unsigned int p_length) {
569
571
}
570
572
if (transition_time_s <= 0 ) {
571
573
setWhite ();
574
+ publishWhiteJsonState ();
572
575
} else {
573
576
Transition ();
577
+ // Let transition publish each 15s and @end
574
578
}
575
- publishWhiteJsonState ();
576
579
}
577
580
578
581
// Handle White single 1 commands
@@ -583,10 +586,11 @@ void callback(char* p_topic, byte* p_payload, unsigned int p_length) {
583
586
}
584
587
if (transition_time_s <= 0 ) {
585
588
setWhite ();
589
+ publishWhiteSingle1JsonState ();
586
590
} else {
587
591
Transition ();
592
+ // Let transition publish each 15s and @end
588
593
}
589
- publishWhiteSingle1JsonState ();
590
594
}
591
595
592
596
// Handle White single 2 commands
@@ -597,10 +601,11 @@ void callback(char* p_topic, byte* p_payload, unsigned int p_length) {
597
601
}
598
602
if (transition_time_s <= 0 ) {
599
603
setWhite ();
604
+ publishWhiteSingle2JsonState ();
600
605
} else {
601
606
Transition ();
607
+ // Let transition publish each 15s and @end
602
608
}
603
- publishWhiteSingle2JsonState ();
604
609
}
605
610
606
611
// Handle combined commands
@@ -612,10 +617,11 @@ void callback(char* p_topic, byte* p_payload, unsigned int p_length) {
612
617
if (transition_time_s <= 0 ) {
613
618
setWhite ();
614
619
setColor ();
620
+ publishCombinedJsonState ();
615
621
} else {
616
622
Transition ();
623
+ // Let transition publish each 15s and @end
617
624
}
618
- publishCombinedJsonState ();
619
625
}
620
626
621
627
// Handle settings commands
@@ -796,7 +802,7 @@ bool processWhiteJson(char* message, bool single1, bool single2) {
796
802
m_w1 = brightness;
797
803
}
798
804
if (single2){
799
- m_w1 = brightness;
805
+ m_w2 = brightness;
800
806
}
801
807
}
802
808
}
@@ -1084,7 +1090,7 @@ void reconnect() {
1084
1090
1085
1091
void loop ()
1086
1092
{
1087
- unsigned long now = millis ();
1093
+ now = millis ();
1088
1094
if (WiFi.status () == WL_CONNECTED) {
1089
1095
// Confirm that still connected to MQTT broker
1090
1096
if (!client.connected ()) {
@@ -1122,9 +1128,9 @@ void loop()
1122
1128
client.publish (MQTT_UP, MQTT_UP_online, true );
1123
1129
}
1124
1130
// Process UDP messages if needed
1125
- UDP_loop (now );
1131
+ UDP_loop ();
1126
1132
// Process transitions if needed
1127
- Transition_loop (now );
1133
+ Transition_loop ();
1128
1134
}
1129
1135
1130
1136
@@ -1222,12 +1228,12 @@ void Transition(void) {
1222
1228
setW2 (transition_w2);
1223
1229
1224
1230
// Set variables for beginning transition
1225
- start_transition_loop_ms = millis () ;
1226
- last_transition_publish = 0 ;
1231
+ start_transition_loop_ms = now ;
1232
+ last_transition_publish = now ;
1227
1233
transitioning = true ;
1228
1234
}
1229
1235
1230
- void Transition_loop (unsigned long now ) {
1236
+ void Transition_loop () {
1231
1237
if (transitioning) {
1232
1238
transition_ms = now - start_transition_loop_ms;
1233
1239
@@ -1244,6 +1250,7 @@ void Transition_loop(unsigned long now) {
1244
1250
if (!UDP_stream) {
1245
1251
setWhite ();
1246
1252
setColor ();
1253
+ last_publish_ms = now;
1247
1254
publishCombinedJsonState ();
1248
1255
publishRGBJsonState ();
1249
1256
publishWhiteJsonState ();
@@ -1256,6 +1263,7 @@ void Transition_loop(unsigned long now) {
1256
1263
if (now - last_transition_publish > 15000 ) {
1257
1264
last_transition_publish = now;
1258
1265
if (!UDP_stream) {
1266
+ last_publish_ms = now;
1259
1267
publish_from_transition_state ();
1260
1268
}
1261
1269
}
@@ -1398,7 +1406,7 @@ void UDP_start_stop(void) {
1398
1406
}
1399
1407
}
1400
1408
1401
- void UDP_loop (unsigned long now ) {
1409
+ void UDP_loop () {
1402
1410
if (UDP_stream == true ) {
1403
1411
// check if there is an UDP message available
1404
1412
if (Udp.parsePacket ()) {
0 commit comments