ESPHome 2025.5.0
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 set_system_address(uint16_t address) { this->address_ = address; }
75 void register_device(UponorSmatrixDevice *device) { this->devices_.push_back(device); }
76
77 bool send(uint16_t device_address, const UponorSmatrixData *data, size_t data_len);
78
79#ifdef USE_TIME
80 void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; }
82 void send_time() { this->send_time_requested_ = true; }
83#endif
84
85 protected:
86 bool parse_byte_(uint8_t byte);
87
88 uint16_t address_;
89 std::vector<UponorSmatrixDevice *> devices_;
90 std::set<uint16_t> unknown_devices_;
91
92 std::vector<uint8_t> rx_buffer_;
93 std::queue<std::vector<uint8_t>> tx_queue_;
94 uint32_t last_rx_;
95 uint32_t last_tx_;
96
97#ifdef USE_TIME
101 bool do_send_time_();
102#endif
103};
104
105class UponorSmatrixDevice : public Parented<UponorSmatrixComponent> {
106 public:
107 void set_device_address(uint16_t address) { this->address_ = address; }
108
109 virtual void on_device_data(const UponorSmatrixData *data, size_t data_len) = 0;
110 bool send(const UponorSmatrixData *data, size_t data_len) {
111 return this->parent_->send(this->address_, data, data_len);
112 }
113
114 protected:
116 uint16_t address_;
117};
118
119inline float raw_to_celsius(uint16_t raw) {
120 return (raw == UPONOR_INVALID_VALUE) ? NAN : fahrenheit_to_celsius(raw / 10.0f);
121}
122
123inline uint16_t celsius_to_raw(float celsius) {
124 return std::isnan(celsius) ? UPONOR_INVALID_VALUE
125 : static_cast<uint16_t>(lroundf(celsius_to_fahrenheit(celsius) * 10.0f));
126}
127
128} // namespace uponor_smatrix
129} // 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:538
The RealTimeClock class exposes common timekeeping functions via the device's local real-time clock.
void set_time_id(time::RealTimeClock *time_id)
bool send(uint16_t device_address, const UponorSmatrixData *data, size_t data_len)
void register_device(UponorSmatrixDevice *device)
std::vector< UponorSmatrixDevice * > devices_
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:482
constexpr float fahrenheit_to_celsius(float value)
Convert degrees Fahrenheit to degrees Celsius.
Definition helpers.h:484