Updated sthome-ut8 towards being in line with PCB versions

This commit is contained in:
Chris Stuurman 2025-10-25 14:43:48 +02:00
parent 1c2e9342ee
commit d859cd620b
4 changed files with 823 additions and 433 deletions

View File

@ -174,7 +174,6 @@ globals:
type: time_t
initial_value: '0'
restore_value: yes
# CAN BUS
- id: can1_msgctr
type: int
restore_value: no
@ -188,7 +187,6 @@ globals:
type: std::queue< std::set<uint32_t> >
restore_value: no
esp32:
board: esp32dev
framework:
@ -2461,6 +2459,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device1
name: "Inv1 BatteryPower"
id: inv1_batterypower
register_type: holding
address: ${Felicity_Inv_BatteryPower} # 0x110A
value_type: S_WORD
@ -2511,6 +2510,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device1
name: "Inv1 AC Output Active Power"
id: inv1_ac_output_active_power
register_type: holding
address: ${Felicity_Inv_ACOutputActivePower} # 0x111E
value_type: S_WORD
@ -2557,6 +2557,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device1
name: "Inv1 PV Input Power"
id: inv1_pv_input_power
register_type: holding
address: ${Felicity_Inv_PVInputPower} # 0x112A
value_type: S_WORD
@ -2624,6 +2625,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device2
name: "Inv2 BatteryPower"
id: inv2_batterypower
register_type: holding
address: ${Felicity_Inv_BatteryPower} # 0x110A
value_type: S_WORD
@ -2674,6 +2676,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device2
name: "Inv2 AC Output Active Power"
id: inv2_ac_output_active_power
register_type: holding
address: ${Felicity_Inv_ACOutputActivePower} # 0x111E
value_type: S_WORD
@ -2720,6 +2723,7 @@ sensor:
- platform: modbus_controller
modbus_controller_id: modbus_device2
name: "Inv2 PV Input Power"
id: inv2_pv_input_power
register_type: holding
address: ${Felicity_Inv_PVInputPower} # 0x112A
value_type: S_WORD
@ -3119,7 +3123,7 @@ script:
index = id(is_school_holiday).state ? ${GM_SCHOOL_HOLIDAY} : id(is_public_holiday).state ? ${GM_PUBLIC_HOLIDAY} : (dayofweek == 1) ? ${GM_SUNDAY} : (dayofweek == 7) ? ${GM_SATURDAY} : ${GM_WORKDAY};
}
else {
index = 0; // default
index = ${GM_WORKDAY}; // default
}
- id: set_active_heating_timers

View File

@ -5,10 +5,12 @@ substitutions:
HEATING_HOT: 70
HEATING_TEMP_SCALE: 1000.0
HEATING_DAY_BLOCKS: 6
GEYSER_MODES: 5
GM_SUNDAY: 0
GM_WORKDAY: 1
GM_SATURDAY: 2
GM_PUBLIC_HOLIDAY: 3
GM_SCHOOL_HOLIDAY: 4
LATE_MORNING_END: 10 #10AM, in winter it should be 11AM

102
common/time.yaml Normal file
View File

@ -0,0 +1,102 @@
# https://community.home-assistant.io/t/display-manually-set-rtc-ds3231-time-in-esphome-sntp-sync-every-12-hours-need-help-with-web-interface/868801
# miloit
time:
- platform: sntp
id: sntp_time
web_server:
port: 80
custom_component:
- lambda: |-
class DS3231Component : public PollingComponent {
public:
DS3231Component(esphome::time::RealTimeClock *rtc) : PollingComponent(10000), rtc_(rtc) {}
void setup() override {
if (!Wire.requestFrom(0x68, 1)) {
ESP_LOGE("DS3231", "RTC not found at I2C address 0x68");
return;
}
ESP_LOGI("DS3231", "RTC found at I2C address 0x68");
auto now = this->rtc_->now();
if (now.is_valid()) {
set_time(now.year, now.month, now.day_of_month, now.hour, now.minute, now.second, now.day_of_week);
ESP_LOGI("DS3231", "RTC time set to %04d-%02d-%02d %02d:%02d:%02d",
now.year, now.month, now.day_of_month, now.hour, now.minute, now.second);
} else {
ESP_LOGE("DS3231", "SNTP time is not valid; cannot set RTC");
}
}
void update() override {
auto time = get_time();
if (time.year > 0) {
ESP_LOGI("DS3231", "Current RTC Time: %04d-%02d-%02d %02d:%02d:%02d",
time.year, time.month, time.day, time.hour, time.minute, time.second);
} else {
ESP_LOGE("DS3231", "Failed to read time from RTC");
}
}
void set_time(int year, int month, int day, int hour, int minute, int second, int day_of_week) {
Wire.beginTransmission(0x68);
Wire.write(0); // Start at register 0
Wire.write(dec_to_bcd(second)); // Seconds
Wire.write(dec_to_bcd(minute)); // Minutes
Wire.write(dec_to_bcd(hour)); // Hours
Wire.write(dec_to_bcd(day_of_week)); // Day of the week
Wire.write(dec_to_bcd(day)); // Day of the month
Wire.write(dec_to_bcd(month)); // Month
Wire.write(dec_to_bcd(year - 2000)); // Year
Wire.endTransmission();
}
struct Time {
int year;
int month;
int day;
int hour;
int minute;
int second;
int day_of_week;
};
Time get_time() {
Wire.beginTransmission(0x68);
Wire.write(0); // Start at register 0
Wire.endTransmission();
if (Wire.requestFrom(0x68, 7) != 7) {
ESP_LOGE("DS3231", "Failed to read time registers");
return Time{0, 0, 0, 0, 0, 0, 0};
}
uint8_t second = bcd_to_dec(Wire.read());
uint8_t minute = bcd_to_dec(Wire.read());
uint8_t hour = bcd_to_dec(Wire.read());
uint8_t day_of_week = bcd_to_dec(Wire.read());
uint8_t day = bcd_to_dec(Wire.read());
uint8_t month = bcd_to_dec(Wire.read());
uint16_t year = bcd_to_dec(Wire.read()) + 2000;
return Time{year, month, day, hour, minute, second, day_of_week};
}
private:
esphome::time::RealTimeClock *rtc_;
uint8_t dec_to_bcd(int val) {
return ((val / 10 * 16) + (val % 10));
}
int bcd_to_dec(uint8_t val) {
return ((val / 16 * 10) + (val % 16));
}
};
auto my_rtc = new DS3231Component(id(sntp_time));
App.register_component(my_rtc);
return {};

File diff suppressed because it is too large Load Diff