@@ -1561,22 +1561,34 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
1561
1561
return ; // not supported
1562
1562
}
1563
1563
1564
+ static uint8_t setTimeRetry = 0 ;
1565
+ uint8_t dst = 0xFE ;
1566
+ bool use_dst = !telegram->read_value (dst, 9 ) || dst == 0xFF ;
1564
1567
if ((telegram->message_data [7 ] & 0x0C ) && has_command (&dateTime_)) { // date and time not valid
1565
- set_datetime (" ntp" , -1 ); // set from NTP
1568
+ if (setTimeRetry < 3 ) {
1569
+ if (!use_dst) {
1570
+ set_datetime (" ntp" , 0 ); // set from NTP without dst
1571
+ } else {
1572
+ set_datetime (" ntp" , -1 ); // set from NTP
1573
+ }
1574
+ setTimeRetry++;
1575
+ }
1566
1576
return ;
1567
1577
}
1568
1578
1569
1579
// check clock
1570
- time_t now = time (nullptr );
1571
- tm * tm_ = localtime (&now);
1572
- bool tset_ = tm_->tm_year > 110 ; // year 2010 and up, time is valid
1573
- tm_->tm_year = (telegram->message_data [0 ] & 0x7F ) + 100 ; // IVT
1574
- tm_->tm_mon = telegram->message_data [1 ] - 1 ;
1575
- tm_->tm_mday = telegram->message_data [3 ];
1576
- tm_->tm_hour = telegram->message_data [2 ];
1577
- tm_->tm_min = telegram->message_data [4 ];
1578
- tm_->tm_sec = telegram->message_data [5 ];
1579
- tm_->tm_isdst = telegram->message_data [7 ] & 0x01 ;
1580
+ time_t now = time (nullptr );
1581
+ tm * tm_ = localtime (&now);
1582
+ bool tset_ = tm_->tm_year > 110 ; // year 2010 and up, time is valid
1583
+ tm_->tm_year = (telegram->message_data [0 ] & 0x7F ) + 100 ; // IVT
1584
+ tm_->tm_mon = telegram->message_data [1 ] - 1 ;
1585
+ tm_->tm_mday = telegram->message_data [3 ];
1586
+ tm_->tm_hour = telegram->message_data [2 ];
1587
+ tm_->tm_min = telegram->message_data [4 ];
1588
+ tm_->tm_sec = telegram->message_data [5 ];
1589
+ if (use_dst) {
1590
+ tm_->tm_isdst = telegram->message_data [7 ] & 0x01 ;
1591
+ }
1580
1592
1581
1593
// render date to DD.MM.YYYY HH:MM and publish
1582
1594
char newdatetime[sizeof (dateTime_)];
@@ -1590,8 +1602,17 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
1590
1602
if (!ivtclock && !junkersclock && tset_ && EMSESP::system_.ntp_connected () && !EMSESP::system_.readonly_mode () && has_command (&dateTime_)) {
1591
1603
double difference = difftime (now, ttime);
1592
1604
if (difference > 15 || difference < -15 ) {
1593
- set_datetime (" ntp" , -1 ); // set from NTP
1594
- LOG_INFO (" thermostat time correction from ntp" );
1605
+ if (setTimeRetry < 3 ) {
1606
+ if (!use_dst) {
1607
+ set_datetime (" ntp" , 0 ); // set from NTP without dst
1608
+ } else {
1609
+ set_datetime (" ntp" , -1 ); // set from NTP
1610
+ }
1611
+ LOG_INFO (" thermostat time correction from ntp" );
1612
+ setTimeRetry++;
1613
+ }
1614
+ } else {
1615
+ setTimeRetry = 0 ;
1595
1616
}
1596
1617
}
1597
1618
#ifndef EMSESP_STANDALONE
@@ -2685,8 +2706,8 @@ bool Thermostat::set_datetime(const char * value, const int8_t id) {
2685
2706
data[3 ] = tm_->tm_mday ;
2686
2707
data[4 ] = tm_->tm_min ;
2687
2708
data[5 ] = tm_->tm_sec ;
2688
- data[6 ] = (tm_->tm_wday + 6 ) % 7 ; // Bosch counts from Mo, time from Su
2689
- data[7 ] = tm_->tm_isdst + 2 ; // set DST and flag for ext. clock
2709
+ data[6 ] = (tm_->tm_wday + 6 ) % 7 ; // Bosch counts from Mo, time from Su
2710
+ data[7 ] = (id == 0 ) ? 2 : tm_->tm_isdst + 2 ; // set DST and flag for ext. clock
2690
2711
if (model () == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) {
2691
2712
data[6 ]++; // Junkers use 1-7;
2692
2713
data[7 ] = 0 ;
0 commit comments