-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-tongou-to-q-sys-jwt.yaml
418 lines (397 loc) · 12.4 KB
/
config-tongou-to-q-sys-jwt.yaml
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
esphome:
name: to-q-sys-jwt
name_add_mac_suffix: true
platformio_options:
platform_packages:
- framework-arduino-api @ https://github.com/dshcherb/ArduinoCore-API/archive/refs/tags/2025.1.4.zip
bk72xx:
board: cbu
framework:
options:
# Increase the UART buffer size via a Libretiny-specific option.
LT_SERIAL_BUFFER_SIZE: 512
version: latest
logger:
web_server:
captive_portal:
mdns:
api:
encryption:
key: !secret api_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
uart:
rx_pin: RX1
tx_pin: TX1
baud_rate: 115200
rx_buffer_size: 512
time:
- platform: homeassistant
id: homeassistant_time
# Register the Tuya MCU connection
tuya:
id: tuya_component
time_id: homeassistant_time
on_datapoint_update:
- sensor_datapoint: 6
datapoint_type: raw
then:
- lambda: |-
// volts with one digit after decimal point.
id(voltage_sensor).publish_state((x[0] << 8 | x[1]) * 0.1);
// amperes with 3 digits after decimal point.
id(current_sensor).publish_state(((x[2] << 16 | x[3] << 8) | x[4]) * 0.001);
// kilo watts with 3 digits after decimal point.
id(power_sensor).publish_state(((x[5] << 16 | x[6] << 8) | x[7]) * 0.001);
number:
- platform: "tuya"
name: "Under-voltage Threshold"
number_datapoint: 116
device_class: voltage
unit_of_measurement: "V"
min_value: 100
max_value: 280
step: 1
- platform: "tuya"
name: "Over-voltage Threshold"
number_datapoint: 115
device_class: voltage
unit_of_measurement: "V"
min_value: 100
max_value: 280
step: 1
- platform: "tuya"
name: "Over-current Threshold"
number_datapoint: 114
device_class: current
unit_of_measurement: "A"
min_value: 1
max_value: 50
step: 0.1
- platform: "tuya"
name: "Temperature Threshold"
number_datapoint: 118
unit_of_measurement: "°C"
device_class: temperature
# In 100s °C
min_value: -25
max_value: 100
multiply: 10.0
step: 0.1
- platform: "tuya"
name: "Over-Power Threshold"
number_datapoint: 119
device_class: power
unit_of_measurement: "W"
min_value: 5
# The value in the original app is 26000, however, the device is rated to
# switch up to 50 Amps and 240 V AC (the relay inside is marked as 60A).
# So it's better to cap the threshold at 240 * 50 = 12000 W.
max_value: 12000
step: 1
- platform: "tuya"
name: "Screen Brightness"
number_datapoint: 140
min_value: 1
max_value: 5
step: 1
- platform: "tuya"
# Called "Actively Report Time" in the developer API. This is actually an interval
# for the MCU to report all data points to the main module over UART. The original
# app limit is 60 seconds but lower values are possible. It may take some time for the
# Tuya component to handle incoming bytes for all data points so use with care.
name: "Reporting Interval"
number_datapoint: 137
unit_of_measurement: "S"
min_value: 5 # 60
max_value: 600
step: 1
- platform: "tuya"
name: "Balance Shortage Threshold"
device_class: energy
number_datapoint: 120
unit_of_measurement: "kW·h"
min_value: 1
max_value: 500
step: 1
- platform: "tuya"
id: charge_electricity
# The electricity allowance for the "prepayment switch" mode.
# Charging will not work if the prepayment switch is off (this logic
# is built into the MCU firmware).
name: "Charge Electricity"
number_datapoint: 14
device_class: energy_storage
unit_of_measurement: "kW·h"
min_value: 0
max_value: 9999 # 999999
datapoint_hidden:
datapoint_type: int
initial_value: 0
restore_value: false
step: 0.1
multiply: 100
select:
- platform: "tuya"
name: "Under-voltage Action"
enum_datapoint: 103
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
2: 'Trip'
- platform: "tuya"
name: "Over-voltage Action"
enum_datapoint: 102
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
2: 'Trip'
- platform: "tuya"
name: "Over-current Action"
enum_datapoint: 104
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
2: 'Trip'
- platform: "tuya"
name: "Over-power Action"
enum_datapoint: 105
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
2: 'Trip'
- platform: "tuya"
name: "Over-temperature Action"
enum_datapoint: 107
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
2: 'Trip'
- platform: "tuya"
# What to do when the device is running out of the electricity budget.
# It is not possible to trip on shortage: in fact, it does not make sense
# because there's still budget. In the pre-paid mode the relay will be tripped
# when the balance is zeroed out.
name: "Balance Shortage Action"
enum_datapoint: 101
optimistic: true
options:
0: 'Ignore'
1: 'Alarm'
- platform: "tuya"
name: "Relay Power-on State"
enum_datapoint: 142
optimistic: true
options:
0: 'Power Off'
1: 'Power On'
2: 'Last State'
text_sensor:
- platform: libretiny
version:
name: LibreTiny Version
- platform: "tuya"
# Seems to indicate whether the module is online (Wi-Fi connected) per the MCU
# based on the feedback from the main module.
name: "Online Status"
sensor_datapoint: 109
filters:
# The Tuya DP is an enum which is converted to human-readable strings.
- map:
- 1 -> Offline
- 0 -> Online
- platform: "tuya"
name: "Last MCU Event"
sensor_datapoint: 110
filters:
# The Tuya DP is an enum which is converted to human-readable strings denoting
# the status of the last event processed by the MCU. Clearing it manually just
# results in the MCU resetting it back to what it was so this is a sensor.
- map:
- 0 -> Normal
- 1 -> Over Current Trip
- 2 -> Over Power Trip
- 3 -> High Temp Trip
- 4 -> Over Voltage Trip
- 5 -> Under Voltage Trip
- 6 -> Over Current Alarm
- 7 -> Over Power Alarm
- 8 -> High Temp Alarm
- 9 -> Over Voltage Alarm
- 10 -> Under Voltage Alarm
- 11 -> Remote ON
- 12 -> Remote OFF
- 13 -> Manual ON
- 14 -> Manual OFF
# Actually irrelevant for this device because this power meter does not
# have current leakage detection.
- 15 -> Leakage Trip
- 16 -> Leakage Alarm
- 17 -> Restore Default
- 18 -> Automatic Closing
- 19 -> Electricity Shortage
# On MCU firmware 1.1.3 (latest at the time of writing) it seems like this
# alarm is not cleared by the MCU even if the balance is topped up past the
# shortage threshold. Doing a local or remote on/off will clear it but it's
# not always practical. Setting the DP to Normal manually is overridden by
# the MCU.
# Product: '{"p":"kmnzgh4yn8pa0lqh","v":"1.1.3","m":2}'
- 20 -> Electricity Shortage Alarm
sensor:
- platform: "tuya"
# Also known as Total Forward Energy
name: "Total Electricity Consumption"
sensor_datapoint: 1
device_class: "energy"
unit_of_measurement: "kW·h"
state_class: "measurement"
filters:
# The values stored in the MCU need to be processed for display.
- multiply: 0.01
accuracy_decimals: 2
- platform: "tuya"
name: "Forward Electricity"
sensor_datapoint: 125
device_class: "energy"
unit_of_measurement: "kW·h"
state_class: "measurement"
icon: "mdi:meter-electric-outline"
accuracy_decimals: 2
filters:
# The values stored in the MCU need to be processed for display.
- multiply: 0.01
- platform: "tuya"
name: "Real-time Temperature"
sensor_datapoint: 131
state_class: "measurement"
unit_of_measurement: "°C"
device_class: "temperature"
accuracy_decimals: 1
filters:
# The values stored in the MCU need to be processed for display.
- multiply: 0.1
icon: "mdi:temperature-celcius"
- platform: "tuya"
name: "Electricity Balance"
sensor_datapoint: 13
state_class: "measurement"
unit_of_measurement: "kW·h"
device_class: "energy"
accuracy_decimals: 2
filters:
# The values stored in the MCU need to be processed for display.
- multiply: 0.01
icon: "mdi:home-battery-outline"
- platform: "template"
id: current_sensor
name: "Real-time Current"
unit_of_measurement: "A"
state_class: "measurement"
device_class: "current"
icon: "mdi:current-ac"
accuracy_decimals: 3
- platform: "template"
id: power_sensor
name: "Real-time Power"
unit_of_measurement: "kW"
state_class: "measurement"
device_class: "power"
icon: "mdi:lightning-bolt"
accuracy_decimals: 3
- platform: "template"
id: voltage_sensor
name: "Real-time Voltage"
unit_of_measurement: "V"
state_class: "measurement"
device_class: "voltage"
icon: "mdi:flash-triangle"
accuracy_decimals: 1
switch:
- platform: "tuya"
# Off - circuit is "open", i.e. phase is broken, neutral wire is always connected in hardware.
# On - circuit is "closed", i.e. phase is connected via the built-in relay.
# The relay will be turned off (circuit is broken) whenever DP 11 (Prepayment switch) is
# off. The "Prepayment switch" has to do with how this device is marketed: i.e. for rental
# properties where somebody pays for electricity used.
name: "Circuit Breaker Switch"
switch_datapoint: 16
icon: "mdi:restart"
device_class: outlet
- platform: "tuya"
# Automatic Reclosing refers to a feature that closes the circuit
# (i.e. allows the current to flow through the relay) automatically
# upon coming back to normal conditions.
# Auto-closing is available only when the device recovers from
# under/over-voltage conditions, not other parameters due to safety
# reasons.
name: "Automatic Closing"
switch_datapoint: 112
restore_mode: DISABLED
- platform: "tuya"
# Reset the MCU to default settings.
name: "Reset MCU to Defaults"
switch_datapoint: 113
- platform: "tuya"
# Report MCU state changes (including electricity measurements) at the
# predefined reporting interval (see DP 137).
name: "Report State Changes"
switch_datapoint: 111
restore_mode: DISABLED
- platform: "tuya"
# Whether to use the energy balance datapoint or not to determine if the
# relay should be on or off (the actual behavior will also depend on
# whether DP 101 is set to alarm or break the circuit). If this mode
# is disabled, the on-device switch button will not be limited if balance
# is zero.
name: "Prepayment Switch Mode"
switch_datapoint: 11
- platform: "tuya"
id: clear_electricity_switch
# Clear the remaining electricity budget.
name: "Clear Remaining Electricity"
switch_datapoint: 12
internal: true
- platform: "tuya"
name: "Screen On"
# Enable or disable the on-device screen. Does not block buttons
# on the device: i.e. one can still trip the switch.
switch_datapoint: 141
inverted: true
button:
- platform: template
# Clearing the balance in the "Prepaid switch mode" will result in the relay
# breaking the circuit. Use with care. If the balance is zero when the
# prepaid mode is turned on, the relay will be tripped as well.
name: "Clear Balance"
icon: "mdi:checkbox-blank-off-outline"
on_press:
- switch.turn_on: clear_electricity_switch
- delay: 1s
# The flag isn't cleared automatically by the MCU so it's done manually.
- switch.turn_off: clear_electricity_switch
# Doing something like this to clear the last event back to Normal is overridden
# by the MCU on MCU firmware 1.1.3 at least.
# - platform: template
# # The last event will stay there even if Alert conditions have been cleared.
# name: "Clear Last Event"
# icon: "mdi:checkbox-blank-off-outline"
# on_press:
# then:
# - lambda: |-
# // Set the Event DP to 0 (Normal) to clear any previous state.
# id(tuya_component).set_enum_datapoint_value(110, 0);
# This datapoint is present in the API but does not seem to be set. It's a string value
# which is empty.
# - platform: "tuya"
# name: "Cycle time"
# sensor_datapoint: 138