Update clock of CP Plus automatically from ESP (if possible).
This commit is contained in:
parent
ccb7b956f8
commit
82c1f45f59
@ -45,6 +45,19 @@ void TrumaiNetBoxApp::update() {
|
||||
this->status_config_updated_ = false;
|
||||
}
|
||||
LinBusProtocol::update();
|
||||
|
||||
#ifdef USE_TIME
|
||||
// Update time of CP Plus automatically when
|
||||
// - Time component configured
|
||||
// - Update was not done
|
||||
// - 30 seconds after init data recieved
|
||||
if (this->time_ != nullptr && !this->update_status_clock_done && this->init_recieved_ > 0) {
|
||||
if (micros() > ((30 * 1000 * 1000) + this->init_recieved_ /* 30 seconds after init recieved */)) {
|
||||
this->update_status_clock_done = true;
|
||||
this->action_write_time();
|
||||
}
|
||||
}
|
||||
#endif // USE_TIME
|
||||
}
|
||||
|
||||
const std::array<uint8_t, 4> TrumaiNetBoxApp::lin_identifier() {
|
||||
|
||||
@ -444,10 +444,6 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
||||
void lin_heartbeat() override;
|
||||
void lin_reset_device() override;
|
||||
|
||||
#ifdef USE_TIME
|
||||
void set_time(time::RealTimeClock *time) { time_ = time; }
|
||||
#endif // USE_TIME
|
||||
|
||||
bool get_status_heater_valid() { return this->status_heater_valid_; }
|
||||
const StatusFrameHeater *get_status_heater() { return &this->status_heater_; }
|
||||
void register_listener(const std::function<void(const StatusFrameHeater *)> &func);
|
||||
@ -472,11 +468,6 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
||||
StatusFrameTimerResponse *update_timer_prepare();
|
||||
void update_timer_submit() { this->update_status_timer_unsubmitted_ = true; }
|
||||
|
||||
#ifdef USE_TIME
|
||||
bool truma_clock_can_update() { return this->status_clock_valid_; }
|
||||
void update_clock_submit() { this->update_status_clock_unsubmitted_ = true; }
|
||||
#endif // USE_TIME
|
||||
|
||||
int64_t get_last_cp_plus_request() { return this->device_registered_; }
|
||||
|
||||
// Automation
|
||||
@ -494,15 +485,15 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
||||
HeatingMode mode = HeatingMode::HEATING_MODE_OFF, u_int8_t water_temperature = 0,
|
||||
EnergyMix energy_mix = EnergyMix::ENERGY_MIX_NONE,
|
||||
ElectricPowerLevel el_power_level = ElectricPowerLevel::ELECTRIC_POWER_LEVEL_0);
|
||||
|
||||
#ifdef USE_TIME
|
||||
void set_time(time::RealTimeClock *time) { time_ = time; }
|
||||
bool truma_clock_can_update() { return this->status_clock_valid_; }
|
||||
void update_clock_submit() { this->update_status_clock_unsubmitted_ = true; }
|
||||
bool action_write_time();
|
||||
#endif // USE_TIME
|
||||
|
||||
protected:
|
||||
#ifdef USE_TIME
|
||||
time::RealTimeClock *time_ = nullptr;
|
||||
#endif // USE_TIME
|
||||
|
||||
// Truma CP Plus needs init (reset). This device is not registered.
|
||||
uint32_t device_registered_ = 0;
|
||||
uint32_t init_requested_ = 0;
|
||||
@ -563,11 +554,20 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
||||
bool update_status_timer_stale_ = false;
|
||||
StatusFrameTimerResponse update_status_timer_;
|
||||
|
||||
#ifdef USE_TIME
|
||||
time::RealTimeClock *time_ = nullptr;
|
||||
|
||||
// The behaviour of `update_status_clock_unsubmitted_` is special.
|
||||
// Just an update is marked. The actual package is prepared when CP Plus asks for the data in the
|
||||
// `lin_multiframe_recieved` method.
|
||||
bool update_status_clock_unsubmitted_ = false;
|
||||
|
||||
// Mark if the initial clock sync was done.
|
||||
bool update_status_clock_done = false;
|
||||
#else
|
||||
const bool update_status_clock_unsubmitted_ = false;
|
||||
#endif // USE_TIME
|
||||
|
||||
bool answer_lin_order_(const u_int8_t pid) override;
|
||||
|
||||
bool lin_read_field_by_identifier_(u_int8_t identifier, std::array<u_int8_t, 5> *response) override;
|
||||
|
||||
12
truma.yaml
12
truma.yaml
@ -5,10 +5,6 @@ esphome:
|
||||
then:
|
||||
# read time from external source (connected via I2C)
|
||||
- ds1307.read_time
|
||||
# wait 90 seconds for Truma CP Plus connection to init
|
||||
- delay: 90 seconds
|
||||
# update CP Plus clock
|
||||
- truma_inetbox.clock.set
|
||||
|
||||
external_components:
|
||||
- source: github://Fabian-Schmidt/esphome-truma_inetbox
|
||||
@ -27,12 +23,7 @@ i2c:
|
||||
time:
|
||||
- platform: ds1307
|
||||
update_interval: never
|
||||
- platform: sntp
|
||||
on_time_sync:
|
||||
- ds1307.write_time
|
||||
# wait 90 seconds for Truma CP Plus connection to init
|
||||
- delay: 90 seconds
|
||||
- truma_inetbox.clock.set
|
||||
id: esptime
|
||||
|
||||
uart:
|
||||
- id: lin_uart_bus
|
||||
@ -45,6 +36,7 @@ uart:
|
||||
|
||||
truma_inetbox:
|
||||
uart_id: lin_uart_bus
|
||||
time_id: esptime
|
||||
cs_pin: 5
|
||||
fault_pin: 18
|
||||
# Advanced users can use `on_heater_message` action. The heater data is in the `message` variable.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user