ESPHome 2025.12.0-dev
Loading...
Searching...
No Matches
uponor_smatrix.h
Go to the documentation of this file.
1#pragma once
2
6
8
9#ifdef USE_TIME
11#include "esphome/core/time.h"
12#endif
13
14#include <queue>
15#include <set>
16#include <vector>
17
18namespace esphome {
19namespace uponor_smatrix {
20
22static const uint8_t UPONOR_ID_DATETIME1 = 0x08;
24static const uint8_t UPONOR_ID_DATETIME2 = 0x09;
26static const uint8_t UPONOR_ID_DATETIME3 = 0x0A;
28static const uint8_t UPONOR_ID_UNKNOWN1 = 0x0C;
30static const uint8_t UPONOR_ID_OUTDOOR_TEMP = 0x2D;
32static const uint8_t UPONOR_ID_UNKNOWN2 = 0x35;
34static const uint8_t UPONOR_ID_TARGET_TEMP_MIN = 0x37;
36static const uint8_t UPONOR_ID_TARGET_TEMP_MAX = 0x38;
38static const uint8_t UPONOR_ID_TARGET_TEMP = 0x3B;
40static const uint8_t UPONOR_ID_ECO_SETBACK = 0x3C;
42static const uint8_t UPONOR_ID_DEMAND = 0x3D;
44static const uint8_t UPONOR_ID_MODE1 = 0x3E;
46static const uint8_t UPONOR_ID_MODE2 = 0x3F;
48static const uint8_t UPONOR_ID_ROOM_TEMP = 0x40;
50static const uint8_t UPONOR_ID_EXTERNAL_TEMP = 0x41;
52static const uint8_t UPONOR_ID_HUMIDITY = 0x42;
54static const uint8_t UPONOR_ID_REQUEST = 0xFF;
55
57static const uint16_t UPONOR_INVALID_VALUE = 0x7FFF;
58
60 uint8_t id;
61 uint16_t value;
62};
63
65
67 public:
69
70 void setup() override;
71 void dump_config() override;
72 void loop() override;
73
74 void register_device(UponorSmatrixDevice *device) { this->devices_.push_back(device); }
75
76 bool send(uint32_t device_address, const UponorSmatrixData *data, size_t data_len);
77
78#ifdef USE_TIME
79 void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; }
81 void send_time() { this->send_time_requested_ = true; }
82#endif
83
84 protected:
85 bool parse_byte_(uint8_t byte);
86
87 std::vector<UponorSmatrixDevice *> devices_;
88 std::set<uint32_t> unknown_devices_;
89
90 std::vector<uint8_t> rx_buffer_;
91 std::queue<std::vector<uint8_t>> tx_queue_;
92 uint32_t last_rx_;
93 uint32_t last_tx_;
94
95#ifdef USE_TIME
99 bool do_send_time_();
100#endif
101};
102
103class UponorSmatrixDevice : public Parented<UponorSmatrixComponent> {
104 public:
105 void set_address(uint32_t address) { this->address_ = address; }
106
107 virtual void on_device_data(const UponorSmatrixData *data, size_t data_len) = 0;
108 bool send(const UponorSmatrixData *data, size_t data_len) {
109 return this->parent_->send(this->address_, data, data_len);
110 }
111
112 protected:
114 uint32_t address_;
115};
116
117inline float raw_to_celsius(uint16_t raw) {
118 return (raw == UPONOR_INVALID_VALUE) ? NAN : fahrenheit_to_celsius(raw / 10.0f);
119}
120
121inline uint16_t celsius_to_raw(float celsius) {
122 return std::isnan(celsius) ? UPONOR_INVALID_VALUE
123 : static_cast<uint16_t>(lroundf(celsius_to_fahrenheit(celsius) * 10.0f));
124}
125
126} // namespace uponor_smatrix
127} // namespace esphome
uint8_t address
Definition bl0906.h:4
uint8_t raw[35]
Definition bl0939.h:0
Helper class to easily give an object a parent of type T.
Definition helpers.h:918
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
void set_time_id(time::RealTimeClock *time_id)
void register_device(UponorSmatrixDevice *device)
std::vector< UponorSmatrixDevice * > devices_
bool send(uint32_t device_address, const UponorSmatrixData *data, size_t data_len)
std::queue< std::vector< uint8_t > > tx_queue_
virtual void on_device_data(const UponorSmatrixData *data, size_t data_len)=0
bool send(const UponorSmatrixData *data, size_t data_len)
uint16_t celsius_to_raw(float celsius)
float raw_to_celsius(uint16_t raw)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
constexpr float celsius_to_fahrenheit(float value)
Convert degrees Celsius to degrees Fahrenheit.
Definition helpers.h:855
constexpr float fahrenheit_to_celsius(float value)
Convert degrees Fahrenheit to degrees Celsius.
Definition helpers.h:857