ESPHome  2024.5.0
uponor_smatrix_climate.cpp
Go to the documentation of this file.
2 #include "esphome/core/helpers.h"
3 #include "esphome/core/log.h"
4 
5 namespace esphome {
6 namespace uponor_smatrix {
7 
8 static const char *const TAG = "uponor_smatrix.climate";
9 
11  LOG_CLIMATE("", "Uponor Smatrix Climate", this);
12  ESP_LOGCONFIG(TAG, " Device address: 0x%04X", this->address_);
13 }
14 
16  const uint32_t now = millis();
17 
18  // Publish state after all update packets are processed
19  if (this->last_data_ != 0 && (now - this->last_data_ > 100) && this->target_temperature_raw_ != 0) {
20  float temp = raw_to_celsius((this->preset == climate::CLIMATE_PRESET_ECO)
22  : this->target_temperature_raw_);
23  float step = this->get_traits().get_visual_target_temperature_step();
24  this->target_temperature = roundf(temp / step) * step;
25  this->publish_state();
26  this->last_data_ = 0;
27  }
28 }
29 
41  return traits;
42 }
43 
45  if (call.get_target_temperature().has_value()) {
46  uint16_t temp = celsius_to_raw(*call.get_target_temperature());
47  if (this->preset == climate::CLIMATE_PRESET_ECO) {
48  // During ECO mode, the thermostat automatically substracts the setback value from the setpoint,
49  // so we need to add it here first
50  temp += this->eco_setback_value_raw_;
51  }
52 
53  // For unknown reasons, we need to send a null setpoint first for the thermostat to react
54  UponorSmatrixData data[] = {{UPONOR_ID_TARGET_TEMP, 0}, {UPONOR_ID_TARGET_TEMP, temp}};
55  this->send(data, sizeof(data) / sizeof(data[0]));
56  }
57 }
58 
59 void UponorSmatrixClimate::on_device_data(const UponorSmatrixData *data, size_t data_len) {
60  for (int i = 0; i < data_len; i++) {
61  switch (data[i].id) {
62  case UPONOR_ID_TARGET_TEMP_MIN:
63  this->min_temperature_ = raw_to_celsius(data[i].value);
64  break;
65  case UPONOR_ID_TARGET_TEMP_MAX:
66  this->max_temperature_ = raw_to_celsius(data[i].value);
67  break;
68  case UPONOR_ID_TARGET_TEMP:
69  // Ignore invalid values here as they are used by the controller to explicitely request the setpoint from a
70  // thermostat
71  if (data[i].value != UPONOR_INVALID_VALUE)
72  this->target_temperature_raw_ = data[i].value;
73  break;
74  case UPONOR_ID_ECO_SETBACK:
75  this->eco_setback_value_raw_ = data[i].value;
76  break;
77  case UPONOR_ID_DEMAND:
78  if (data[i].value & 0x1000) {
81  } else {
84  }
85  break;
86  case UPONOR_ID_MODE1:
87  this->set_preset_((data[i].value & 0x0008) ? climate::CLIMATE_PRESET_ECO : climate::CLIMATE_PRESET_NONE);
88  break;
89  case UPONOR_ID_ROOM_TEMP:
90  this->current_temperature = raw_to_celsius(data[i].value);
91  break;
92  case UPONOR_ID_HUMIDITY:
93  this->current_humidity = data[i].value & 0x00FF;
94  }
95  }
96 
97  this->last_data_ = millis();
98 }
99 
100 } // namespace uponor_smatrix
101 } // namespace esphome
void control(const climate::ClimateCall &call) override
This class is used to encode all control actions on a climate device.
Definition: climate.h:33
float current_humidity
The current humidity of the climate device, as reported from the integration.
Definition: climate.h:182
float raw_to_celsius(uint16_t raw)
void on_device_data(const UponorSmatrixData *data, size_t data_len) override
float target_temperature
The target temperature of the climate device.
Definition: climate.h:186
void set_supports_current_humidity(bool supports_current_humidity)
This class contains all static data for climate devices.
void set_visual_min_temperature(float visual_min_temperature)
The climate device is set to heat to reach the target temperature.
Definition: climate_mode.h:18
void set_visual_target_temperature_step(float temperature_step)
ClimateMode mode
The active mode of the climate device.
Definition: climate.h:173
void set_visual_current_temperature_step(float temperature_step)
float current_temperature
The current temperature of the climate device, as reported from the integration.
Definition: climate.h:179
bool has_value() const
Definition: optional.h:87
void set_supported_presets(std::set< ClimatePreset > presets)
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
The climate device is set to cool to reach the target temperature.
Definition: climate_mode.h:16
optional< ClimatePreset > preset
The active preset of the climate device.
Definition: climate.h:208
bool send(const UponorSmatrixData *data, size_t data_len)
void set_supported_modes(std::set< ClimateMode > modes)
float get_visual_target_temperature_step() const
ClimateTraits get_traits()
Get the traits of this climate device with all overrides applied.
Definition: climate.cpp:440
void set_visual_max_temperature(float visual_max_temperature)
The climate device is actively heating.
Definition: climate_mode.h:37
const optional< float > & get_target_temperature() const
Definition: climate.cpp:274
void publish_state()
Publish the state of the climate device, to be called from integrations.
Definition: climate.cpp:395
void set_supports_action(bool supports_action)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
The climate device is idle (monitoring climate but no action needed)
Definition: climate_mode.h:39
Device is running an energy-saving preset.
Definition: climate_mode.h:94
void set_supports_current_temperature(bool supports_current_temperature)
The climate device is actively cooling.
Definition: climate_mode.h:35
bool set_preset_(ClimatePreset preset)
Set preset. Reset custom preset. Return true if preset has been changed.
Definition: climate.cpp:563
ClimateAction action
The active state of the climate device.
Definition: climate.h:176
uint16_t celsius_to_raw(float celsius)