-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpropane_monitor.yaml
1328 lines (1262 loc) · 68.6 KB
/
propane_monitor.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
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
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
substitutions:
# If you are interested in this project, and you don't have any Mopeka sensors available,
# change 'sub_show_dev' to "true". This will enable components in the web portal that will allow
# you to test out the different features as if you were connected to an actual sensor. This is
# very helpful if you are not at the same location as your sensors (for example, working on this
# as a winter project when your RV is in storage)
sub_show_dev: "true"
# ---------------------------------------------------------------------------
# Project Specific Substitutions
sub_text_devicename: "PropaneMonitor"
sub_esphome_name: propanemonitor
sub_code_version: "2022.11.29"
# Network and service related substitutions
sub_wifi_ssid1: !secret esp_wifi_ssid1
sub_wifi_password1: !secret esp_wifi_pass1
# Fast connect is only available when a single SSID is used. True or False
sub_wifi_fast_connect: "true"
sub_wifi_ap_password: !secret esp_ap_psk
sub_web_server_port: !secret esp_http_server_port
sub_web_server_auth_user: !secret esp_http_user
sub_web_server_auth_password: !secret esp_http_pass
sub_api_password: !secret esp_api_pass
sub_ota_safe_mode: "true"
sub_ota_password: !secret esp_ota_pass
sub_sensor1_name: "Sensor 1"
sub_sensor1_tank_type: "30LB_V"
sub_sensor1_mac: "F8:DE:AA:BF:F7:0A" # Lippert Sensor
#sub_sensor1_mac: "F6:CC:9C:06:F6:F9" # Mopeka Sensor
sub_sensor1_id: "tank1"
sub_sensor2_name: "Sensor 2"
sub_sensor2_tank_type: "30LB_V"
sub_sensor2_mac: "CC:9C:31:1E:75:8D"
sub_sensor2_id: "tank2"
## Used for the configuration of the display screens
sub_page1_title: "Propane Levels"
sub_page2_title: "Sensor Conditions"
#*****************************************************************************#
esphome:
name: ${sub_esphome_name}
comment: "Lippert integration with mopeka component"
project:
name: "rperciaccante.mopeka_pro_check"
version: ${sub_code_version}
includes:
- tdisplays3/tft_espi_display.h
- tdisplays3/Free_Fonts.h
libraries:
- SPI
- FS
- SPIFFS
- tdisplays3=https://github.com/landonr/lilygo-tdisplays3-esphome.git
on_boot:
priority: 600
then:
script.execute: on_boot
#*****************************************************************************#
esp32:
board: esp32s3box
variant: esp32s3
framework:
type: arduino
version: 2.0.3
platform_version: 5.0.0
#*****************************************************************************#
custom_component:
lambda: |-
App.register_component(display);
return {display};
id: displayComponent
#*****************************************************************************#
# Since the ESPHome component does not support the Lippert propane sensors
# natively, this adds support
external_components:
- source:
type: git
url: https://github.com/rperciaccante/esphome/
ref: mopeka_dev
components: [ mopeka_pro_check ]
#*****************************************************************************#
# Default is DEBUG, set to WARN to keep things easier to manage installation
# and general use - can be changed as needed - https://esphome.io/components/logger.html
logger:
level: DEBUG
#logs:
# ble_client: DEBUG
#*****************************************************************************#
# Best practice is to use specific SSID/PASSWD in local secrets.yaml file.
# For more information on the WiFi component: https://esphome.io/components/wifi.html
# In this configuration, it will enable a local hotspot, which you connect to, and pick the
# WiFi network to connect to.
wifi:
# To define specific SSID/PASSD, uncomment the next 3 lines and add the SSID/PASSED to the secrets.yaml file
networks:
- ssid: ${sub_wifi_ssid1}
password: ${sub_wifi_password1}
ap: # Enable fallback hotspot
ssid: ${sub_text_devicename} Hotspot
# To enable a password on the hotspot, uncomment the next line, and add the ap_password to the secrets.yaml file.
password: ${sub_wifi_ap_password}
#*****************************************************************************#
# This section tells the device to enable a local captive portal which can be used to connect to the device to
# change network settings or to upload a new firmware. This is recommended.
captive_portal:
#*****************************************************************************#
ota:
safe_mode: ${sub_ota_safe_mode}
password: ${sub_ota_password}
#*****************************************************************************#
api:
password: ${sub_api_password}
reboot_timeout: 0s
#*****************************************************************************#
web_server:
include_internal: ${sub_show_dev}
port: ${sub_web_server_port}
js_include: "./css/V2/www.js"
js_url: ""
version: 2
auth:
username: ${sub_web_server_auth_user}
password: ${sub_web_server_auth_password}
#*****************************************************************************#
esp32_ble_tracker:
#*****************************************************************************#
interval:
# Run the errorCheck script every 5 seconds
- interval: 5s
then:
- script.execute: errorCheck
# ---------------------------------------------------------------------------
- interval: 10s
then:
- script.execute: pageRefresh
- if:
condition:
switch.is_on: refreshEnabled
then:
- number.increment: pageCurrent
#*****************************************************************************#
# Binary Sensors
binary_sensor:
- id: deviceShowWelcome
platform: template
name: (DEV) State - Show Welcome Message
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 1 Error status
# in the web interface
- id: sensor1HasError
platform: template
name: (DEV) Error - Sensor 1
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 1 Battery Error status
# in the web interface
- id: sensor1BattError
platform: template
name: (DEV) Error - Sensor 1 Battery
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 1 Bluetooth Signal Error status
# in the web interface
- id: sensor1BTSignalError
platform: template
name: (DEV) Error - Sensor 1 BT Signal
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 2 Error status
# in the web interface
- id: sensor2HasError
platform: template
name: (DEV) Error - Sensor 2
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 2 Battery Error status
# in the web interface
- id: sensor2BattError
platform: template
name: (DEV) Error - Sensor 2 Battery
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to see the status of the Sensor 1 Bluetooth Signal Error status
# in the web interface
- id: sensor2BTSignalError
platform: template
name: (DEV) Error - Sensor 2 Battery
internal: true
# ---------------------------------------------------------------------------
- id: pageNext
platform: gpio
pin:
number: GPIO0
inverted: true
name: ${sub_text_devicename} Page Next
internal: true
on_click:
- min_length: 50ms
max_length: 350ms
then:
- script.execute: screenTimer
- switch.turn_on: backlight
- switch.turn_off: refreshEnabled
- number.increment: pageCurrent
- script.execute: pageRefresh
- min_length: 1000ms
max_length: 2000ms
then:
- script.execute: screenTimer
- switch.toggle: refreshEnabled
- switch.turn_on: backlight
- script.stop: pageRefresh
- script.execute: displayRotationStatus
- delay: 3s
- script.execute: pageRefresh
# ---------------------------------------------------------------------------
- id: screen
platform: gpio
pin:
number: GPIO14
inverted: true
name: ${sub_text_devicename} Screen
internal: true
on_click:
- min_length: 50ms
max_length: 350ms
then:
- script.execute: screenTimer
- switch.toggle: backlight
- min_length: 1000ms
max_length: 2000ms
then:
- script.execute: screenTimer
- switch.turn_on: backlight
- switch.toggle: screensaver
- script.execute: displayScreensaverStatus
- delay: 3s
#*****************************************************************************#
# Buttons
button:
- id: reboot
platform: restart
name: ${sub_text_devicename} Device Restart
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to trigger the screensaver timeout
# in the web interface
- id: triggerScreensaver
platform: template
name: (DEV) Device - Trigger Screensaver Timeout
internal: true
on_press:
then:
- script.execute: screenTimer
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to refresh the current page view
# in the web interface
- id: rotatePage
platform: template
name: (DEV) Page - Refresh Current
internal: true
on_press:
then:
- script.execute: pageRefresh
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to force view of Page 1 (sensor level widgets)
# in the web interface
- id: dev_showPage1
platform: template
name: (DEV) Page - Show Page 1
internal: true
on_press:
then:
- script.execute: pageBuild1
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to force view of Page 2 (Sensor Conditions)
# in the web interface
- id: dev_showPage2
platform: template
name: (DEV) Page - Show Page 2
internal: true
on_press:
then:
- script.execute: pageBuild2
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to force view of Page 3 (Network Information)
# in the web interface
- id: dev_showPage3
platform: template
name: (DEV) Page - Show Page 3
internal: true
on_press:
then:
- script.execute: pageBuild3
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to force view of Rotation Status page
# in the web interface
- id: dev_showScrollStatus
platform: template
name: (DEV) Page - Show Scroll Status
internal: true
on_press:
then:
- script.execute: displayRotationStatus
- number.increment: pageCurrent
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to force view of Screensaver Status page
# in the web interface
- id: dev_showScreenSaverStatus
platform: template
name: (DEV) Page - Show Screensaver Status
internal: true
on_press:
then:
- script.execute: displayScreensaverStatus
#*****************************************************************************#
# Numbers
number:
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to change the page currenty displayed on the LCD
# in the web interface
- id: pageCurrent
platform: template
name: Current Page
internal: true
optimistic: true
initial_value: 0
min_value: 0
max_value: 2
step: 1
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 1 level
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor1LPLevel
platform: template
name: (DEV) LP Level - Sensor 1
internal: true
optimistic: true
initial_value: -1
min_value: -1
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor1LPLevel).publish_state(id(dev_sensor1LPLevel).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 2 level in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor2LPLevel
platform: template
name: (DEV) LP Level - Sensor 2
internal: true
optimistic: true
initial_value: -1
min_value: -1
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor2LPLevel).publish_state(id(dev_sensor2LPLevel).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 1 battery level in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor1Batt
platform: template
name: (DEV) Battery - Sensor 1
internal: true
optimistic: true
initial_value: -1
min_value: -1
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor1Batt).publish_state(id(dev_sensor1Batt).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 2 battery level in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor2Batt
platform: template
name: (DEV) Battery - Sensor 2
internal: true
optimistic: true
initial_value: -1
min_value: -1
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor2Batt).publish_state(id(dev_sensor2Batt).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 1 temperature in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor1Temp
platform: template
name: (DEV) Temp - Sensor 1
internal: true
optimistic: true
initial_value: -50
min_value: -50
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor1Temp).publish_state(id(dev_sensor1Temp).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 2 temperature in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor2Temp
platform: template
name: (DEV) Temp - Sensor 2
internal: true
optimistic: true
initial_value: -50
min_value: -50
max_value: 100
step: 1
on_value:
then:
- lambda: |-
id(sensor2Temp).publish_state(id(dev_sensor2Temp).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 1 bluetooth signal level in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor1BTSignal
platform: template
name: (DEV) BT Signal - Sensor 1
internal: true
optimistic: true
initial_value: 1
min_value: -100
max_value: 1
step: 1
on_value:
then:
- lambda: |-
id(sensor1BTSignal).publish_state(id(dev_sensor1BTSignal).state);
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will allow you to set the current sensor 2 bluetooth signal level in the web interface
# Initial value is set outside acceptable range so as not to impact legitimate sensor levels
# ** NOTE ** this sends the value directly to sensor opject to replicate exactly how the device processes values
- id: dev_sensor2BTSignal
platform: template
name: (DEV) BT Signal - Sensor 2
internal: true
optimistic: true
initial_value: 1
min_value: -100
max_value: 1
step: 1
on_value:
then:
- lambda: |-
id(sensor2BTSignal).publish_state(id(dev_sensor2BTSignal).state);
#*****************************************************************************#
# Sensors
sensor:
# ---------------------------------------------------------------------------
- id: uptime_s
platform: uptime
update_interval: 10s
internal: true
# ---------------------------------------------------------------------------
- id: ${sub_esphome_name}_wifi_signal
platform: wifi_signal
name: ${sub_text_devicename} Device WiFi Signal
unit_of_measurement: "dBm"
device_class: "signal_strength"
state_class: "measurement"
entity_category: diagnostic
update_interval: 30s
# ---------------------------------------------------------------------------
- platform: mopeka_pro_check
mac_address: ${sub_sensor1_mac}
tank_type: ${sub_sensor1_tank_type}
temperature:
name: ${sub_text_devicename} ${sub_sensor1_name} Temp
id: sensor1Temp
unit_of_measurement: "°F"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 0
filters:
- lambda: return x * (9.0/5.0) + 32.0;
on_value:
then:
- lambda: |-
float sensorTemp = id(sensor1Temp).state;
if ((sensorTemp < -20) || (sensorTemp > 150)) {
id(sensor1Temp).state = -99;
}
level:
name: ${sub_text_devicename} ${sub_sensor1_name} Level
id: sensor1LPLevel
unit_of_measurement: "%"
state_class: "measurement"
accuracy_decimals: 0
on_value:
then:
- sensor.template.publish:
id: sensor1LvlBGColor
state: !lambda |-
float checkValue = id(sensor1LPLevel).state;
float redThreshold = 20;
float orangeThreshold = 40;
float yellowThreshold = 60;
float greenThreshold = 80;
if (checkValue > 100 || checkValue < 0) {
id(sensor1LPLevel).state = -99;
}
if ((checkValue > redThreshold) && (checkValue <= orangeThreshold)){
return display->tft.color565(255, 180, 0); // orange
} else if ((checkValue > orangeThreshold) && (checkValue <= yellowThreshold)){
return display->tft.color565(255, 255, 0); // yellow
} else if ((checkValue > yellowThreshold) && (checkValue <= greenThreshold)){
return display->tft.color565(180, 255, 0); // greenyellow
} else if ((checkValue > greenThreshold) && (checkValue <= 100)){
return display->tft.color565(0, 255, 0); // green
} else {
return display->tft.color565(255, 0, 0); // red
}
battery_level:
name: ${sub_text_devicename} ${sub_sensor1_name} Battery
id: sensor1Batt
unit_of_measurement: "%"
device_class: "battery"
state_class: "measurement"
accuracy_decimals: 0
on_value:
then:
- sensor.template.publish:
id: sensor1BattBGColor
state: !lambda |-
float checkValue = id(sensor1Batt).state;
float greenThreshold = 50;
if ((checkValue > 100) || (checkValue < 0)) {
id(sensor1Batt).state = -99;
}
if ((checkValue >= greenThreshold)) {
id(sensor1BattError).publish_state(false);
return display->tft.color565(0, 0, 0); // black
} else {
id(sensor1BattError).publish_state(true);
ESP_LOGW("errorCheck","${sub_sensor1_name} Battery level outside of margins: %.0f", checkValue);
return display->tft.color565(255, 0, 0); // red
}
# ---------------------------------------------------------------------------
- platform: mopeka_pro_check
mac_address: ${sub_sensor2_mac}
tank_type: ${sub_sensor2_tank_type}
temperature:
name: ${sub_text_devicename} ${sub_sensor2_name} Temp
id: sensor2Temp
unit_of_measurement: "°F"
device_class: "temperature"
state_class: "measurement"
accuracy_decimals: 0
filters:
- lambda: return x * (9.0/5.0) + 32.0;
on_value:
then:
- lambda: |-
float sensorTemp = id(sensor2Temp).state;
if ((sensorTemp < -20) || (sensorTemp > 150)) {
id(sensor2Temp).state = -99;
}
level:
name: ${sub_text_devicename} ${sub_sensor2_name} Level
id: sensor2LPLevel
unit_of_measurement: "%"
state_class: "measurement"
accuracy_decimals: 0
on_value:
then:
- sensor.template.publish:
id: sensor2LvlBGColor
state: !lambda |-
float checkValue = id(sensor2LPLevel).state;
float redThreshold = 20;
float orangeThreshold = 40;
float yellowThreshold = 60;
float greenThreshold = 80;
if ((checkValue > 100) || (checkValue < 0)) {
id(sensor2LPLevel).state = -99;
}
if ((checkValue > redThreshold) && (checkValue <= orangeThreshold)){
return display->tft.color565(255, 180, 0); // orange
} else if ((checkValue > orangeThreshold) && (checkValue <= yellowThreshold)){
return display->tft.color565(255, 255, 0); // yellow
} else if ((checkValue > yellowThreshold) && (checkValue <= greenThreshold)){
return display->tft.color565(180, 255, 0); // greenyellow
} else if ((checkValue > greenThreshold) && (checkValue <= 100)){
return display->tft.color565(0, 255, 0); // green
} else {
return display->tft.color565(255, 0, 0); // red
}
battery_level:
name: ${sub_text_devicename} ${sub_sensor2_name} Battery
id: sensor2Batt
unit_of_measurement: "%"
device_class: "battery"
state_class: "measurement"
accuracy_decimals: 0
on_value:
then:
- sensor.template.publish:
id: sensor2BattBGColor
state: !lambda |-
float checkValue = id(sensor2Batt).state;
float greenThreshold = 50;
if ((checkValue > 100) || (checkValue < 0)) {
id(sensor2Batt).state = -99;
}
if ((checkValue >= greenThreshold)) {
id(sensor2BattError).publish_state(false);
return display->tft.color565(0, 0, 0); // black
} else {
id(sensor2BattError).publish_state(true);
ESP_LOGW("errorCheck","${sub_sensor2_name} Battery level outside of margins: %.0f", checkValue);
return display->tft.color565(255, 0, 0); // red
}
- script.execute: errorCheck
# ---------------------------------------------------------------------------
- id: sensor1BTSignal
platform: ble_rssi
mac_address: ${sub_sensor1_mac}
name: ${sub_text_devicename} ${sub_sensor1_name} BLE RSSI
unit_of_measurement: "dBm"
device_class: "signal_strength"
state_class: "measurement"
entity_category: diagnostic
accuracy_decimals: 0
icon: mdi:signal
on_value:
then:
- sensor.template.publish:
id: sensor1BTSignalBGColor
state: !lambda |-
float checkValue = id(sensor1BTSignal).state;
float redThreshold = -80;
if ((checkValue > redThreshold) && (checkValue < 0)) {
id(sensor1BTSignalError).publish_state(false);
return display->tft.color565(0, 0, 0); // black
} else {
id(sensor1BTSignalError).publish_state(true);
ESP_LOGW("errorCheck","${sub_sensor1_name} BLE RSSI level outside of margins: %.0f", checkValue);
return display->tft.color565(255, 0, 0); // red
}
- script.execute: errorCheck
# ---------------------------------------------------------------------------
- id: sensor2BTSignal
platform: ble_rssi
mac_address: ${sub_sensor2_mac}
name: ${sub_text_devicename} ${sub_sensor2_name} BLE RSSI
unit_of_measurement: "dBm"
device_class: "signal_strength"
state_class: "measurement"
entity_category: diagnostic
accuracy_decimals: 0
icon: mdi:signal
on_value:
then:
- sensor.template.publish:
id: sensor2BTSignalBGColor
state: !lambda |-
float checkValue = id(sensor2BTSignal).state;
float redThreshold = -80;
if ((checkValue < -98) || (checkValue >= 0)) {
id(sensor2BTSignal).state = -99;
}
if ((checkValue > redThreshold) && (checkValue < 0)) {
id(sensor2BTSignalError).publish_state(false);
return display->tft.color565(0, 0, 0); // black
} else {
id(sensor2BTSignalError).publish_state(true);
ESP_LOGW("errorCheck","${sub_sensor2_name} BLE RSSI level outside of margins: %.0f", checkValue);
return display->tft.color565(255, 0, 0); // red
}
- script.execute: errorCheck
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 1 level widget
# in the web interface
- id: sensor1LvlBGColor
platform: template
name: (DEV) Display - Sensor 1 LP Level BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 2 level widget
# in the web interface
- id: sensor1BattBGColor
platform: template
name: (DEV) Display - Sensor 1 Battery BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 1 bluetooth signal widget
# in the web interface
- id: sensor1BTSignalBGColor
platform: template
name: (DEV) Display - Sensor 1 BT Signal BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 1 temp widget
# in the web interface
- id: sensor1TempBGColor
platform: template
name: (DEV) Display - Sensor 1 Temp BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 2 bluetooth signal widget
# in the web interface
- id: sensor2LvlBGColor
platform: template
name: (DEV) Display - Sensor 2 Level BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 1 battery level widget
# in the web interface
- id: sensor2BattBGColor
platform: template
name: (DEV) Display - Sensor 2 Battery BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 2 battery level widget
# in the web interface
- id: sensor2BTSignalBGColor
platform: template
name: (DEV) Display - Sensor 2 ST Signal BG Color
internal: true
# ---------------------------------------------------------------------------
# Visible ONLY in the web portal, this will display the background color used for the sensor 2 temp widget
# in the web interface
- id: sensor2TempBGColor
platform: template
name: (DEV) Display - Sensor 2 Temp BG Color
internal: true
#*****************************************************************************#
# Scripts
script:
- id: on_boot
then:
- logger.log: "System bootup underway..."
- switch.turn_on: backlight
- lambda: |-
id(deviceShowWelcome).publish_state(true);
- script.execute: pageWelcome
- delay: 500ms
- switch.turn_on: refreshEnabled
- script.execute: screenTimer
- delay: 5s
- text_sensor.template.publish:
id: codeVersion
state: ${sub_code_version}
- lambda: |-
id(sensor1HasError).publish_state(false);
id(sensor2HasError).publish_state(false);
id(sensor1MACAddress).publish_state("${sub_sensor1_mac}");
id(sensor2MACAddress).publish_state("${sub_sensor2_mac}");
# ---------------------------------------------------------------------------
- id: screenTimer
mode: restart
then:
- logger.log:
format: "Screen timeout script called"
level: WARN
- if:
condition:
switch.is_on: screensaver
then:
- delay: 60s
- logger.log: "Screen timeout reached"
- switch.turn_off: backlight
# ---------------------------------------------------------------------------
- id: errorCheck
mode: restart
then:
- lambda: |-
if (id(sensor1BattError).state == true || id(sensor1BTSignalError).state == true) {
id(sensor1HasError).publish_state(true);
} else {
id(sensor1HasError).publish_state(false);
};
if (id(sensor2BattError).state == true || id(sensor2BTSignalError).state == true) {
id(sensor2HasError).publish_state(true);
} else {
id(sensor2HasError).publish_state(false);
};
# ---------------------------------------------------------------------------
- id: pageRefresh
mode: restart
then:
if:
condition:
- binary_sensor.is_off: deviceShowWelcome
then:
- lambda: |-
static script::Script<> *scripts[] = {id(pageBuild1), id(pageBuild2), id(pageBuild3)};
int current_page = id(pageCurrent).state;
scripts[current_page]->execute();
# ---------------------------------------------------------------------------
- id: pageBuild1
mode: restart
then:
- lambda: |-
int xWidth = display->tft.width();
int yHeight = display->tft.height();
int xCenter = xWidth / 2;
int yHLine = 34; // Vertical position of horizontal line
int yColHeaderCenter = yHLine + 15;
int xLoffset = 10;
int xRoffset = 310;
int xCol1Center = 80;
int xCol2Center = 240;
int xCRoffset = xCenter + 10;
int xCLoffset = xCenter - 10;
int colYOffset = 40;
float level1 = id(sensor1LPLevel).state;
float level2 = id(sensor2LPLevel).state;
//**********************************************************************************
// Build common page layout - two rows
display->tft.fillScreen(TFT_BLACK);
display->tft.setRotation(1);
display->tft.setTextColor(TFT_WHITE, TFT_BLACK);
display->tft.drawRoundRect(0, 0, xWidth, yHeight, 10, TFT_RED);
display->tft.drawFastHLine(0, yHLine, xWidth, TFT_RED);
display->tft.setFreeFont(FMB12);
display->tft.setTextDatum(MC_DATUM);
// *** If a 2 column page, draw vertical line ***
display->tft.drawFastVLine(160, 35, 135, TFT_RED);
// Display page1 title
display->tft.drawString("${sub_page1_title}",xCenter, yHLine / 2);
// If there is an error on sensor 1, display error indicator before heading
if (id(sensor1HasError).state == true) {
display->tft.setFreeFont(FSB9);
display->tft.setTextColor(TFT_WHITE, TFT_RED);
display->tft.fillCircle(xCLoffset - 5,colYOffset +10,10, TFT_RED);
display->tft.drawString("!",xCLoffset - 5,colYOffset +10);
display->tft.setFreeFont(FMB12);
display->tft.setTextColor(TFT_WHITE, TFT_BLACK);
}
display->tft.drawString("${sub_sensor1_name}",xCol1Center ,yColHeaderCenter);
// If there is an error on sensor 2, display error indicator before heading
if (id(sensor2HasError).state == true) {
display->tft.setTextColor(TFT_WHITE, TFT_RED);
display->tft.fillCircle(xRoffset - 5,colYOffset +10,10, TFT_RED);
display->tft.setFreeFont(FSB9);
display->tft.drawString("!",xRoffset - 5,colYOffset +10);
display->tft.setFreeFont(FMB12);
}
display->tft.setTextColor(TFT_WHITE, TFT_BLACK);
display->tft.drawString("${sub_sensor2_name}",xCol2Center,yColHeaderCenter);
// Build the Col1 Sensor background color
display->tft.setFreeFont(FSB24);
display->tft.setTextColor(TFT_BLACK, id(sensor1LvlBGColor).state);
display->tft.fillRoundRect(xLoffset + 5, colYOffset + 30, 126, 90, 10, id(sensor1LvlBGColor).state);
// Display sensor 1 level value
display->tft.setTextDatum(ML_DATUM);
display->tft.drawString("%", xCol1Center + 15, 110);
display->tft.setTextDatum(MR_DATUM);
if (level1 <= 100 && level1 >= 0) {
display->tft.drawFloat(level1,0, xCol1Center +14, 110);
} else {
display->tft.drawString("--", xCol1Center +14, 110);
}
// Build the Col2 Sensor background color
display->tft.setFreeFont(FSB24);
display->tft.setTextColor(TFT_BLACK, id(sensor2LvlBGColor).state);
display->tft.fillRoundRect(xCRoffset + 5, colYOffset + 30, 126, 90, 10, id(sensor2LvlBGColor).state);
// Display sensor 1 level value
display->tft.setTextDatum(ML_DATUM);
display->tft.drawString("%", xCol2Center + 15, 110);
display->tft.setTextDatum(MR_DATUM);
if (level2 <= 100 && level2 >= 0) {
display->tft.drawFloat(level2,0, xCol2Center + 14, 110);
} else {
display->tft.drawString("--", xCol2Center + 14, 110);
}
# ---------------------------------------------------------------------------
- id: pageBuild2
mode: restart
then:
- lambda: |-
int xWidth = display->tft.width();
int yHeight = display->tft.height();
int xCenter = xWidth / 2;
int yHLine = 34;
int yColHeaderCenter = yHLine + 15;
int lineYoffset = 20;
int yLine1 = 75;
int yLine2 = yLine1 + lineYoffset;
int yLine3 = yLine2 + lineYoffset;
int yLine4 = yLine3 + lineYoffset;
int yLine5 = yLine4 + lineYoffset;
int xLoffset = 10;
int xRoffset = 310;
int xCol1Center = 80;
int xCol2Center = 240;
int xCRoffset = xCenter + 10;
int xCLoffset = xCenter - 10;
int colYOffset = 40;
float batt1 = id(sensor1Batt).state;
float batt2 = id(sensor2Batt).state;
float btsignal1 = id(sensor1BTSignal).state;
float btsignal2 = id(sensor2BTSignal).state;
float level1 = id(sensor1LPLevel).state;
float level2 = id(sensor2LPLevel).state;
float temp1 = id(sensor1Temp).state;
float temp2 = id(sensor2Temp).state;
// Build common page layout - two rows
display->tft.fillScreen(TFT_BLACK);
display->tft.setRotation(1);
display->tft.setTextColor(TFT_WHITE, TFT_BLACK);
display->tft.drawRoundRect(0, 0, xWidth, yHeight, 10, TFT_RED);
display->tft.drawFastHLine(0, yHLine, xWidth, TFT_RED);
display->tft.setFreeFont(FMB12);
display->tft.setTextDatum(MC_DATUM);
// *** If a 2 column page, draw vertical line ***
display->tft.drawFastVLine(160, 35, 135, TFT_RED);
// Display page2 title
display->tft.drawString("${sub_page2_title}",xCenter, yHLine / 2);
// Print page and column headers
display->tft.drawString("${sub_sensor1_name}",xCol1Center ,yColHeaderCenter);
display->tft.drawString("${sub_sensor2_name}",xCol2Center,yColHeaderCenter);
// print MAC address under sensor name
display->tft.setFreeFont(FS9);
display->tft.drawString("${sub_sensor1_mac}",xCol1Center, yLine1);
display->tft.drawString("${sub_sensor2_mac}",xCol2Center, yLine1);
// Column 1
// Attribute Labels - each is inside a black rectangle we can change the color of in case of error
display->tft.setFreeFont(FS9);
// Build the column 1 "BT Signal" line
display->tft.setTextDatum(ML_DATUM);
display->tft.setTextColor(TFT_WHITE, id(sensor1BTSignalBGColor).state);
display->tft.fillRoundRect(5, yLine2 - 8, 151, 20, 5, id(sensor1BTSignalBGColor).state);
display->tft.drawString("BT Signal:", xLoffset, yLine2);
display->tft.setTextDatum(MR_DATUM);
if (btsignal1 != -99) {
display->tft.drawFloat(btsignal1,0, xCLoffset-37, yLine2);
} else {
display->tft.drawString("--", xCLoffset-37, yLine2);
}
display->tft.drawString("dBm", xCLoffset, yLine2);
display->tft.setTextColor(TFT_WHITE, TFT_BLACK);
// Build the column 1 "Battery" line
display->tft.setTextDatum(ML_DATUM);
display->tft.setTextColor(TFT_WHITE, id(sensor1BattBGColor).state);
display->tft.fillRoundRect(5, yLine3 - 8, 151, 20, 5, id(sensor1BattBGColor).state);
display->tft.drawString("Battery:", xLoffset, yLine3);
display->tft.setTextDatum(MR_DATUM);
if (batt1 != -99) {