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;
|
this->status_config_updated_ = false;
|
||||||
}
|
}
|
||||||
LinBusProtocol::update();
|
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() {
|
const std::array<uint8_t, 4> TrumaiNetBoxApp::lin_identifier() {
|
||||||
|
|||||||
@ -444,10 +444,6 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
|||||||
void lin_heartbeat() override;
|
void lin_heartbeat() override;
|
||||||
void lin_reset_device() 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_; }
|
bool get_status_heater_valid() { return this->status_heater_valid_; }
|
||||||
const StatusFrameHeater *get_status_heater() { return &this->status_heater_; }
|
const StatusFrameHeater *get_status_heater() { return &this->status_heater_; }
|
||||||
void register_listener(const std::function<void(const StatusFrameHeater *)> &func);
|
void register_listener(const std::function<void(const StatusFrameHeater *)> &func);
|
||||||
@ -472,11 +468,6 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
|||||||
StatusFrameTimerResponse *update_timer_prepare();
|
StatusFrameTimerResponse *update_timer_prepare();
|
||||||
void update_timer_submit() { this->update_status_timer_unsubmitted_ = true; }
|
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_; }
|
int64_t get_last_cp_plus_request() { return this->device_registered_; }
|
||||||
|
|
||||||
// Automation
|
// Automation
|
||||||
@ -494,15 +485,15 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
|||||||
HeatingMode mode = HeatingMode::HEATING_MODE_OFF, u_int8_t water_temperature = 0,
|
HeatingMode mode = HeatingMode::HEATING_MODE_OFF, u_int8_t water_temperature = 0,
|
||||||
EnergyMix energy_mix = EnergyMix::ENERGY_MIX_NONE,
|
EnergyMix energy_mix = EnergyMix::ENERGY_MIX_NONE,
|
||||||
ElectricPowerLevel el_power_level = ElectricPowerLevel::ELECTRIC_POWER_LEVEL_0);
|
ElectricPowerLevel el_power_level = ElectricPowerLevel::ELECTRIC_POWER_LEVEL_0);
|
||||||
|
|
||||||
#ifdef USE_TIME
|
#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();
|
bool action_write_time();
|
||||||
#endif // USE_TIME
|
#endif // USE_TIME
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef USE_TIME
|
|
||||||
time::RealTimeClock *time_ = nullptr;
|
|
||||||
#endif // USE_TIME
|
|
||||||
|
|
||||||
// Truma CP Plus needs init (reset). This device is not registered.
|
// Truma CP Plus needs init (reset). This device is not registered.
|
||||||
uint32_t device_registered_ = 0;
|
uint32_t device_registered_ = 0;
|
||||||
uint32_t init_requested_ = 0;
|
uint32_t init_requested_ = 0;
|
||||||
@ -563,11 +554,20 @@ class TrumaiNetBoxApp : public LinBusProtocol {
|
|||||||
bool update_status_timer_stale_ = false;
|
bool update_status_timer_stale_ = false;
|
||||||
StatusFrameTimerResponse update_status_timer_;
|
StatusFrameTimerResponse update_status_timer_;
|
||||||
|
|
||||||
|
#ifdef USE_TIME
|
||||||
|
time::RealTimeClock *time_ = nullptr;
|
||||||
|
|
||||||
// The behaviour of `update_status_clock_unsubmitted_` is special.
|
// 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
|
// Just an update is marked. The actual package is prepared when CP Plus asks for the data in the
|
||||||
// `lin_multiframe_recieved` method.
|
// `lin_multiframe_recieved` method.
|
||||||
bool update_status_clock_unsubmitted_ = false;
|
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 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;
|
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:
|
then:
|
||||||
# read time from external source (connected via I2C)
|
# read time from external source (connected via I2C)
|
||||||
- ds1307.read_time
|
- 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:
|
external_components:
|
||||||
- source: github://Fabian-Schmidt/esphome-truma_inetbox
|
- source: github://Fabian-Schmidt/esphome-truma_inetbox
|
||||||
@ -27,12 +23,7 @@ i2c:
|
|||||||
time:
|
time:
|
||||||
- platform: ds1307
|
- platform: ds1307
|
||||||
update_interval: never
|
update_interval: never
|
||||||
- platform: sntp
|
id: esptime
|
||||||
on_time_sync:
|
|
||||||
- ds1307.write_time
|
|
||||||
# wait 90 seconds for Truma CP Plus connection to init
|
|
||||||
- delay: 90 seconds
|
|
||||||
- truma_inetbox.clock.set
|
|
||||||
|
|
||||||
uart:
|
uart:
|
||||||
- id: lin_uart_bus
|
- id: lin_uart_bus
|
||||||
@ -45,6 +36,7 @@ uart:
|
|||||||
|
|
||||||
truma_inetbox:
|
truma_inetbox:
|
||||||
uart_id: lin_uart_bus
|
uart_id: lin_uart_bus
|
||||||
|
time_id: esptime
|
||||||
cs_pin: 5
|
cs_pin: 5
|
||||||
fault_pin: 18
|
fault_pin: 18
|
||||||
# Advanced users can use `on_heater_message` action. The heater data is in the `message` variable.
|
# 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