-
Notifications
You must be signed in to change notification settings - Fork 2
/
proscenic_t21.be
248 lines (204 loc) · 5.38 KB
/
proscenic_t21.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
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
# 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/proscenic_T21.html
import hct
var In=hct.CallbackIn
var Out=hct.CallbackOut
log("Setting up Proscenic T21 (using hct version "+hct.VERSION+")...")
# Now we add a Number slider to control cooking temperature in F.
# Since the fryer MCU uses F natively, this just the process similar to the cookbook pull-down above.
hct.Number(
'Cooking Temperature (F)',
170..399,
'slider', # Input type
nil, # Step size
'°F', # Unit of measure
nil, # Entity ID
'mdi:temperature-fahrenheit',
[
Out('tuyareceived#dptype2id103'),
In(
/value->hct.tuya.send(2,103,value)
)
]
)
# Now a slider for temperature in C (not necessary but nice to have if you use C in your country).
# This is a little more complex as it means converting the temperature in the callbacks.
# Here our outgoing callback is a map from the conversion function to the trigger that calls it.
import math
callback_f_to_c=Out(
'tuyareceived#dptype2id103',
/value->math.ceil((value-32)/1.8)
)
callback_c_to_f=In(
/value->hct.tuya.send(2,103,int((value*1.8)+32))
)
hct.Number(
'Cooking Temperature (C)',
77..204,
'slider',
nil,
'°C',
nil,
'mdi:temperature-celsius',
[callback_f_to_c, callback_c_to_f]
)
hct.Number(
'Cooking Time',
1..60,
'box',
nil,
'minutes',
nil,
'mdi:timer',
[
Out('tuyareceived#DpType2Id7'),
In(
/value->hct.tuya.send(2,7,value)
)
]
)
def keep_warm_enable_if_time_set(value)
# If the Keep Warm time is set a value greater than zero, automatically enable the Keep Warm setting, and vice versa.
# This is more convenient as otherwise the Home Assistant user would need to juggle between two separte controls.
value=value!=nil ? value : 0
if value==0
tasmota.set_power(2,false)
return hct.Publish(value)
end
value=value<5 ? 5 : value
if !tasmota.get_power()[2]
hct.tools.add_rule_once(
'Power3#state=1',
/->hct.tuya.send(2,105,value)
)
tasmota.set_power(2,true)
else
hct.tuya.send(2,105,value)
end
return hct.Publish(value)
end
hct.Number(
'Keep Warm Time',
0..120,
'box',
nil,
'minutes',
nil,
'mdi:timer-sync',
[
Out('tuyareceived#DpType2Id105'),
Out('Power3#state=0',/->0),
Out('Power3#state=1',/->5),
In(keep_warm_enable_if_time_set)
]
)
def delay_enable_if_time_set(value)
# Same principle as keep_warm_enable_if_time_set above.
value=value!=nil ? value : 0
if value==0
tasmota.set_power(3,false)
return hct.Publish(value)
end
value=value<5 ? 5 : value
if !tasmota.get_power()[3]
hct.tools.add_rule_once(
'Power4#state=1',
/->hct.tuya.send(2,6,value)
)
tasmota.set_power(3,true)
else
hct.tuya.send(2,6,value)
end
return hct.Publish(value)
end
hct.Number(
'Delay Time',
0..720,
'box',
nil,
'minutes',
nil,
'mdi:timer-pause',
[
Out('tuyareceived#DpType2Id6'),
Out('Power4#state=0',/->0),
Out('Power4#state=1',/->5),
In(delay_enable_if_time_set)
]
)
hct.Sensor(
'Status',
nil,
nil,
nil,
'mdi:playlist-play',
[
Out(
'tuyareceived#dptype4id5',
/value->{0:'Ready',1:'Delayed Cook',2:'Cooking',3:'Keep Warm',4:'Off',5:'Cooking Complete'}.find(value,'Unknown')
)
],
'ENUM'
)
hct.Sensor(
'Time Remaining',
'minutes',
nil,
nil,
'mdi:timer',
Out('tuyareceived#dptype2Id8'),
'DURATION'
)
# Lastly we add the cookbook pull-down. This has already been covered in the README: https://github.com/fmtr/hct#example-walkthrough
food_data=hct.MapData({'Default':0, 'Fries':1,'Shrimp':2,'Pizza':3,'Chicken':4,'Fish':5,'Steak':6,'Cake':7,'Bacon':8,'Preheat':9,'Custom':10})
hct.Select(
'Cookbook',
food_data.keys,
nil,
'mdi:chef-hat',
[
Out(
'tuyareceived#dptype4id3',
/value->food_data.out.find(value,'Default')
),
In(
/value->hct.tuya.send(4,3,food_data.in.find(value,0))
)
]
)
# Optional, extended controls. Mainly for aesthetics, convenience in Home Assistant.
hct.Switch(
'Power',
nil,
'mdi:power',
[
Out('power1#state'),
In(
/value->tasmota.set_power(0,value)
)
]
)
hct.Switch(
'Cook/Pause',
nil,
'mdi:play-pause',
[
Out('power2#state'),
In(
/value->tasmota.set_power(1,value)
)
]
)
# Since the functions above make the Keep Warm/Delay switches redundant, expose them instead as sensors.
hct.BinarySensor(
'Keep Warm',
nil,
'mdi:sync-circle',
[Out('power3#state')]
)
hct.BinarySensor(
'Delay',
nil,
'mdi:pause-circle',
[Out('power4#state')]
)