-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnspanel_esphome_hw_temperature.yaml
More file actions
192 lines (169 loc) · 6.05 KB
/
nspanel_esphome_hw_temperature.yaml
File metadata and controls
192 lines (169 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#####################################################################################################
##### NSPanel Easy - https://github.com/edwardtfn/NSPanel-Easy #####
#####################################################################################################
##### ESPHOME Hardware - Temperature #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
---
substitutions:
##############################
## Change only in your ##
## local yaml substitutions ##
temp_units: "°C"
##############################
TEMP_UNIT_IS_FAHRENHEIT: ${temp_units == "°F" or temp_units == "F" or temp_units == "°f" or temp_units == "f"}
BOOT_STEP_HW_TEMPERATURE: '8'
GPIO_TEMPERATURE_ADC_PIN: 38
ntc_source_filter_delta: 0.002 # adjust to your sensor's voltage jitter level
ntc_source_filter_heartbeat: 5min
TAG_HW_TEMPERATURE: nspanel.hw.temperature
esphome:
platformio_options:
build_flags:
- -D NSPANEL_EASY_HW_TEMPERATURE
- -D NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT=${1 if TEMP_UNIT_IS_FAHRENHEIT else 0}
globals:
- id: embedded_indoor_temp # Is embedded sensor used for indoor temperature?
type: bool
restore_value: true
initial_value: 'true'
- id: temperature_unit
type: std::string
restore_value: true
initial_value: '"${temp_units}"'
number:
- id: temperature_correction # Temperature correction
name: Temperature Correction
platform: template
entity_category: config
unit_of_measurement: ${temp_units}
min_value: ${ -18.0 if TEMP_UNIT_IS_FAHRENHEIT else -10.0 }
max_value: ${ 18.0 if TEMP_UNIT_IS_FAHRENHEIT else 10.0 }
initial_value: 0
step: ${ 1.0 if TEMP_UNIT_IS_FAHRENHEIT else 0.1 }
mode: box
restore_value: true
internal: false
optimistic: true
update_interval: never
on_value:
then:
- logger.log: Temperature correction changed.
- delay: 1s
- lambda: temp_nspanel->publish_state(temp_nspanel->raw_state);
script:
- id: !extend action_component_text
then:
- lambda: |-
if (page != "mem") return;
if (component == "temp_unit") {
id(temperature_unit) = (txt == "°F") ? "°F" : "°C";
}
- id: !extend action_component_val
then:
- lambda: |-
if (page != "mem") return;
if (component == "embedded_indoor_temperature") {
id(embedded_indoor_temp) = (val>0);
}
- id: display_embedded_temp # Show panel's temperature if selected, or API or Wi-Fi are out
mode: single
then:
- lambda: |-
if (system_flags.tft_upload_active) return;
if (!id(embedded_indoor_temp) and
system_flags.api_ready and
system_flags.wifi_ready and
current_page_id != ${PAGE_BOOT_ID})
return;
if (isnan(temp_nspanel->state)) {
disp1->set_component_text(hmi::home::INDR_TEMP.name, "");
return;
}
static char buffer[15];
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
// Fahrenheit with no decimal
snprintf(buffer, sizeof(buffer), "%.0f${temp_units}", celsius_to_fahrenheit(temp_nspanel->state));
#else
// Celsius with one decimal
snprintf(buffer, sizeof(buffer), "%.1f${temp_units}", temp_nspanel->state);
#endif
disp1->set_component_text(hmi::home::INDR_TEMP.name,
adjustDecimalSeparator(buffer, id(mui_decimal_separator)[0]).c_str());
- id: !extend dump_config
then:
- lambda: |-
ESP_LOGCONFIG("${TAG_HW_TEMPERATURE}", "Temperature unit: ${temp_units}");
- id: !extend page_home
then:
- script.execute: display_embedded_temp
- id: !extend stop_all
then:
- lambda: display_embedded_temp->stop();
sensor:
# 1) Raw ADC - fast sampling, early spike removal
- id: ntc_source
platform: adc
pin: ${GPIO_TEMPERATURE_ADC_PIN}
attenuation: 12db
samples: 16
update_interval: 1s
internal: true
filters:
# (A) Remove single-spike noise
- median:
window_size: 5
send_every: 1
send_first_at: 1
# (B) Smooth the curve
- exponential_moving_average:
alpha: 0.2
send_every: 1
send_first_at: 1
# (C) Only publish when the smoothed value actually changes
- delta: ${ntc_source_filter_delta}
# (D) If nothing changes, publish once every 5 minutes
- heartbeat:
period: ${ntc_source_filter_heartbeat}
optimistic: true
# 2) Convert to resistance
- id: resistance_sensor
platform: resistance
sensor: ntc_source
configuration: DOWNSTREAM
resistor: 11.2kOhm
internal: true
# 3) Temperature (HA-facing)
- id: temp_nspanel
name: Temperature
platform: ntc
sensor: resistance_sensor
unit_of_measurement: °C
accuracy_decimals: 1
internal: false
calibration:
b_constant: 3950
reference_temperature: 25°C
reference_resistance: 10kOhm
filters:
# Publish only when temperature changes meaningfully
- delta: 0.01
# (D) If nothing changes, publish once every 5 minutes
- heartbeat:
period: ${ntc_source_filter_heartbeat}
optimistic: true
# Apply offset
- lambda: |-
// Apply offset based on correction units
#if NSPANEL_EASY_HW_TEMPERATURE_IS_FAHRENHEIT
// Offset is in °F, convert delta to °C before applying
return x + (temperature_correction->state / 1.8f);
#else
// Offset already in °C
return x + temperature_correction->state;
#endif
on_value:
then:
- script.execute: display_embedded_temp
...