Snippets

Created by Peter Scargill
  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
README.md

# Timer for Node-Red
BigTimer offers a range of timing facilities for Node-Red and can be used singly or in groups. Full support for dusk/dawn and variations also week/month control is  supported and the node offers outputs to MQTT, speech and databases.

### Usage

Suitable for general use, BigTimer has 3 outputs, one of which triggers when there is a change and presents one of two messages (for, for example MQTT or other control mechanism), the second is a simple 1 or 0 every minute in the payload but also has additional outputs reflecting the status message in msg.state and message time. There is also a msg.name available  - and the third outputs a message which could be used for speech or debugging.

### Inputs

It also has an input. This can be used to override the schedule - valid commands in the payload are "on", "off","default" and more detailed in the blog - "default" leaves the timer to it's own devices and can also be used as an instant test.

### Override

The manual override will time-out after 8 hours and go back to auto (just in case you forget to turn something off). Manual override will also be over-ridden by any scheduled change. There is a pause schedule button for convenient longer-term pausing of the schedule.

### General

Note if upgrading - check your settings. In addition to dusk/dawn, new prefixes have been added which may need checking just after an upgrade.




package.json
{
  "name": "node-red-contrib-bigtimer",
  "version": "1.2.90",
  "description": "A great Node Red general timer with dusk, dawn, months, days, manual override, schedule pause, random or fixed offsets and much more.",
  "homepage": "http://tech.scargill.net/big-timer/",
  "license": "MIT",
  "readme": "Nothing special",
  
  "repository": {
    "type": "git",
    "url": "none"
  },
  
  "author": {
    "name": "Peter Scargill",
	"email": "pete@scargill.org",
	"url": "http://tech.scargill.net"
  },
  "dependencies": {
    "suncalc": "1.*"
  },
  "keywords": [
    "node-red",
    "bigtimer",
	"scargill",
	"timer",
	"timers",
	"scheduling",
	"schedule"
	
  ],
  "node-red": {
    "nodes": {
      "bigtimer": "bigtimer.js"
    }
  }
}






bigtimer.js

/**
 * This node is copyright (c) Peter Scargill - but as I've had so many ideas from others -
 * consider it free to use for whatever purpose you like. If you redesign it
 * please remember to drop my name and link in there somewhere.
 * http://tech.scargill.net 
 */

module.exports = function(RED) {
	"use strict";
	var SunCalc = require('suncalc');
	
	function pad(n, width, z) {
        z = z || '0';
        n = n + '';
        return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
    }
	
	function randomInt (low, high) {
    var m=Math.floor(Math.random() * (Math.abs(high) - low) + low);
	if (high<=0) return -m; else return m;
}
	
	function bigTimerNode(n) {
		RED.nodes.createNode(this, n);
		var node = this;
	
		var ismanual=-1;
		var timeout=0;
		var startDone=0;
		
		var onlyManual=0;
		
		node.name=n.name;
		node.lat = n.lat;
		node.lon = n.lon;
		node.start = n.start;
		node.end = n.end;
		node.startT = n.starttime;
		node.endT = n.endtime;
		node.startOff = n.startoff;
		node.endOff = n.endoff;
		node.outtopic = n.outtopic;
		node.outPayload1 = n.outpayload1;
		node.outPayload2 = n.outpayload2;
		node.outText1 = n.outtext1;
		node.outText2 = n.outtext2;

		node.sun = n.sun;
		node.mon = n.mon;
		node.tue = n.tue;
		node.wed = n.wed;
		node.thu = n.thu;
		node.fri = n.fri;
		node.sat = n.sat;
		node.jan = n.jan;
		node.feb = n.feb;
		node.mar = n.mar;
		node.apr = n.apr;
		node.may = n.may;
		node.jun = n.jun;
		node.jul = n.jul;
		node.aug = n.aug;
		node.sep = n.sep;
		node.oct = n.oct;
		node.nov = n.nov;
		node.dec = n.dec;
		node.suspend=n.suspend;
		node.random=n.random;
		node.repeat=n.repeat;
		node.atStart=n.atstart;
		
	    var goodDay=0;
		
		var temporaryManual=0;
		var permanentManual=0;
		
		var autoState=0;
		var lastState=-1;
		
		var playit = 0;
		var newEndTime = 0;
		
		var actualStartOffset=0;
		var actualEndOffset=0;

		var actualStartTime=0;
		var actualEndTime=0;
		
		var manualState=0;
		var autoState=0;
		var lastState=-1;
		
		var change=0;
								
		node
				.on(
						"input",
						function(inmsg) {
							var now = new Date(); // UTC time - not local time
							var nowOff = -now.getTimezoneOffset() * 60000;	// local offset		
							var times = SunCalc.getTimes(now, node.lat,node.lon);	// get this from UTC, not local time

							var dawn=(times.dawn.getHours()*60) + times.dawn.getMinutes();
							var dusk=(times.dusk.getHours()*60) + times.dusk.getMinutes();
							
							var solarNoon=(times.solarNoon.getHours()*60) + times.solarNoon.getMinutes();

							var sunrise=(times.sunrise.getHours()*60) + times.sunrise.getMinutes();
							var sunset=(times.sunset.getHours()*60) + times.sunset.getMinutes();

							var night=(times.night.getHours()*60) + times.night.getMinutes();
							var nightEnd=(times.nightEnd.getHours()*60) + times.nightEnd.getMinutes();
							
						    now=new Date(now+nowOff); // from now on we're working on local time		
							var today=(now.getHours()*60) + now.getMinutes();	
									
									
							/* var nowMillis = Date.UTC(now.getUTCFullYear(), now
									.getUTCMonth(), now.getUTCDate(), now
									.getUTCHours(), now.getUTCMinutes(), 1);
							var midnightMillis = Date.UTC(now.getUTCFullYear(),
									now.getUTCMonth(), now.getUTCDate(), 0, 1);
							var startMillis = Date.UTC(times[node.start]
									.getUTCFullYear(), times[node.start]
									.getUTCMonth(), times[node.start]
									.getUTCDate(), times[node.start]
									.getUTCHours(), times[node.start]
									.getUTCMinutes());
							var endMillis = Date.UTC(times[node.end]
									.getUTCFullYear(), times[node.end]
									.getUTCMonth(), times[node.end]
									.getUTCDate(), times[node.end]
									.getUTCHours(), times[node.end]
									.getUTCMinutes());

							nowMillis += nowOff;
							startMillis += nowOff;
							endMillis += nowOff;
							
							var dawn = (((startMillis - midnightMillis) / 60000)) % 1440;
							var dusk = (((endMillis - midnightMillis) / 60000)) % 1440;
							var today = (Math
									.round((nowMillis - midnightMillis) / 60000)) % 1440;
							
							*/
							
							var startTime = parseInt(node.startT, 10);
							var endTime = parseInt(node.endT, 10);
							
							var outmsg = {
								payload : "",
								topic : ""
							};
							var outmsg2 = {
								payload : "",
								reference : node.outtopic+":"+node.outPayload1+":"+node.outPayload2 + ":" + today,
								topic : "status",
								state : "",
								time : "",
								name : ""
							};
							var outtext = {
								payload : "",
								topic : ""
							};

							if (actualStartOffset==0)
								{ if (node.random) actualStartOffset=randomInt(0,node.startOff); else actualStartOffset=node.startOff; }

							if (actualEndOffset==0)
								{ if (node.random) actualEndOffset=randomInt(0,node.endOff); else actualEndOffset=node.endOff; }					

							if (startTime == 5000) startTime = dawn;
							if (startTime == 5001) startTime = dusk;
							if (startTime == 5002) startTime = solarNoon;
							if (startTime == 5003) startTime = sunrise;
							if (startTime == 5004) startTime = sunset;
							if (startTime == 5005) startTime = night;
							if (startTime == 5006) startTime = nightEnd;

							if (endTime == 5000) endTime = dawn;
							if (endTime == 5001) endTime = dusk;
							if (endTime == 5002) endTime = solarNoon;
							if (endTime == 5003) endTime = sunrise;
							if (endTime == 5004) endTime = sunset;
							if (endTime == 5005) endTime = night;
							if (endTime == 5006) endTime = nightEnd;
							
							actualStartTime=(startTime+Number(actualStartOffset))%1440;  
							actualEndTime= (endTime+Number(actualEndOffset))%1440; 
			
							autoState = 0; goodDay=0;
							switch (now.getDay()) {
							case 0:
								if (node.sun)
									autoState=1;
								break;
							case 1:
								if (node.mon)
									autoState=1; ;
								break;
							case 2:
								if (node.tue)
									autoState=1;
								break;
							case 3:
								if (node.wed)
									autoState=1; 
								break;
							case 4:
								if (node.thu)
									autoState=1;
								break;
							case 5:
								if (node.fri)
									autoState=1; 
								break;
							case 6:
								if (node.sat)
									autoState=1;
								break;
							}

							if (autoState)
							{ 
							autoState=0;
						    switch (now.getMonth()) {
								case 0:
									if (node.jan)
										autoState=1;
									break;
								case 1:
									if (node.feb)
										autoState=1;
									break;
								case 2:
									if (node.mar)
										autoState=1;
									break;
								case 3:
									if (node.apr)
										autoState=1;
									break;
								case 4:
									if (node.may)
										autoState=1;
									break;
								case 5:
									if (node.jun)
										autoState=1;
									break;
								case 6:
									if (node.jul)
										autoState=1;
									break;
								case 7:
									if (node.aug)
										autoState=1;
									break;
								case 8:
									if (node.sep)
										autoState=1;
									break;
								case 9:
									if (node.oct)
										autoState=1;
									break;
								case 10:
									if (node.nov)
										autoState=1;
									break;
								case 11:
									if (node.dec)
										autoState=1;
									break;
								}
								if (autoState==1) goodDay=1; 
							}
							// if autoState==1 at this point - we are in the right day and right month

							if (autoState==1) // have to handle midnight wrap
							{
								autoState=0;
								if (actualStartTime <= actualEndTime) {
									if ((today >= actualStartTime)
											&& (today <= actualEndTime))
										autoState=1;
								} else {
									if ((today >= actualStartTime)
											|| (today <= actualEndTime))
										autoState=1;
								}
							}

							// autoState is 1 or 0 or would be on auto.... has anything changed...
							change=0;
							
							if ((node.atStart==0)&&(startDone==0)) lastState=autoState; // that is - no output at the start if node.atStart is not ticked
							
							if (autoState!=lastState) // there's a change of auto
							{
							 lastState=autoState; change=1;
							 if (autoState==1) actualEndOffset=0; else actualStartOffset=0; // if turning on - reset random offset for next OFF time else reset offset for next ON time
							 temporaryManual=0; // kill temporary manual as we've changed to next auto state
							}
							
							// manual override
							switch (inmsg.payload)
							{
								case "on"  :
								case "ON"  :
								case "1"   : if ( permanentManual==0) { temporaryManual=1; timeout=480; } else timeout=1440;
											 change=1; manualState=1; timeout=480; break;
								case "off" :
								case "OFF" :
								case "0"   : if ( permanentManual==0) { temporaryManual=1; timeout=480; } else timeout=1440;
								             change=1; manualState=0; timeout=480; break;
								case "default" :
								case "DEFAULT" :
								case "auto" :
								case "AUTO" : temporaryManual=0; permanentManual=0; change=1; break;
								case "manual" :
								case "MANUAL" : if ((temporaryManual==0) && permanentManual==0)  manualState=autoState;
												temporaryManual=0; permanentManual=1; change=1; break;
								default :  break;
							}

							if (timeout) if ((--timeout)==0) manualState=0; // kill the output after 8 hours of any kind of manual on
							if ((temporaryManual==1) || (permanentManual==1)) autoState=manualState; // if in permanent manual - OR temporary - use manualState instead of auto
							

							var duration = 0;
							var manov=""; 
							if (permanentManual==1) manov="Man. override. "; else if (temporaryManual==1) manov="Temp. override. ";
							if (node.suspend) manov+="No schedule.";
							
							if ((permanentManual==1) || (temporaryManual==1) || (node.suspend))
							{
								if (autoState==1) 
									node.status({
										fill : "green",
										shape : "dot",
										text : "ON "+manov
										});
									else
										node.status({
										fill : "red",
										shape : "dot",
										text : "OFF "+manov
										});
							}
							else // so not manual but auto....
								{
									outmsg2.name=node.name;
									if (goodDay==1) // auto and today's the day
									{
											if (autoState==1) 
											{  // i.e. if turning on automatically
												if (today <= actualEndTime)
													duration = actualEndTime - today;
												else
													duration = actualEndTime + (1440 - today);
												outmsg2.state="on"; outmsg2.time=pad(parseInt(duration/60),2) + "hrs " + pad(duration%60,2) + "mins"; 
												node.status({
													fill : "green",
													shape : "dot",
													text : "On for " + pad(parseInt(duration/60),2) + "hrs " + pad(duration%60,2) + "mins"
													});										
											} 
										else {
											if (today <= actualStartTime)
												duration = actualStartTime - today;
											else
												duration = actualStartTime + (1440 - today);
											outmsg2.state="off"; outmsg2.time=pad(parseInt(duration/60),2) + "hrs " + pad(duration%60,2) + "mins";
											node.status({
												fill : "blue",
												shape : "dot",
												text : "Off for "  + pad(parseInt(duration/60),2) + "hrs " + pad(duration%60,2) + "mins"
												});		
										}
									}
								else
									{ 
									outmsg2.state="none"; outmsg2.time="";
									node.status({   // auto and nothing today thanks
												fill : "black",
												shape : "dot",
												text : "No action today"
											});	
									}
								}

							outmsg.topic = node.outtopic;
						    outmsg2.payload = (autoState==1)? "1" : "0";			
	                        outtext.payload=node.outText1;
							
							if (temporaryManual || permanentManual) outmsg.state=(manualState) ? "on" : "off" ; else outmsg.state="auto";
							outmsg.value=autoState;
							
							if (autoState==1)
								{
									outmsg.payload = node.outPayload1;
									outtext.payload=node.outText1;								
								}
							else
								{
									outmsg.payload = node.outPayload2;
									outtext.payload=node.outText2;
								}	
						
							// take into account CHANGE variable - if true a manual or auto change is due
							
							if ((change) || ((node.atStart)&&(startDone==0)))
							{
								node.send([outmsg, outmsg2,outtext]);			
							}
							else
							{
								if (node.repeat) node.send([outmsg, outmsg2,null]);	else node.send([null, outmsg2,null]);
							}	
							startDone=1;
						});  // end of the internal function

		var tock = setTimeout(function() {
			node.emit("input", {});
		}, 2000); // wait 2 secs before starting to let things settle down -
					// e.g. UI connect

		var tick = setInterval(function() {
			node.emit("input", {});
		}, 60000); // trigger every 60 secs

		node.on("close", function() {
			if (tock) {
				clearTimeout(tock);
			}
			if (tick) {
				clearInterval(tick);
			}
		});

	}
	RED.nodes.registerType("bigtimer", bigTimerNode);
}





bigtimer.html

<!--
	This node is copyright (c) Peter Scargill - but as I've had so
	many ideas from others - consider it free to use for whatever
	purpose you like. If you redesign it please remember to drop
	my name and link in there somewhere. http://tech.scargill.net
	This software puts out one of two messages on change of state 
    which could be sent to the MQTT node, tests every minute and can
	be over-ridden manually.
-->

<script type="text/x-red" data-template-name="bigtimer">

     <div class="form-row">
		<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
		<input type="text" id="node-input-name" placeholder="Name">
     </div>

<script type="text/x-red" data-help-name="bigtimer">
    <p>Bigtimer sends messages for start and end conditions at any time, day, month or period.</p>
	<p>The first output sends out a message on time (and if repeat is ticked - every minute)</p>
	<p>The second output simply sends the state - 1 or 0 every minute as well as echoing the status in msg.state and msg.time </p>
	<p>The third output sends an optional message for both states - suitable for speech output or a log.</p>
	<p>The input can be used a trigger (internal 1 minute timer or manual override via the input. The message can be 1/on, 0/off or auto/default (the input can be used to leave the scheduler to it's own devices and/or to trigger it instantly).</p>
	<p>Manual On/Off overrides time-out after 8 hours OR at change of schedule.</p>
    <p>Start/End offsets can be fixed or random (tick the box) within the offset period specified. Schedule can be paused by the interface tick box or by the "manual" command ("auto" command to return to normal)</p>
</script>
	 
	 <div class="form-row">
        <label for="node-input-starttime"><i class="fa fa-clock-o"></i> On Time</label>
        <select id="node-input-starttime" style="width:73% !important">
            <option value=  "0">00:00</option>
            <option value= "15">00:15</option>
            <option value= "30">00:30</option>
            <option value= "45">00:45</option>
            <option value= "60">01:00</option>
            <option value= "75">01:15</option>
            <option value= "90">01:30</option>
            <option value="105">01:45</option>
            <option value="120">02:00</option>
            <option value="135">02:15</option>
            <option value="150">02:30</option>
            <option value="165">02:45</option>
            <option value="180">03:00</option>
            <option value="195">03:15</option>
            <option value="210">03:30</option>
            <option value="225">03:45</option>
            <option value="240">04:00</option>
            <option value="255">04:15</option>
            <option value="270">04:30</option>
            <option value="285">04:45</option>
            <option value="300">05:00</option>
            <option value="315">05:15</option>
            <option value="330">05:30</option>
            <option value="345">05:45</option>
            <option value="360">06:00</option>
            <option value="375">06:15</option>
            <option value="390">06:30</option>
            <option value="405">06:45</option>
            <option value="420">07:00</option>
            <option value="435">07:15</option>
            <option value="450">07:30</option>
            <option value="465">07:45</option>
            <option value="480">08:00</option>
            <option value="495">08:15</option>
            <option value="510">08:30</option>
            <option value="525">08:45</option>
            <option value="540">09:00</option>
            <option value="555">09:15</option>
            <option value="570">09:30</option>
            <option value="585">09:45</option>
            <option value="600">10:00</option>
            <option value="615">10:15</option>
            <option value="630">10:30</option>
            <option value="645">10:45</option>
            <option value="660">11:00</option>
            <option value="675">11:15</option>
            <option value="690">11:30</option>
            <option value="705">11:45</option>
            <option value="720">12:00</option>
            <option value="735">12:15</option>
            <option value="750">12:30</option>
            <option value="765">12:45</option>
            <option value="780">13:00</option>
            <option value="795">13:15</option>
            <option value="810">13:30</option>
            <option value="825">13:45</option>
            <option value="840">14:00</option>
            <option value="855">14:15</option>
            <option value="870">14:30</option>
            <option value="885">14:45</option>
            <option value="900">15:00</option>
            <option value="915">15:15</option>
            <option value="930">15:30</option>
            <option value="945">15:45</option>
            <option value="960">16:00</option>
            <option value="975">16:15</option>
            <option value="990">16:30</option>
            <option value="1005">16:45</option>
            <option value="1020">17:00</option>
            <option value="1035">17:15</option>
            <option value="1050">17:30</option>
            <option value="1065">17:45</option>
            <option value="1080">18:00</option>
            <option value="1095">18:15</option>
            <option value="1110">18:30</option>
            <option value="1125">18:45</option>
            <option value="1140">19:00</option>
            <option value="1155">19:15</option>
            <option value="1170">19:30</option>
            <option value="1185">19:45</option>
            <option value="1200">20:00</option>
            <option value="1215">20:15</option>
            <option value="1230">20:30</option>
            <option value="1245">20:45</option>
            <option value="1260">21:00</option>
            <option value="1275">21:15</option>
            <option value="1290">21:30</option>
            <option value="1305">21:45</option>
            <option value="1320">22:00</option>
            <option value="1335">22:15</option>
            <option value="1350">22:30</option>
            <option value="1365">22:45</option> 
			<option value="1380">23:00</option>
            <option value="1395">23:15</option>
            <option value="1410">23:30</option>
            <option value="1425">23:45</option>
            <option value="5000">Dawn</option>
            <option value="5001">Dusk</option>
           <option value="5003">Sunrise</option>
           <option value="5004">Sunset</option>
           <option value="5005">Night</option>
           <option value="5006">Night end</option>
			

			
			
        </select>
    </div>
	
	 <div class="form-row">
        <label for="node-input-endtime"><i class="fa fa-clock-o"></i> Off Time</label>
        <select id="node-input-endtime" style="width:73% !important">
            <option value=  "0">00:00</option>
            <option value= "15">00:15</option>
            <option value= "30">00:30</option>
            <option value= "45">00:45</option>
            <option value= "60">01:00</option>
            <option value= "75">01:15</option>
            <option value= "90">01:30</option>
            <option value="105">01:45</option>
            <option value="120">02:00</option>
            <option value="135">02:15</option>
            <option value="150">02:30</option>
            <option value="165">02:45</option>
            <option value="180">03:00</option>
            <option value="195">03:15</option>
            <option value="210">03:30</option>
            <option value="225">03:45</option>
            <option value="240">04:00</option>
            <option value="255">04:15</option>
            <option value="270">04:30</option>
            <option value="285">04:45</option>
            <option value="300">05:00</option>
            <option value="315">05:15</option>
            <option value="330">05:30</option>
            <option value="345">05:45</option>
            <option value="360">06:00</option>
            <option value="375">06:15</option>
            <option value="390">06:30</option>
            <option value="405">06:45</option>
            <option value="420">07:00</option>
            <option value="435">07:15</option>
            <option value="450">07:30</option>
            <option value="465">07:45</option>
            <option value="480">08:00</option>
            <option value="495">08:15</option>
            <option value="510">08:30</option>
            <option value="525">08:45</option>
            <option value="540">09:00</option>
            <option value="555">09:15</option>
            <option value="570">09:30</option>
            <option value="585">09:45</option>
            <option value="600">10:00</option>
            <option value="615">10:15</option>
            <option value="630">10:30</option>
            <option value="645">10:45</option>
            <option value="660">11:00</option>
            <option value="675">11:15</option>
            <option value="690">11:30</option>
            <option value="705">11:45</option>
            <option value="720">12:00</option>
            <option value="735">12:15</option>
            <option value="750">12:30</option>
            <option value="765">12:45</option>
            <option value="780">13:00</option>
            <option value="795">13:15</option>
            <option value="810">13:30</option>
            <option value="825">13:45</option>
            <option value="840">14:00</option>
            <option value="855">14:15</option>
            <option value="870">14:30</option>
            <option value="885">14:45</option>
            <option value="900">15:00</option>
            <option value="915">15:15</option>
            <option value="930">15:30</option>
            <option value="945">15:45</option>
            <option value="960">16:00</option>
            <option value="975">16:15</option>
            <option value="990">16:30</option>
            <option value="1005">16:45</option>
            <option value="1020">17:00</option>
            <option value="1035">17:15</option>
            <option value="1050">17:30</option>
            <option value="1065">17:45</option>
            <option value="1080">18:00</option>
            <option value="1095">18:15</option>
            <option value="1110">18:30</option>
            <option value="1125">18:45</option>
            <option value="1140">19:00</option>
            <option value="1155">19:15</option>
            <option value="1170">19:30</option>
            <option value="1185">19:45</option>
            <option value="1200">20:00</option>
            <option value="1215">20:15</option>
            <option value="1230">20:30</option>
            <option value="1245">20:45</option>
            <option value="1260">21:00</option>
            <option value="1275">21:15</option>
            <option value="1290">21:30</option>
            <option value="1305">21:45</option>
            <option value="1320">22:00</option>
            <option value="1335">22:15</option>
            <option value="1350">22:30</option>
            <option value="1365">22:45</option> 
			<option value="1380">23:00</option>
            <option value="1395">23:15</option>
            <option value="1410">23:30</option>
            <option value="1425">23:45</option>
            <option value="5000">Dawn</option>
            <option value="5001">Dusk</option>
            <option value="5003">Sunrise</option>
            <option value="5004">Sunset</option>
            <option value="5005">Night</option>
            <option value="5006">Night end</option>
            <option value="10001">1 minute</option>
            <option value="10002">2 minutes</option>
            <option value="10005">5 minutes</option>
            <option value="10010">10 minutes</option>
            <option value="10015">15 minutes</option>
            <option value="10030">30 minutes</option>
            <option value="10060">60 minutes</option>
            <option value="10090">90 minutes</option>
            <option value="10120">120 minutes</option>
        </select>
    </div>

	<div class="form-row">
		<label for="node-input-startoff"><i class="fa fa-clock-o"></i>On Offset</label>
		<input type="text" id="node-input-startoff" placeholder="0">
	</div>

	<div class="form-row">
		<label for="node-input-endoff"><i class="fa fa-clock-o"></i> Off Offset</label>
		<input type="text" id="node-input-endoff" placeholder="0">
	</div>
	
	<div class="form-row">	
		<label for="node-input-lat"><i class="fa fa-globe"></i> Latitude</label>
		<input type="text" id="node-input-lat" placeholder="51.025">
	</div>
  
	<div class="form-row">
		<label for="node-input-lon"><i class="fa fa-globe"></i> Longitude</label>
		<input type="text" id="node-input-lon" placeholder="-1.4">
	</div>

  
	<div class="form-row">
		<label for="node-input-outtopic"><i class="fa fa-tag"></i> Topic Msg</label>
		<input type="text" id="node-input-outtopic" placeholder="MQTT Topic">
	</div>

	<div class="form-row">
		<label for="node-input-outpayload1"><i class="fa fa-tag"></i> ON Msg</label>
		<input type="text" id="node-input-outpayload1" placeholder="MQTT Payload">
	</div>
	<div class="form-row">
		<label for="node-input-outtext1"><i class="fa fa-tag"></i> ON Text</label>
		<input type="text" id="node-input-outtext1" placeholder="Text">
	</div>
	
	<div class="form-row">
		<label for="node-input-outpayload2"><i class="fa fa-tag"></i> OFF Msg</label>
		<input type="text" id="node-input-outpayload2" placeholder="MQTT Payload">
	</div>
	<div class="form-row">
		<label for="node-input-outtext2"><i class="fa fa-tag"></i> OFF Text</label>
		<input type="text" id="node-input-outtext2" placeholder="Text">
	</div>
	<style>
	input[type=checkbox] { vertical-align:top; position:relative; bottom:1px; } 
	</style>
  
	<div>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sun" placeholder="sun" >Sun</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-mon" placeholder="mon" >Mon</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-tue" placeholder="tue" >Tue</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-wed" placeholder="wed" >Wed</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-thu" placeholder="thu" >Thu</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-fri" placeholder="fri" >Fri</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sat" placeholder="sat" >Sat</span>
	</div>
	<br/><br/>
	<div>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jan" placeholder="jan" >Jan</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-feb" placeholder="feb" >Feb</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-mar" placeholder="mar" >Mar</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-apr" placeholder="apr" >Apr</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-may" placeholder="may" >May</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jun" placeholder="jun" >Jun</span>
		<br/><br/>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-jul" placeholder="jul" >Jul</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-aug" placeholder="aug" >Aug</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-sep" placeholder="sep" >Sep</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-oct" placeholder="oct" >Oct</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-nov" placeholder="nov" >Nov</span>
		<span style="width: 50px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-dec" placeholder="dec" >Dec</span>
	</div>

	<br/><br/>
	
		<div>
		<span style="width: 150px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-suspend" placeholder="suspend" >Suspend schedule</span>
		<span style="width: 150px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-random" placeholder="random" >Randomise offsets</span>
		<br/><br/>
	</div>
	<div>
		<span style="width: 150px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-repeat" placeholder="repeat" >Repeat output</span>
		<span style="width: 150px; float: left; margin-left: 5px;"><input type="checkbox" id="node-input-atstart" placeholder="atstart" >Output at startup</span>
		<br/><br/>
	</div>
	

	
</script>



<script type="text/x-red" data-help-name="bigtimer">
    <p>Uses the suncalc module and timing options to generate a topic and one of two messages from output 1 - checked every minute)</p>
    <p>The Dawn and Dusk offsets can be both positive (+ve) for minutes later or negative (-ve) for minutes earlier.</p>
	<p>Output 1 outputs only when the manual input is pressed or when the CHANGE occurs. Output 2 simply sends "1" or "0" to the payload every minute regardless along with status info in msg.state and msg.time</p>
</script>

<script type="text/javascript">
    RED.nodes.registerType('bigtimer',{
        category: 'scargill-input',
        color:"#99ff00",
        defaults: {
            outtopic: {value:""},
            outpayload1: {value:""},
            outpayload2: {value:""},
		    name: {value:"Big Timer"},
            lat: {value:"", required:true, validate:RED.validators.number()},
            lon: {value:"", required:true, validate:RED.validators.number()},
            start: {value:"sunrise", required:true},
            end: {value:"sunset", required:true},
			starttime: {value:"5000", required: true},
			endtime: {value:"1435", required: true},
			startoff: {value:"0", required: true},
			endoff: {value:"0", required: true},
			outtext1: {value:""},
			outtext2: {value:""},
			sun: {value:true},
			mon: {value:true},
			tue: {value:true},
			wed: {value:true},
			thu: {value:true},
			fri: {value:true},
			sat: {value:true},
			jan: {value:true},
			feb: {value:true},
			mar: {value:true},
			apr: {value:true},
			may: {value:true},
			jun: {value:true},
			jul: {value:true},
			aug: {value:true},
			sep: {value:true},
			oct: {value:true},
			nov: {value:true},
			dec: {value:true},
			suspend: {value:false},
			random: {value:true},
			repeat: {value:false},
			atstart: {value:true}
			},
        inputs:1,
        outputs:3,
        icon: "timer.png",
        label: function() {
            return this.name||"bigtimer";
        },
        labelStyle: function() {
            return this.name?"node_label_italic":"";
        },
        oneditprepare: function() {
            if (($("#node-input-lat").val() === "") && ($("#node-input-lon").val() === "")) {
                if ("geolocation" in navigator) {
                    navigator.geolocation.getCurrentPosition(function(position) {
                        $("#node-input-lat").val(Number(position.coords.latitude.toFixed(5)));
                        $("#node-input-lon").val(Number(position.coords.longitude.toFixed(5)));
                    });
                }
            }
        }
    });
</script>











Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.