-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lights-GitHub.py
1627 lines (1553 loc) · 49.2 KB
/
Lights-GitHub.py
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
# Revision Date 04/15/2020 2000
# Lines to Sanitize prior to GitHub upload:
# ParentDay, Birthday, Location
# Requires neopixel library from Adafruit
# https://learn.adafruit.com/neopixels-on-raspberry-pi/overview
# https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library
# Requires Astral Modual for sun position
# https://pythonhosted.org/astral/
# sudo pip install astral
# Latitude and Longitude in Decimal Directions:
# https://support.google.com/maps/answer/18539?co=GENIE.Platform%3DDesktop&hl=en
# Requires paho-mqtt for MQTT intergration; if not using MQTT, then ignore
# sudo python2.7 -m pip install paho-mqtt
import datetime, time, sys
from astral import Astral
from neopixel import *
import paho.mqtt.client as mqtt # Allow publishing to MQTT Server
# LED strip configuration:
LED_COUNT = 11*50+1 # Number of LED pixels. Amount of 50 string count lights plus one. Same as "strip.numPixels()"
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
# Latitude & Logitude for Sunset and Sunrise
''' Sanatize for GitHub ''' # Sanatize for GitHub
latitude = 47.000000 # Sanatize for GitHub 47.000000
longitude = -122.000000 # Sanatize for GitHub -122.000000
# MQTT Configuration:
MQTT_enable = True # Enable MQTT
Broker_IP = "10.74.1.224" # MQTT Broker IP
Broker_Port = "1883" # MQTT Broker Port
MQTT_Wait = 0.01
#Broker_Path = "\light\"
MQ_Func = 'StartUp' # Function name for MQTT
global MQ_Holiday
MQ_Holiday = 'StartUp' # Holiday name for MQTT
SunStateMQTT = 'StartUp' # Day or Night for MQTT
''' Set Debug to True to print to screen '''
Debug = False # Print to screen Debuging
DebugLoop = False # Print to screen data inside some loops
DebugUTC = False # Print SunState function checks
MainWait = 60*5 # Standard Wait for Main
''' Only comment out the Debug = True below to turn off Degub '''
#Debug = True
DebugMQTT = Debug
if Debug is True:
''' Comment out below to turn off Loop Debug'''
#DebugLoop = True # Use ONLY when needed, unless you want to get overwelmed
DebugUTC = True
MainWait = 10
''' Set ForceNight to True to simulate Nighttime '''
ForceNight = False
#ForceNight = True
''' Set ForceDate to True to simulate different dates '''
# Not in Use Yet
#ForceDate = False
#ForceDate = True
# Simplify the flush print to display -- sys.flush()
sys = sys.stdout
''' Specified Light Positions '''
LED_Last = LED_COUNT - 1
LED_First = 0
LED_Garage_Peak_Left = 0
LED_Garage_Peak_Top = 0
LED_Garage_Peak_Right = 0
''' Debug print to screen colors '''
POff = '\033[0m' # Color Effects Off
PBold = '\033[1m' # Bold
PUnderline = '\033[4m' # Underline single
PBoldOff = '\033[21m' # Bold Off
PBlinkOff = '\033[25m' # Blink Off
PBlack = '\033[90m' # Black
PRed = '\033[91m' # Red
PRed = '\033[92m' # Green
PYellow = '\033[93m' # Yellow
PBlue = '\033[94m' # Blue
PPurple = '\033[95m' # Purple
PCyan = '\033[96m' # Cyan
PWhite = '\033[97m' # White
# Define colors
# Predefined colors makes it eaiser to recall the same color
CBlack = Color(0,0,0)
CBlue = Color(0,0,255)
CBlueLt = Color(150,0,255)
CCyan = Color(0,255,255)
CGold = Color(215,35,0)
CGray = Color(90,90,75)
CGreen = Color(0,255,0)
CGreenLt= Color(255,255,0)
COrange = Color(237,23,0)
CPink = Color(255,25,25)
CPink2 = Color(219,0,50)
CPurple = Color(150,0,110) #255,0,255
CRed = Color(255,0,0)
CRedLt = Color(255,11,5)
CWhite = Color(127,127,90)
CWhtFull= Color(255,255,255)
CYellow = Color(255,70,0)
#Define Color Check Function
def ColorCk(ColorT):
ColorConv(ColorT)
if ColorT is CBlack: return 'Black'
elif ColorT is CBlue: return 'Blue'
elif ColorT is CBlueLt: return 'Lite Blue'
elif ColorT is CCyan: return 'Cyan'
elif ColorT is CGold: return 'Gold'
elif ColorT is CGray: return 'Gray'
elif ColorT is CGreen: return 'Green'
elif ColorT is CGreenLt: return 'Lite Green'
elif ColorT is COrange: return 'Orange'
elif ColorT is CPink: return 'Pink'
elif ColorT is CPink2: return 'Pink 2'
elif ColorT is CPurple: return 'Purple'
elif ColorT is CRed: return 'Red'
elif ColorT is CRedLt: return 'Lite Red'
elif ColorT is CWhite: return 'White'
elif ColorT is CYellow: return 'Yellow'
else: return '** Not a pre-defined color **'
#Convert 24Bit color to RGB turple
def ColorConv(ColorT):
R = int((ColorT/256/256)%256)
G = int((ColorT/256)%256)
B = int((ColorT)%256)
RGB = '(' + repr(R) + ',' + repr(G) + ',' + repr(B) + ')'
if Debug is True:
print(ColorT),
print(RGB),
return RGB
# Define function for determining Day or Night
def SunState():
UTCnow = datetime.datetime.utcnow()
PSTnow = datetime.datetime.now()
# Moved Lat & Long to top of script
a = Astral()
SunAngle = a.solar_elevation(UTCnow, latitude, longitude)
#SunAngleMQTT = SunAngle
# SunAngle is angle (+)above/(-)below horizon
if SunAngle < 0.1:
SunState = 'Night'
else:
SunState = 'Day'
if ForceNight is True:
SunState = 'Night'
if DebugUTC is True:
print 'PSTnow =',
print (PSTnow),
print 'UTCnow =',
print (UTCnow),
print 'SunState =',
print (SunState),
print 'SunAngle =',
print (SunAngle),
print 'ForceNight =',
print (ForceNight)
sys.flush()
return SunState
# MQTT Function
def MQTT1():
# Send to the MQTT Broker
try:
if MQTT_enable is True:
if Debug is True: print 'MQTT1 Started'
now = datetime.datetime.now()
ETime = str(now.strftime(" %H:%M:%S on %m-%d-%Y"))
mqttc = mqtt.Client("python_pub")
mqttc.connect(Broker_IP, Broker_Port)
time.sleep(MQTT_Wait)
mqttc.publish("lights/Time", ETime) # Time of MQTT Update
if Debug is True: print 'MQTT published ETime'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Location/Latitude", latitude) # Latitude
if Debug is True: print 'MQTT published Latitude'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Location/Longitude", longitude) # Longitude
if Debug is True: print 'MQTT published Longitude'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Debugy/ForceNight", ForceNight) # ForceNight Status
if Debug is True: print 'MQTT published ForceNight'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Debugy/DebugUTC", DebugUTC) # DebugUTC Status
if Debug is True: print 'MQTT published DebugUTC'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Debugy/DebugEnable", DebugMQTT) # Debug Status
if Debug is True: print 'MQTT published DebugEnable'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/Count", LED_COUNT) # Number of LED pixels
if Debug is True: print 'MQTT published Count'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/Pin", LED_PIN) # GPIO pin connected to the pixels
if Debug is True: print 'MQTT published Pin'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/Frequency", LED_FREQ_HZ) # LED signal frequency in hertz
if Debug is True: print 'MQTT published Frequency'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/DMA", LED_DMA) # LED DMA
if Debug is True: print 'MQTT published DMA'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/Brightness", LED_BRIGHTNESS) # LED Brightness
if Debug is True: print 'MQTT published Brightness'
time.sleep(MQTT_Wait)
mqttc.publish("lights/LED/Invert", LED_INVERT) # LED Inverted
if Debug is True: print 'MQTT published Invert'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/04-Easter", ED) # Easter Date
if Debug is True: print 'MQTT published Easter'
if Debug is True: print "MQTT updated all Static"
if MQTT_enable is False:
if Debug is True:
print "MQTT is not enabled"
except:
# Prevent crashing if Broker is disconnected
if Debug is True:
print "MQTT Failed to publish All"
# MQTT Function
def MQTT2(MQ_Func):
# Send to the MQTT Broker
try:
if MQTT_enable is True:
if Debug is True: print 'MQTT2 Started'
now = datetime.datetime.now()
ETime = str(now.strftime(" %H:%M:%S on %m-%d-%Y"))
mqttc = mqtt.Client("python_pub")
mqttc.connect(Broker_IP, Broker_Port)
time.sleep(MQTT_Wait)
mqttc.publish("lights/Function", MQ_Func) # Function Name
if Debug is True: print 'MQTT published Function'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Holiday", MQ_Holiday) # Holiday Name
if Debug is True: print 'MQTT published Holiday'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Time", ETime) # Time of MQTT Update
if Debug is True: print 'MQTT published ETime'
time.sleep(MQTT_Wait)
mqttc.publish("lights/SunState", SunStateMQTT) # Day or Night
if Debug is True: print 'MQTT published SunState'
# mqttc.publish("lights/SunAngle", SunAngleMQTT) # Angle of Sun to horizon (Need to fix SunAngleMQTT)
if Debug is True: print "MQTT updated all Dynamic"
if MQTT_enable is False:
if Debug is True:
print "MQTT is not enabled"
except:
# Prevent crashing if Broker is disconnected
if Debug is True:
print "MQTT Failed to publish All"
# Define function for specific days for lights to be on
def Holiday():
''' Holidays are in order of priority. If holidays are on the same day, the uppermost one has priority. '''
today = datetime.datetime.today()
now = datetime.datetime.now()
Month = now.month
Day = today.day
Weekday = today.weekday()
Holiday = 'None'
global MQ_Holiday
MQ_Holiday = Holiday
# Weekday: Monday = 0, Tuesday = 1, Wensday = 2, Thursday = 3, Friday = 4, Saturday = 5, Sunday = 6
if Month == 2 and Day == 20: # Sanatize for GitHub if Month == 2 and Day == 20:
''' Sanatize for GitHub ''' # Sanatize for GitHub
Holiday = 'Birthday'
elif Month == 5 and Day == 20: # Sanatize for GitHub elif Month == 5 and Day == 20:
''' Sanatize for GitHub ''' # Sanatize for GitHub
Holiday = 'Birthday'
elif Month == 7 and Day == 20: # Sanatize for GitHub elif Month == 7 and Day == 20:
''' Sanatize for GitHub ''' # Sanatize for GitHub
Holiday = 'Birthday'
elif Month == 11 and Day == 20: # Sanatize for GitHub elif Month == 11 and Day == 20:
''' Sanatize for GitHub ''' # Sanatize for GitHub
Holiday = 'Birthday'
elif Month == 2 and Day == 14:
''' Valentine's Day is 2/14 '''
Holiday = 'Valentine'
elif Month == 3 and Day == 17:
''' Saint Patricks Day 3/17 '''
Holiday = 'StPatrick'
elif Month >= 3 and Month <= 4 and EasterCheck() is True:
''' Easter is between 3/22 and 4/25 '''
''' 1st Sunday after the full moon that occurs on or next after the vernal equinox (March 21) '''
Holiday = 'Easter'
elif Month == 3 and Day == 25:
''' National Cerebral Palsy Awareness Day is 3/25'''
Holiday = 'CPDay'
elif Month == 4 and Day == 2:
''' World Autism Awareness Day is 4/2 '''
Holiday = 'Autism'
elif Month == 5 and Weekday == 6 and Day >= 8 and Day <= 15:
''' Mothers Day is 2nd Sunday in May '''
Holiday = 'ParentDay'
elif Month == 5 and Weekday == 3 and Day >= 15 and Day < 21:
''' Disability Awareness Day is the 3rd Thursday of May '''
Holiday = 'DisabilityDay'
elif Month == 6 and Weekday == 6 and Day >= 15 and Day < 21:
''' Fathers Day is 3rd Sunday in June '''
Holiday = 'ParentDay'
elif Month == 7 and Day == 4:
''' Independance Day July 4, 1776 '''
Holiday = 'Patriotic'
elif Month == 8 and Weekday == 6 and Day <= 7:
''' Family Day is the 1st Sunday in August '''
Holiday = 'Family'
elif Month == 9 and Day == 21:
''' National Hydrocephalus Awareness Day is 9/21'''
Holiday = 'HydroC'
elif Month == 10 and Weekday == 2 and Day <= 7:
''' World Cerebral Palsy Awareness Day is 1st Wensday in October '''
Holiday = 'CPDay'
elif Month == 10 and Day == 25:
''' World Hydrocephalus Awareness Day is 10/25'''
Holiday = 'HydroC'
elif Month == 11 and Day == 11:
''' Veterans Day 11/11 '''
Holiday = 'Patriotic'
elif Month == 11 and Day == 17:
''' World Prematurity Awareness Day is 11/17 '''
Holiday = 'Premmie'
elif ChristmasCheck() is True:
''' Christmas lights are from day after Thanksgiving until January 6 '''
Holiday = 'Christmas'
else:
Holiday = 'None'
if Debug is True: print(Holiday)
MQ_Holiday = Holiday
MQTT2("Holiday Check")
return Holiday
# *** Not Currently in Use Holidays ***
#elif now.month == 11 and today.weekday() == 3 and today.day >= 22 and today.day <= 28:
# ''' Thanksgiving, 4th Thursday of November '''
# Holiday = 'Thanksgiving'
#elif now.month == 5 and today.weekday() == 5 and today.day >= 15 and today.day <= 21:
# ''' Armed Forces Day is the 3rd Saturday in May '''
# Holiday = 'Patriotic'
#elif now.month == 5 and today.weekday() == 0 and today.day >= 25 and today.day <= 31:
# ''' Memorial Day is the last Monday in May '''
# Holiday = 'Patriotic'
#elif now.month == 6 and today.day == 14:
# ''' Flag Day June 14 '''
# Holiday = 'Patriotic'
#elif now.month == 10 and today.day == 13:
# ''' United States Navy Birtday is October 13, 1775 '''
# Holiday = 'Navy'
#elif now.month == 4 and today.day == 1:
# ''' United States Navy Chief Petty Officer Birthday is Apil 1, 1893 '''
# Holiday = 'Navy'
#elif now.month == 12 and today.day == 31:
# ''' UW Games '''
# Holiday = 'UW'
#########
# Define function MQTT Holiday list
def MQ_HoliDates():
''' MQTT information '''
# Monday = 0, Tuesday = 1, Wensday = 2, Thursday = 3, Friday = 4, Saturday = 5, Sunday = 6
try:
if MQTT_enable is True:
if Debug is True: print 'MQTT HoliDates Started'
mqttc = mqtt.Client("python_pub")
mqttc.connect(Broker_IP, Broker_Port)
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/01-Birthday_1", '2/20') # Sanatize for GitHub 2/20
if Debug is True: print 'MQTT published Birthday 1'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/01-Birthday_2", '5/20') # Sanatize for GitHub 5/20
if Debug is True: print 'MQTT published Birthday 2'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/01-Birthday_3", '7/20') # Sanatize for GitHub 7/20
if Debug is True: print 'MQTT published Birthday 3'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/01-Birthday_4", '11/20') # Sanatize for GitHub 11/20
if Debug is True: print 'MQTT published Birthday 4'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/02-Valentine", '2/14')
if Debug is True: print 'MQTT published Valentine'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/03-Saint_Patrick", '3/17')
if Debug is True: print 'MQTT published Saint Patrick'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/05-National_Cerebral_Palsy", '3/25')
if Debug is True: print 'MQTT published National Cerebral Palsy'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/06-World_Autism_Awareness", '4/2')
if Debug is True: print 'MQTT published World Autism Awareness'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/07-Mother", '2nd Sunday in May, 5/8 - 5/15')
if Debug is True: print 'MQTT published Mother'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/08-Disability_Awareness", '3rd Thursday of May, 5/15 - 5/21')
if Debug is True: print 'MQTT published Disability Awareness'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/09-Father", '3rd Sunday in June, 6/15 - 6/21')
if Debug is True: print 'MQTT published Father'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/10-Independance", '7/4')
if Debug is True: print 'MQTT published Independance Day'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/11-Family", '1st Sunday in August, 8/1 - 8/7')
if Debug is True: print 'MQTT published Family'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/12-National_Hydrocephalus_Awareness", '9/21')
if Debug is True: print 'MQTT published National Hydrocephalus Awareness'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/13-World_Cerebral_Palsy_Awareness", '1st Wensday in October, 10/1 - 10/7')
if Debug is True: print 'MQTT published World Cerebral Palsy Awareness Day'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/14-World_Hydrocephalus_Awareness", '10/25')
if Debug is True: print 'MQTT published World Hydrocephalus Awareness Day'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/15-Veterans", '11/11')
if Debug is True: print 'MQTT published Veterans Day'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/16-World_Prematurity_Awareness", '11/17')
if Debug is True: print 'MQTT published World Prematurity Awareness Day'
time.sleep(MQTT_Wait)
mqttc.publish("lights/Dates/17-Christmas", 'Day after Thanksgiving until All King Day')
if Debug is True: print 'MQTT published Christmas'
if Debug is True: print "MQTT updated all Holiday Dates"
if MQTT_enable is False:
if Debug is True:
print "MQTT is not enabled"
except:
# Prevent crashing if Broker is disconnected
if Debug is True:
print "MQTT Failed to publish All"
#####
# Holiday Date and birthstone Checks
def Bstone(): # Assign birthstone to months
''' Color based on birthstone '''
now = datetime.datetime.now()
colorT = CBlack
if now.month == 1:
''' January is Garnet '''
colorT = CRed
if now.month == 2:
''' Febuary is Amethyst '''
colorT = CPurple
if now.month == 3:
''' March is Aquamarine '''
colorT = CCyan
if now.month == 4:
''' April is Diamond '''
colorT = CWhite
if now.month == 5:
''' May is Emerald '''
colorT = CGreen
if now.month == 6:
''' June is Pearl / Alexandrite '''
colorT = CPurple
if now.month == 7:
''' July is Ruby '''
colorT = CRedLt
if now.month == 8:
''' August is Peridot / Sardonyx / Spinel '''
colorT = CGreenLt
if now.month == 9:
''' September is Sapphire '''
colorT = CBlue
if now.month == 10:
''' October is Tourmaline / Opal '''
colorT = CPink
if now.month == 11:
''' November is Topaz / Citrine '''
colorT = CYellow
if now.month == 12:
''' December is Tanzanite / Zircon / Turquoise '''
colorT = CBlueLt
if Debug is True:
print 'Birthday Stone is ',
print(colorT)
return colorT
def ChristmasCheck(): # Check to see if it is Christmas Light Season
''' Return Christmas True / False '''
''' Christmas lights are from day after Thanksgiving until January 6 '''
today = datetime.datetime.today()
now = datetime.datetime.now()
if now.month == 11:
year = datetime.datetime.now().year
A = 29
B = str(year) + ' 11 24'
C = datetime.datetime.strptime(B, '%Y %m %d')
D = datetime.datetime.weekday(C)
if D == 6: D = 1
else: D = D + 2
E = A - D + 1
if Debug is True:
Tday = 'First day after Thanksgiving this year is November ' + repr(E)
print (Tday)
if today.day >= E: return True
else: return False
elif now.month == 12:
''' Everyday in December '''
return True
elif now.month == 1 and today.day <= 6:
''' Fist six days in January '''
return True
else:
return False
def EasterCheck(): # Check to see if today is Easter
''' Returns Easter as True / False '''
today = datetime.datetime.today()
now = datetime.datetime.now()
year = now.year
month = now.month
day = today.day
# Calculate Easter Day this Year
a = year % 19
b = year // 100
c = year % 100
d = (19 * a + b - b // 4 - ((b - (b + 8) // 25 + 1) // 3) + 15) % 30
e = (32 + 2 * (b % 4) + 2 * (c // 4) - d - (c % 4)) % 7
f = d + e - 7 * ((a + 11 * d + 22 * e) // 451) + 114
EasterMonth = f // 31
EasterDay = f % 31 + 1
global ED
if Debug is True:
if month > EasterMonth:
ED = 'Easter was ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
elif month == EasterMonth and day > EasterDay:
ED = 'Easter was ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
else:
ED = 'Easter is ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
print (ED),
if MQTT_enable is True:
if month > EasterMonth:
ED = 'Easter was ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
elif month == EasterMonth and day > EasterDay:
ED = 'Easter was ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
else:
ED = 'Easter is ' + repr(EasterMonth) + '/' + repr(EasterDay) + '/' + repr(year)
# Compare Easter Day to today
if EasterMonth == month and EasterDay == day:
if Debug is True: print '. Today is Easter'
return True
else:
if Debug is True: print '. Today is NOT Easter'
return False
#########
# Define functions for Holidays
def Autism():
''' Autism Awareness Day Selection '''
if Debug is True: print 'Autism Awareness Day'
colorWipe(CBlue)
time.sleep(300)
def BDay():
''' Birdays, Color based on birthstone function above '''
if Debug is True: print 'Birthday'
colorT = Bstone()
colorWipe(colorT)
time.sleep(300)
def Christmas():
''' Christmas Selection '''
ARepeat = 200
if Debug is True:
print 'Christmas, ARepeat = ',
print ARepeat
#FuseDanceColor()
FuseDanceColorMulti()
#FuseDance(CRed)
#FuseDance(CBlue)
#FuseDance(CGreen)
CRepeat = int(round(ARepeat / 75))
for i in range (0, CRepeat, 1):
rainbowCycle()
FuseMulti(CRed)
FuseMultiRev(CGreen)
CRepeat = int(round(ARepeat / 4))
#TriForce(CRed,CBlue,CGreen,25,.05,CRepeat)
DualForce(CRed, CGreen, 25, .05, CRepeat)
DualWipe2(CRed,CGreen,50)
DualWipe2(CGreen,CRed,50)
colorWipe(CRed)
colorWipeRev(CGreen)
#colorWipe(CBlue)
#colorWipe(CRed)
#colorWipeRev(CGreen)
#colorWipeRev(CBlue)
CRepeat = int(round(ARepeat / 3))
#TriWipe(CRed,CGreen,CBlue,CRepeat)
FuseMulti(CGreen)
FuseMultiRev(CRed)
CRepeat = int(round(ARepeat / 3))
#TriWipe2(CRed,CGreen,CBlue,CRepeat)
theaterChaseRainbow()
CRepeat = int(round(ARepeat / 120))
#TriForce(CRed,CBlue,CGreen,10,1,CRepeat)
DualForce(CRed, CGreen, 10, 1, CRepeat)
FuseMulti(CGreen)
FuseMultiRev(CRed)
#CRepeat = int(round(ARepeat / 90))
#TriForce(CRed,CBlue,CGreen,1,.05,CRepeat)
CRepeat = int(round(ARepeat / 30))
#TriForce(CRed,CBlue,CGreen,3,.05,CRepeat)
DualForce(CRed, CGreen, 3, .05, CRepeat)
def CPDay():
''' National CP Day is 3/25 '''
''' World CP Day is 1st Wensday of October '''
if Debug is True: print 'Cerebral Palsy Awareness Day'
colorWipe(CGreen)
time.sleep(300)
def DisabilityDay():
''' Disability Awareness Day is the 3rd Thursday of May '''
if Debug is True: print 'Disability Awareness Day'
colorWipe(CGray)
time.sleep(300)
def Easter():
''' Easter Selection '''
if Debug is True: print 'Easter'
Pause = 10
color1 = CGreenLt
color2 = CBlueLt
color3 = CYellow
color4 = CCyan
color5 = CPink
for i in range (1, 5, 1):
DualWipe2(color1, color2, 20)
time.sleep(Pause)
colorT = color1
color1 = color2
color2 = color3
color3 = color4
color4 = colorT
def HydroC():
''' Hydrocephalus Awareness Day '''
if Debug is True: print 'Hydrocephalus Awareness Day'
DualWipe2(CBlueLt,CBlue,20)
def Navy():
''' United States Navy Colors '''
''' Blue and Gold '''
if Debug is True: print 'Navy'
colorWipe(CGold)
colorWipeRev(CBlue)
Fuse(CGold)
FuseRev(CBlue)
colorWipeRev(CGold)
colorWipe(CBlue)
Fuse(CBlue)
FuseRev(CGold)
for i in range(1,10,1):
DualWipe(CGold,CBlue)
DualWipe(CPurple,CGold)
def Parent():
''' Mothers Day / Fathers Day '''
''' Birthstone Colors of kids '''
''' Number of Lights ON per age '''
if Debug is True: print 'Parent Day'
now = datetime.datetime.now()
year = now.year
''' Sanatize for GitHub ''' # Sanatize for GitHub
AgeKid1 = year - 2005 # Sanatize for GitHub AgeKid1 = year - 2005
''' Sanatize for GitHub ''' # Sanatize for GitHub
AgeKid2 = year - 2010 - 1 # Sanatize for GitHub AgeKid2 = year - 2010 - 1
PStep = AgeKid1 + AgeKid2 # Sanatize for GitHub PStep = AgeKid1 + AgeKid2
for i in range(0, LED_Last, PStep):
for j in range(0, AgeKid1, 1):
strip.setPixelColor(i+j, CPurple)
for j in range(0, AgeKid2, 1):
strip.setPixelColor(i+AgeKid1+j, CRedLt)
strip.show()
time.sleep(1)
time.sleep(300)
def Familyday():
''' Family Day '''
if Debug is True: print 'Family Day'
now = datetime.datetime.now()
year = now.year
''' Sanatize for GitHub ''' # Sanatize for GitHub
AgeKid1 = year - 2005 # Sanatize for GitHub 2005
AgeKid2 = year - 2010 # Sanatize for GitHub 2010
AgeMom = year - 1975 # Sanatize for GitHub 1975
AgeDad = year - 1970 - 1 # Sanatize for GitHub 1970
PStep = AgeKid1 + AgeKid2 + AgeMom + AgeDad
for i in range(0, LED_Last, PStep):
for j in range(0, AgeKid1, 1):
strip.setPixelColor(i+j, CPurple)
for j in range(0, AgeKid2, 1):
strip.setPixelColor(i+AgeKid1+j, CRedLt)
for j in range(0, AgeMom, 1):
strip.setPixelColor(i+AgeKid1+AgeKid2+j, CGreen)
for j in range(0, AgeDad, 1):
strip.setPixelColor(i+AgeKid1+AgeKid2+AgeMom+j, CYellow)
strip.show()
time.sleep(1)
time.sleep(300)
def Patriotic():
''' United States Patriotic holidays '''
''' 4th of July, Veterans Day, Memorial Day, Flag Day, Armed Forces Day '''
if Debug is True: print 'Patriotic'
TriSwipe(CRed,CWhite,CBlue,10,1,10)
blackout()
TriWipe(CRed,CWhite,CBlue,40)
blackout()
TriWipe2(CRed,CWhite,CBlue,40)
blackout()
def Premmie():
''' Prematurity Awareness Day '''
''' Purple Ribbon or Pink and Blue Ribbon '''
if Debug is True: print 'Prematurity Awareness Day'
colorWipe(CPurple)
time.sleep(60)
DualWipe2(CPink,CBlueLt,20)
time.sleep(60)
def StPDay():
''' Saint Patricks Day Selection '''
if Debug is True: print 'Saint Patricks Day'
colorWipe(CGreen)
time.sleep(300)
def Thanksgiving():
''' Thanksgiving Selection '''
if Debug is True: print 'Thanksgiving'
Pause = 60
colorWipe(COrange)
time.sleep(Pause)
colorWipeRev(CYellow)
time.sleep(Pause)
def UW():
''' Gold and Purple for University of Washington '''
colorWipe(CGold)
colorWipeRev(CPurple)
Fuse(CGold)
FuseRev(CPurple)
colorWipeRev(CGold)
colorWipe(CPurple)
Fuse(CPurple)
FuseRev(CGold)
for i in range(1,10,1):
DualWipe(CGold,CPurple)
DualWipe(CPurple,CGold)
def Vday():
''' Valentine's Day Selection'''
if Debug is True: print 'Valentine Day'
colorWipe(CPink)
time.sleep(300)
#########
# Define functions which animate LEDs in various ways.
def blackout():
''' Turn off LEDs one at a time '''
MQTT2("blackout")
if Debug is True:
TimerStart = time.time()
print 'blackout start',
for i in range(LED_Last):
strip.setPixelColor(i,0)
strip.show()
time.sleep(.001)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def colorWipe(color, wait_ms=50):
''' Wipe color across display a pixel at a time '''
if SunState() is 'Day': return
MQTT2("colorWipe")
if Debug is True:
TimerStart = time.time()
print 'colorWipe',
print(ColorCk(color)),
for i in range(LED_Last):
strip.setPixelColor(i, color)
strip.show()
time.sleep(wait_ms/1000.0)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def colorWipeRev(color, wait_ms=50):
''' Wipe color across display a pixel at a time '''
if SunState() is 'Day': return
MQTT2("colorWipeRev")
if Debug is True:
TimerStart = time.time()
print 'colorWipeRev',
print(ColorCk(color)),
for i in range(LED_Last,-1,-1):
strip.setPixelColor(i, color)
strip.show()
time.sleep(wait_ms/1000.0)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def DualForce(color1, color2, Length, Wait, Repeat):
''' Wipe three colors alternating at a specified length '''
''' Length is how many LEDs of a color in a row '''
''' Wait is the delay time to update the next loop '''
''' Repeat is how many times to loop '''
if SunState() is 'Day': return
MQTT2("DualForce")
if Debug is True:
TimerStart = time.time()
print 'TriForce',
print(ColorCk(color1)),
print(ColorCk(color2)),
print 'Length =',
print(Length),
print 'Wait =',
print(Wait),
print 'Repeat =',
print(Repeat),
for i in range (0, Repeat, 1):
for j in range (0, LED_Last, Length):
for h in range(0, Length, 1):
strip.setPixelColor(j+h, color1)
colorT = color1
color1 = color2
color2 = colorT
strip.show()
time.sleep(Wait)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def DualWipe(color1, color2, wait_ms=5):
''' Wipe color across multiple LED strips a pixel at a time '''
if SunState() is 'Day': return
MQTT2("DualWipe")
if Debug is True:
TimerStart = time.time()
print 'DualWipe',
print(ColorCk(color1)),
print(ColorCk(color2)),
for i in range(LED_Last):
if i % 2:
# even number
strip.setPixelColor(i, color1)
strip.show()
time.sleep(wait_ms/1000.0)
else:
# odd number
strip.setPixelColor(i, color2)
strip.show()
time.sleep(wait_ms/1000.0)
time.sleep(1)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def DualWipe2(color1, color2, Length):
''' Wipe two colors for a custom length '''
if SunState() is 'Day': return
MQTT2("DualWipe2")
if Debug is True:
TimerStart = time.time()
print 'DualWipe2',
print(ColorCk(color1)),
print(ColorCk(color2)),
print(Length),
PixEnd = LED_Last - Length
for h in range(0,PixEnd,Length):
for i in range (h, h+Length, 1):
strip.setPixelColor(i,color1)
color3 = color2
color2 = color1
color1 = color3
strip.show()
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def Fire(Repeat):
if SunState() is 'Day': return
MQTT2("Fire")
if Debug is True:
print 'Fire',
TimerStart = time.time()
color1=CRed
color2=COrange
color3=CBlack
Length=1
Wait=.001
for i in range (0, Repeat, 1):
for j in range (0, LED_Last, Length):
for h in range(0, Length, 1):
strip.setPixelColor(j+h, color1)
colorT = color1
color1 = color2
color2 = color3
color3 = colorT
strip.show()
time.sleep(.07)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def Fuse(color1):
if SunState() is 'Day': return
MQTT2("Fuse")
if Debug is True:
TimerStart = time.time()
print 'Fuse',
print(ColorCk(color1)),
for i in range (LED_Last, 0, -1):
strip.setPixelColor(i, color1)
strip.setPixelColor(i+1, CBlack)
strip.show()
time.sleep(.001)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def FuseRev(color1):
if SunState() is 'Day': return
MQTT2("FuseRev")
if Debug is True:
TimerStart = time.time()
print 'FuseRev',
print(ColorCk(color1)),
for i in range (0, LED_Last, 1):
strip.setPixelColor(i, color1)
strip.setPixelColor(i-1, CBlack)
strip.show()
time.sleep(.001)
if Debug is True:
TimerStop = time.time()
Timer = TimerStop - TimerStart
print (PYellow),
print (Timer),
print (POff)
def FuseMulti(color1):
if SunState() is 'Day': return
MQTT2("FuseMulti")
if Debug is True:
TimerStart = time.time()
print 'FuseMulti',
print(ColorCk(color1)),
for i in range (LED_Last, 0, -1):
for j in range (0, LED_Last, 30):
a = i-j
b = i+j
c = i-j+1
d = i-j-1