-
Notifications
You must be signed in to change notification settings - Fork 2
/
electriq_cdx_pro_le.be
162 lines (149 loc) · 4 KB
/
electriq_cdx_pro_le.be
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
# To use this code, add it to your `autoexec.be` - or upload this script to your device and add `load("/<filename>.be")`.
# Before using this code, make sure you've completed the initial Tuya setup, as shown here: https://templates.blakadder.com/electriq_CD12PW.html
import hct
var In=hct.CallbackIn
var Out=hct.CallbackOut
log("Setting up development Home Assistant controls (using hct version "+hct.VERSION+")...")
var tuyasend0=/value->tasmota.cmd('TuyaSend0')
tasmota.add_rule('power1#state=1',tuyasend0)
tasmota.add_rule('Mqtt#Connected',tuyasend0)
preset_data=hct.MapData({'Smart':0, 'High':2, 'Low':3,'Purify':1})
swing_data=hct.MapData({'Fixed 90°':1,'Fixed 45°':0,'Swing':2})
callbacks=[
Out(
'tuyareceived#DpType4Id2',
/value->value==1?'fan':'drying',
'action'
),
Out(
'power1#state=0',
/value->'off',
'action'
),
Out(
'tuyareceived#DpType2Id4',
nil,
'target_humidity',
nil,
true
),
In(
def (value,data)
if data.entity.values.find('preset_mode','Smart')=='Smart'
hct.logger.debug('Unit is in Smart mode, so disallowing any changes to target humidity. Force-publishing 55%.')
return hct.Publish(55)
else
hct.tuya.send(2,4,value)
end
end,
'target_humidity'
),
Out(
'tuyareceived#DpType2Id103',
nil,
'current_temperature',
nil,
true # Dedupe, as Tuya published every 10 seconds, including duplicates.
),
Out(
'tuyareceived#DpType2Id3',
nil,
'current_humidity',
nil,
true # Dedupe, as Tuya published every 10 seconds, including duplicates.
),
Out(
'tuyareceived#DpType4Id2',
/value->value==1?'fan_only':'dry',
'mode'
),
Out(
'power1#state=0',
/value->'off',
'mode'
),
In(
def (value)
if value=='off'
tasmota.set_power(0,false)
else
tasmota.set_power(0,true)
hct.tuya.send(4,2,value=='fan_only'?1:0)
end
end,
'mode'
),
Out(
'tuyareceived#DpType4Id2',
/value->preset_data.out.find(value,'Unknown'),
'preset_mode'
),
In(
/value->hct.tuya.send(4,2,preset_data.in.find(value,0)),
'preset_mode'
),
Out(
'tuyareceived#DpType4Id102',
/value->swing_data.out.find(value,'Unknown'),
'swing_mode'
),
In(
/value->hct.tuya.send(4,102,swing_data.in.find(value,0)),
'swing_mode'
)
]
climate=hct.Climate(
hct.UseDeviceName,
nil,
nil,
'C',
nil,
35..80,
['dry', 'fan_only','off'],
preset_data.keys,
nil,
swing_data.keys,
nil,
callbacks
)
light_indicator=hct.Light(
'Humidity Health Indicator',
nil,
'mdi:wall-sconce-flat-variant',
[
In(/value->hct.tuya.send(1,101,value)),
Out('tuyareceived#DpType1Id101'),
Out(
'tuyareceived#DpType2Id3',
def (value)
# The indicator color is not reported from the Tuya MCU, but we can infer it from the current humidity, using values from the manual.
if value>=70
return hct.Light.DataRGB(255,102,102)
elif value>=60
return hct.Light.DataRGB(255,178,102)
else
return hct.Light.DataRGB(178,255,102)
end
end,
'rgb',
nil,
true # Dedupe.
)
]
)
light_uv=hct.Light(
'Ultra Violet',
nil,
'mdi:sun-wireless',
[
In(/value->hct.tuya.send(1,10,value)),
Out('tuyareceived#DpType1Id10'),
Out(
'tuyareceived#DpType1Id10',
/value->hct.Light.DataRGB(178,102,255),
'rgb',
nil,
true # Dedupe.
)
]
)