-
Notifications
You must be signed in to change notification settings - Fork 25
/
TOTAL API V6
952 lines (785 loc) · 33.8 KB
/
TOTAL API V6
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
/**
* Total Comfort API
*
* Based on Code by Eric Thomas
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
* lgk v 3 added optional outdoor temp sensors and preferences for it, also made api login required.
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
* lgk version 4 supports celsius and fahrenheit with option, and now colors.
* lgk version 5, due to intermittant update failures added last update date/time tile so that you can see when it happended
* not there is a new input tzoffset which defaults to my time ie -5 which you must set .
* lgk version 6 add support for actually knowing the fan is on or not (added tile),
* and also the actual operating state ie heating,cooling or idle via new response variables.
* lgk version 7, change the new operating state to be a value vs standard tile
* to work around a bug smartthings caused in the latest 2.08 release with text wrapping.
* related also added icons to the operating state, and increase the width of the last update
* to avoid wrapping.
*
*/
preferences {
input("username", "text", title: "Username", description: "Your Total Comfort User Name", required: true)
input("password", "password", title: "Password", description: "Your Total Comfort password",required: true)
input("honeywelldevice", "text", title: "Device ID", description: "Your Device ID", required: true)
input ("enableOutdoorTemps", "enum", title: "Do you have the optional outdoor temperature sensor and want to enable it?", options: ["Yes", "No"], required: false, defaultValue: "No")
input ("tempScale", "enum", title: "Fahrenheit or Celsius?", options: ["F", "C"], required: false, defaultValue: "F")
input("tzOffset", "number", title: "Time zone offset +/-xx?", required: false, defaultValue: -5, description: "Time Zone Offset ie -5.")
}
metadata {
definition (name: "Total Comfort API", namespace:
"Total Comfort API", author: "Eric Thomas, modified lg kahn") {
capability "Polling"
capability "Thermostat"
capability "Refresh"
capability "Temperature Measurement"
capability "Sensor"
capability "Relative Humidity Measurement"
command "heatLevelUp"
command "heatLevelDown"
command "coolLevelUp"
command "coolLevelDown"
attribute "outdoorHumidity", "number"
attribute "outdoorTemperature", "number"
attribute "lastUpdate", "string"
}
simulator {
// TODO: define status and reply messages here
}
tiles {
valueTile("temperature", "device.temperature", width: 2, height: 2, canChangeIcon: true) {
state("temperature", label: '${currentValue}°',
icon: "http://cdn.device-icons.smartthings.com/Weather/[email protected]",
unit:"F", backgroundColors: [
[value: -14, color: "#1e9cbb"],
[value: -10, color: "#90d2a7"],
[value: -5, color: "#44b621"],
[value: -2, color: "#f1d801"],
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
standardTile("thermostatMode", "device.thermostatMode", inactiveLabel: false, canChangeIcon: true) {
state "off", label:'${name}', action:"thermostat.cool", icon: "st.Outdoor.outdoor19"
state "cool", label:'${name}', action:"thermostat.heat", icon: "st.Weather.weather7", backgroundColor: '#1e9cbb'
state "heat", label:'${name}', action:"thermostat.auto", icon: "st.Weather.weather14", backgroundColor: '#E14902'
state "auto", label:'${name}', action:"thermostat.off", icon: "st.Weather.weather3", backgroundColor: '#44b621'
}
standardTile("thermostatFanMode", "device.thermostatFanMode", inactiveLabel: false, canChangeIcon: true) {
state "auto", label:'${name}', action:"thermostat.fanAuto", icon: "st.Appliances.appliances11", backgroundColor: '#44b621'
state "circulate", label:'${name}', action:"thermostat.fanCirculate", icon: "st.Appliances.appliances11", backgroundColor: '#44b621'
state "on", label:'${name}', action:"thermostat.fanOn", icon: "st.Appliances.appliances11", backgroundColor: '#44b621'
}
controlTile("coolSliderControl", "device.coolingSetpoint", "slider", height: 3, width: 1, inactiveLabel: false) {
state "setCoolingSetpoint", label:'Set temperarure to', action:"thermostat.setCoolingSetpoint",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
}
valueTile("coolingSetpoint", "device.coolingSetpoint", inactiveLabel: false)
{
state "default", label:'Cool\n${currentValue}°', unit:"F",
backgroundColors: [
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
}
valueTile("heatingSetpoint", "device.heatingSetpoint", inactiveLabel: false)
{
state "default", label:'Heat\n${currentValue}°', unit: "F",
backgroundColors:[
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 15, color: "#90d2a7"],
[value: 23, color: "#44b621"],
[value: 29, color: "#f1d801"],
[value: 31, color: "#153591"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
}
//tile added for operating state - Create the tiles for each possible state, look at other examples if you wish to change the icons here.
valueTile("thermostatOperatingState", "device.thermostatOperatingState", inactiveLabel: false) {
state "Heating", label:'${name}', backgroundColor : '#E14902', icon: "st.Weather.weather14"
state "Cooling", label:'${name}', backgroundColor : '#1e9cbb', icon: "st.Weather.weather7"
state "Idle", label:'${name}', icon: ""
state "Unknown", label:'${name}', backgroundColor : '#cc0000', icon: ""
}
standardTile("fanOperatingState", "device.fanOperatingState", inactiveLabel: false) {
state "On", label:'${name}',icon: "st.Appliances.appliances11", backgroundColor : '#53a7c0'
state "Idle", label:'${name}',icon: "st.Appliances.appliances11"
state "Unknown", label:'${name}',icon: "st.Appliances.appliances11", backgroundColor : '#cc0000'
}
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, decoration: "flat") {
state "default", action:"polling.poll", icon:"st.secondary.refresh"
}
standardTile("heatLevelUp", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false) {
state "heatLevelUp", label:' ', action:"heatLevelUp", icon:"st.thermostat.thermostat-up"
}
standardTile("heatLevelDown", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false) {
state "heatLevelDown", label:' ', action:"heatLevelDown", icon:"st.thermostat.thermostat-down"
}
standardTile("coolLevelUp", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false) {
state "coolLevelUp", label:' ', action:"coolLevelUp", icon:"st.thermostat.thermostat-up"
}
standardTile("coolLevelDown", "device.heatingSetpoint", canChangeIcon: false, inactiveLabel: false) {
state "coolLevelDown", label:' ', action:"coolLevelDown", icon:"st.thermostat.thermostat-down"
}
valueTile("relativeHumidity", "device.relativeHumidity", inactiveLabel: false)
{
state "default", label:'Humidity\n${currentValue}%',
icon: "http://cdn.device-icons.smartthings.com/Weather/[email protected]",
unit:"%", backgroundColors : [
[value: 01, color: "#724529"],
[value: 11, color: "#724529"],
[value: 21, color: "#724529"],
[value: 35, color: "#44b621"],
[value: 49, color: "#44b621"],
[value: 50, color: "#1e9cbb"]
]
}
standardTile("thermostatMode", "device.thermostatMode", inactiveLabel: false, canChangeIcon: true)
{
}
/* lgk new tiles for outside temp and hummidity */
valueTile("outdoorTemperature", "device.outdoorTemperature", width: 1, height: 1, canChangeIcon: true) {
state("temperature", label: 'Outdoor\n ${currentValue}°',
icon: "http://cdn.device-icons.smartthings.com/Weather/[email protected]",
unit:"F", backgroundColors: [
[value: -31, color: "#003591"],
[value: -10, color: "#90d2a7"],
[value: -5, color: "#44b621"],
[value: -2, color: "#f1d801"],
[value: 0, color: "#153591"],
[value: 7, color: "#1e9cbb"],
[value: 00, color: "#cccccc"],
[value: 31, color: "#153500"],
[value: 44, color: "#1e9cbb"],
[value: 59, color: "#90d2a7"],
[value: 74, color: "#44b621"],
[value: 84, color: "#f1d801"],
[value: 95, color: "#d04e00"],
[value: 96, color: "#bc2323"]
]
)
}
valueTile("outdoorHumidity", "device.outdoorHumidity", inactiveLabel: false){
state "default", label:'Outdoor\n ${currentValue}%',
icon: "http://cdn.device-icons.smartthings.com/Weather/[email protected]",
unit:"%", backgroundColors : [
[value: 01, color: "#724529"],
[value: 11, color: "#724529"],
[value: 21, color: "#724529"],
[value: 35, color: "#44b621"],
[value: 49, color: "#44b621"],
[value: 70, color: "#449c00"],
[value: 90, color: "#009cbb"]
]
}
valueTile("status", "device.lastUpdate", width: 3, height: 1, decoration: "flat") {
state "default", label: 'Last Update: ${currentValue}'
}
main "temperature"
details(["temperature", "thermostatMode", "thermostatFanMode",
"heatLevelUp", "heatingSetpoint" , "heatLevelDown", "coolLevelUp",
"coolingSetpoint", "coolLevelDown" ,"thermostatOperatingState","fanOperatingState",
"refresh","relativeHumidity","outdoorTemperature","outdoorHumidity", "status"])
}
}
def coolLevelUp()
{
state.DisplayUnits = settings.tempScale
if (state.DisplayUnits == "F")
{
int nextLevel = device.currentValue("coolingSetpoint") + 1
if( nextLevel > 99){
nextLevel = 99
}
log.debug "Setting cool set point up to: ${nextLevel}"
setCoolingSetpoint(nextLevel)
}
else
{
int nextLevel = device.currentValue("coolingSetpoint") + 0.5
if( nextLevel > 37){
nextLevel = 37
}
log.debug "Setting cool set point up to: ${nextLevel}"
setCoolingSetpoint(nextLevel)
}
}
def coolLevelDown()
{
state.DisplayUnits = settings.tempScale
if (state.DisplayUnits == "F")
{
int nextLevel = device.currentValue("coolingSetpoint") - 1
if( nextLevel < 50){
nextLevel = 50
}
log.debug "Setting cool set point down to: ${nextLevel}"
setCoolingSetpoint(nextLevel)
}
else
{
double nextLevel = device.currentValue("coolingSetpoint") - 0.5
if( nextLevel < 10){
nextLevel = 10
}
log.debug "Setting cool set point down to: ${nextLevel}"
setCoolingSetpoint(nextLevel)
}
}
def heatLevelUp()
{
state.DisplayUnits = settings.tempScale
if (state.DisplayUnits == "F")
{
log.debug "in fahrenheit level up"
int nextLevel = device.currentValue("heatingSetpoint") + 1
if( nextLevel > 90){
nextLevel = 90
}
log.debug "Setting heat set point up to: ${nextLevel}"
setHeatingSetpoint(nextLevel)
}
else
{
log.debug "in celsius level uo"
double nextLevel = device.currentValue("heatingSetpoint") + 0.5
if( nextLevel > 33){
nextLevel = 33
}
log.debug "Setting heat set point up to: ${nextLevel}"
setHeatingSetpoint(nextLevel)
}
}
def heatLevelDown()
{
state.DisplayUnits = settings.tempScale
if (state.DisplayUnits == "F")
{
log.debug "in fahrenheit level down"
int nextLevel = device.currentValue("heatingSetpoint") - 1
if( nextLevel < 40){
nextLevel = 40
}
log.debug "Setting heat set point down to: ${nextLevel}"
setHeatingSetpoint(nextLevel)
}
else
{
log.debug "in celsius level down"
double nextLevel = device.currentValue("heatingSetpoint") - 0.5
if( nextLevel < 4){
nextLevel = 4
}
log.debug "Setting heat set point down to: ${nextLevel}"
setHeatingSetpoint(nextLevel)
}
}
// parse events into attributes
def parse(String description) {
}
// handle commands
def setHeatingSetpoint(Double temp)
{
data.SystemSwitch = 'null'
data.HeatSetpoint = temp
data.CoolSetpoint = 'null'
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
if(data.SetStatus==1)
{
sendEvent(name: 'heatingSetpoint', value: temp as double)
}
}
def setHeatingSetpoint(temp) {
data.SystemSwitch = 'null'
data.HeatSetpoint = temp
data.CoolSetpoint = 'null'
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
if(data.SetStatus==1)
{
sendEvent(name: 'heatingSetpoint', value: temp as Integer)
}
}
def setCoolingSetpoint(double temp) {
data.SystemSwitch = 'null'
data.HeatSetpoint = 'null'
data.CoolSetpoint = temp
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
if(data.SetStatus==1)
{
sendEvent(name: 'coolingSetpoint', value: temp as double)
}
}
def setCoolingSetpoint(temp) {
data.SystemSwitch = 'null'
data.HeatSetpoint = 'null'
data.CoolSetpoint = temp
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
if(data.SetStatus==1)
{
sendEvent(name: 'coolingSetpoint', value: temp as Integer)
}
}
def setTargetTemp(temp) {
data.SystemSwitch = 'null'
data.HeatSetpoint = temp
data.CoolSetpoint = temp
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
}
def setTargetTemp(double temp) {
data.SystemSwitch = 'null'
data.HeatSetpoint = temp
data.CoolSetpoint = temp
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='1'
data.StatusCool='1'
data.FanMode = 'null'
setStatus()
}
def off() {
setThermostatMode(2)
}
def auto() {
setThermostatMode(4)
}
def heat() {
setThermostatMode(1)
}
def emergencyHeat() {
}
def cool() {
setThermostatMode(3)
}
def setThermostatMode(mode) {
data.SystemSwitch = mode
data.HeatSetpoint = 'null'
data.CoolSetpoint = 'null'
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat=1
data.StatusCool=1
data.FanMode = 'null'
setStatus()
def switchPos
if(mode==1)
switchPos = 'heat'
if(mode==2)
switchPos = 'off'
if(mode==3)
switchPos = 'cool'
/* lgk modified my therm has pos 5 for auto vision pro */
if(mode==4 || swithPos == 5)
switchPos = 'auto'
if(data.SetStatus==1)
{
sendEvent(name: 'thermostatMode', value: switchPos)
}
}
def fanOn() {
setThermostatFanMode(1)
}
def fanAuto() {
setThermostatFanMode(0)
}
def fanCirculate() {
setThermostatFanMode(2)
}
def setThermostatFanMode(mode) {
data.SystemSwitch = 'null'
data.HeatSetpoint = 'null'
data.CoolSetpoint = 'null'
data.HeatNextPeriod = 'null'
data.CoolNextPeriod = 'null'
data.StatusHeat='null'
data.StatusCool='null'
data.FanMode = mode
setStatus()
def fanMode
if(mode==0)
fanMode = 'auto'
if(mode==1)
fanMode = 'on'
if(mode==2)
fanMode = 'circulate'
if(data.SetStatus==1)
{
sendEvent(name: 'thermostatFanMode', value: fanMode)
}
}
def poll() {
refresh()
}
def setStatus() {
data.SetStatus = 0
login()
log.debug "Executing 'setStatus'"
def today= new Date()
log.debug "https://www.mytotalconnectcomfort.com/portal/Device/SubmitControlScreenChanges"
log.debug "setting heat setpoint to $data.HeatSetpoint"
log.debug "setting cool setpoint to $data.CoolSetpoint"
def params = [
uri: "https://www.mytotalconnectcomfort.com/portal/Device/SubmitControlScreenChanges",
headers: [
'Accept': 'application/json, text/javascript, */*; q=0.01',
'DNT': '1',
'Accept-Encoding': 'gzip,deflate,sdch',
'Cache-Control': 'max-age=0',
'Accept-Language': 'en-US,en,q=0.8',
'Connection': 'keep-alive',
'Host': 'rs.alarmnet.com',
'Referer': "https://www.mytotalconnectcomfort.com/portal/Device/Control/${settings.honeywelldevice}",
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
'Cookie': data.cookiess ],
body: [ DeviceID: "${settings.honeywelldevice}", SystemSwitch : data.SystemSwitch ,HeatSetpoint :
data.HeatSetpoint, CoolSetpoint: data.CoolSetpoint, HeatNextPeriod:
data.HeatNextPeriod,CoolNextPeriod:data.CoolNextPeriod,StatusHeat:data.StatusHeat,
StatusCool:data.StatusCool,FanMode:data.FanMode,ThermostatUnits: settings.tempScale]
]
log.debug "params = $params"
httpPost(params) { response ->
log.debug "Request was successful, $response.status"
}
log.debug "SetStatus is 1 now"
data.SetStatus = 1
}
def getStatus() {
log.debug "Executing getStatus"
log.debug "enable outside temps = $enableOutdoorTemps"
def today= new Date()
log.debug "https://www.mytotalconnectcomfort.com/portal/Device/CheckDataSession/${settings.honeywelldevice}?_=$today.time"
def params = [
uri: "https://www.mytotalconnectcomfort.com/portal/Device/CheckDataSession/${settings.honeywelldevice}",
headers: [
'Accept': '*/*',
'DNT': '1',
'Cache' : 'false',
'dataType': 'json',
'Accept-Encoding': 'plain',
'Cache-Control': 'max-age=0',
'Accept-Language': 'en-US,en,q=0.8',
'Connection': 'keep-alive',
'Referer': 'https://www.mytotalconnectcomfort.com/portal',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
'Cookie': data.cookiess ],
]
log.debug "doing request"
httpGet(params) { response ->
log.debug "Request was successful, $response.status"
//log.debug "data = $response.data"
log.debug "ld = $response.data.latestData"
def curTemp = response.data.latestData.uiData.DispTemperature
def fanMode = response.data.latestData.fanData.fanMode
def switchPos = response.data.latestData.uiData.SystemSwitchPosition
def coolSetPoint = response.data.latestData.uiData.CoolSetpoint
def heatSetPoint = response.data.latestData.uiData.HeatSetpoint
def statusCool = response.data.latestData.uiData.StatusCool
def statusHeat = response.data.latestData.uiData.StatusHeat
def curHumidity = response.data.latestData.uiData.IndoorHumidity
def Boolean hasOutdoorHumid = response.data.latestData.uiData.OutdoorHumidityAvailable
def Boolean hasOutdoorTemp = response.data.latestData.uiData.OutdoorTemperatureAvailable
def curOutdoorHumidity = response.data.latestData.uiData.OutdoorHumidity
def curOutdoorTemp = response.data.latestData.uiData.OutdoorTemperature
def displayUnits = response.data.latestData.uiData.DisplayUnits
def fanIsRunning = response.data.latestData.fanData.fanIsRunning
def equipmentStatus = response.data.latestData.uiData.EquipmentOutputStatus
/*ld = [fanData:[fanModeCirculateAllowed:true, fanModeAutoAllowed:true, fanModeFollowScheduleAllowed:false,
fanIsRunning:false, fanModeOnAllowed:true, fanMode:0],
drData:[Load:127.5, HeatSetpLimit:0,
OptOutable:false, DeltaHeatSP:-0.01, CoolSetpLimit:0, Phase:-1, DeltaCoolSP:-0.01],
uiData:[OutdoorTemperature:128.0000, TemporaryHoldUntilTime:0, ScheduleHeatSp:67.0000,
DeviceID:453824, DispTemperatureAvailable:true, VacationHold:0, VacationHoldUntilTime:0,
CoolSetpoint:76.0000, ScheduleCoolSp:76.0000, SwitchHeatAllowed:true, CoolNextPeriod:67,
IndoorHumidity:31.0000, SwitchAutoAllowed:true, SetpointChangeAllowed:true, HeatLowerSetptLimit:40.0000,
OutdoorHumidStatus:128, SwitchOffAllowed:true, OutdoorHumidityAvailable:false,
StatusCool:0, OutdoorTemperatureAvailable:false, EquipmentOutputStatus:0, StatusHeat:0,
CurrentSetpointStatus:0, HoldUntilCapable:true, CoolUpperSetptLimit:99.0000, SwitchCoolAllowed:true,
OutdoorHumidity:128.0000, DualSetpointStatus:false, SwitchEmergencyHeatAllowed:false, Commercial:false,
CoolLowerSetptLimit:50.0000, OutdoorHumiditySensorNotFault:true, IndoorHumiditySensorAvailable:true,
ScheduleCapable:true, DisplayUnits:F, DispTemperature:70.0000, Deadband:3.0000, HeatUpperSetptLimit:90.0000,
IsInVacationHoldMode:false, OutdoorTemperatureSensorNotFault:true, HeatSetpoint:67.0000, DispTemperatureStatus:0,
HeatNextPeriod:67, IndoorHumiditySensorNotFault:true, OutdoorTempStatus:128, IndoorHumidStatus:0,
SystemSwitchPosition:4], canControlHumidification:false, hasFan:true]
log.trace("Fan operating state: ${response.data.latestData.fanData.fanIsRunning}")
log.trace("EquipmentOutputStatus: ${response.data.latestData.uiData.EquipmentOutputStatus}")
log.trace("IndoorHumidity: ${response.data.latestData.uiData.IndoorHumidity}")
log.trace("OutdoorTemp = ${response.data.latestData.uiData.OutdoorTemperature}")
log.trace("fanMode: ${response.data.latestData.fanData.fanMode}")
log.trace("SystenSwitchPosition: ${response.data.latestData.uiData.SystemSwitchPosition}")
log.trace("StatusCool: ${response.data.latestData.uiData.StatusCool}")
log.trace("StatusHeat: ${response.data.latestData.uiData.StatusHeat}")
log.trace("IndoorHumiditySensorAvailable: ${response.data.latestData.uiData.IndoorHumiditySensorAvailable}")
log.trace("IndoorHumidityAvailable: ${response.data.latestData.uiData.IndoorHumidityAvailable}")
log.debug "OutdoorHumidityAvailable: response.data.latestData.uiData.OutdoorHumidityAvailable"
log.debug "OutdoorTemperatureAvailable: $response.data.latestData.uiData.OutdoorTemperatureAvailable"
log.debug "OutdoorHumiditySensorNotFault = $response.data.latestData.uiData.OutdoorHumiditySensorNotFault"
log.debug "OutdoorTemperatureSensorNotFault = $response.data.latestData.uiData.OutdoorTemperatureSensorNotFault"
log.debug "IndoorHumiditySensorNotFault: $response.data.latestData.uiData.IndoorHumiditySensorNotFault"
log.debug "IndoorHumidStatus: $response.data.latestData.uiData.IndoorHumidStatus"
log.debug "OutdoorHumidStatus: $response.data.latestData.uiData.OutdoorHumidStatus"
log.debug "OutdoorHumidity: = $response.data.latestData.uiData.OutdoorHumidity"
log.debug "OutdoorTemperature = $response.data.latestData.uiData.OutdoorTemperature"
log.debug "got curOutdoorTemp = $curOutdoorTemp"
log.debug "got curOutdoorHumidity = $curOutdoorHumidity"
log.debug "hasOutdoorHumid = $hasOutdoorHumid"
log.debug "hasOutdoorTemp = $hasOutdoorTemp"
*/
// log.debug "displayUnits = $displayUnits"
state.DisplayUnits = $displayUnits
//Operating State Section
//Set the operating state to off
def operatingState = "Unknown"
// lgk operating state not working here.. shows both on ie 1 when heat doesnt go on to 67 and heat till 76 and current is 73
//Check the status of heat and cool
// lgk old method now use equipment status
if (equipmentStatus == 1) {
operatingState = "Heating"
} else if (equipmentStatus == 2) {
operatingState = "Cooling"
} else if (equipmentStatus == 0) {
operatingState = "Idle"
} else {
operatingState = "Unknown"
}
/*
if(statusCool == 1 && (switchPos == 3 || switchPos == 5 || swithPos == 4)) {
operatingState = "cooling"
} else if (statusHeat == 1 && (switchPos == 1 || switchPos == 5 || switchPos == 4)) {
operatingState = "heating"
} else if (statusCool == 0 && statusHeat == 0) {
operatingState = "idle"
} else {
operatingState = "unknown"
}
*/
log.trace("Set operating State to: ${operatingState}")
// set fast state
def fanState = "Unknown"
if (fanIsRunning == true)
fanState = "On"
else fanState = "Idle"
log.trace("Set Fan operating State to: ${fanState}")
//End Operating State
// log.debug curTemp
// log.debug fanMode
// log.debug switchPos
//fan mode 0=auto, 2=circ, 1=on
if(fanMode==0)
fanMode = 'auto'
if(fanMode==1)
fanMode = 'on'
if(fanMode==2)
fanMode = 'circulate'
if(switchPos==1)
switchPos = 'heat'
if(switchPos==2)
switchPos = 'off'
if(switchPos==3)
switchPos = 'cool'
if(switchPos==4 || switchPos==5)
switchPos = 'auto'
def formattedCoolSetPoint = String.format("%5.1f", coolSetPoint)
def formattedHeatSetPoint = String.format("%5.1f", heatSetPoint)
def formattedTemp = String.format("%5.1f", curTemp)
def finalCoolSetPoint = formattedCoolSetPoint as BigDecimal
def finalHeatSetPoint = formattedHeatSetPoint as BigDecimal
def finalTemp = formattedTemp as BigDecimal
//Send events
sendEvent(name: 'thermostatOperatingState', value: operatingState)
sendEvent(name: 'fanOperatingState', value: fanState)
sendEvent(name: 'thermostatFanMode', value: fanMode)
sendEvent(name: 'thermostatMode', value: switchPos)
sendEvent(name: 'coolingSetpoint', value: finalCoolSetPoint )
sendEvent(name: 'heatingSetpoint', value: finalHeatSetPoint )
sendEvent(name: 'temperature', value: finalTemp, state: switchPos)
sendEvent(name: 'relativeHumidity', value: curHumidity as Integer)
if (settings.tzOffset == null)
settings.tzOffset = -5
def now = new Date()
def tf = new java.text.SimpleDateFormat("MM/dd/yyyy h:mm a")
tf.setTimeZone(TimeZone.getTimeZone("GMT${settings.tzOffset}"))
def newtime = "${tf.format(now)}" as String
sendEvent(name: "lastUpdate", value: newtime, descriptionText: "Last Update: $newtime")
if (enableOutdoorTemps == "Yes")
{
if (hasOutdoorHumid)
{
sendEvent(name: 'outdoorHumidity', value: curOutdoorHumidity as Integer)
}
if (hasOutdoorTemp)
{
sendEvent(name: 'outdoorTemperature', value: curOutdoorTemp as Integer)
}
}
}
}
def getHumidifierStatus()
{
/*
$.ajax({
url: humUrl,
type: 'POST',
cache: false,
dataType: "json",
success: function(data) {
/portal/Device/Menu/GetHumData/454832';
*/
def params = [
uri: "https://www.mytotalconnectcomfort.com/portal/Device/Menu/GetHumData/${settings.honeywelldevice}",
headers: [
'Accept': '*/*',
'DNT': '1',
'dataType': 'json',
'cache': 'false',
'Accept-Encoding': 'plain',
'Cache-Control': 'max-age=0',
'Accept-Language': 'en-US,en,q=0.8',
'Connection': 'keep-alive',
'Host': 'rs.alarmnet.com',
'Referer': 'https://www.mytotalconnectcomfort.com/portal/Menu/${settings.honeywelldevice}',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
'Cookie': data.cookiess ],
]
httpGet(params) { response ->
log.debug "GetHumidity Request was successful, $response.status"
log.debug "response = $response.data"
// log.debug "ld = $response.data.latestData"
// log.debug "humdata = $response.data.latestData.humData"
log.trace("lowerLimit: ${response.data.latestData.humData.lowerLimit}")
log.trace("upperLimit: ${response.data.humData.upperLimit}")
log.trace("SetPoint: ${response.data.humData.Setpoint}")
log.trace("DeviceId: ${response.data.humData.DeviceId}")
log.trace("IndoorHumidity: ${response.data.humData.IndoorHumidity}")
}
}
def api(method, args = [], success = {}) {
}
// Need to be logged in before this is called. So don't call this. Call api.
def doRequest(uri, args, type, success) {
}
def refresh() {
log.debug "Executing 'refresh'"
def unit = getTemperatureScale()
log.debug "units = $unit"
login()
//getHumidifierStatus()
getStatus()
}
def login() {
log.debug "Executing 'login'"
def params = [
uri: 'https://www.mytotalconnectcomfort.com/portal',
headers: [
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'sdch',
'Host': 'www.mytotalconnectcomfort.com',
'DNT': '1',
'Origin': 'www.mytotalconnectcomfort.com/portal/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36'
],
body: [timeOffset: '240', UserName: "${settings.username}", Password: "${settings.password}", RememberMe: 'false']
]
data.cookiess = ''
httpPost(params) { response ->
log.debug "Request was successful, $response.status"
log.debug response.headers
response.getHeaders('Set-Cookie').each {
String cookie = it.value.split(';|,')[0]
log.debug "Adding cookie to collection: $cookie"
if(cookie != ".ASPXAUTH_TH_A=") {
data.cookiess = data.cookiess+cookie+';'
}
}
log.debug "cookies: $data.cookiess"
}
}
def isLoggedIn() {
if(!data.auth) {
log.debug "No data.auth"
return false
}
def now = new Date().getTime();
return data.auth.expires_in > now
}
def updated()
{
log.debug "in updated"
state.DisplayUnits = settings.tempScale
log.debug "display units now = $state.DisplayUnits"
}
def installed() {
state.DisplayUnits = settings.tempScale
log.debug "display units now = $state.DisplayUnits"
}