UNPKG

node-red-contrib-jewishtimer

Version:

A Timer for node-red which supports jewish dates and Zmanim

392 lines (384 loc) 14.5 kB
<script type="text/javascript"> const TIMER_COUNT = /* REPLACE_TIMER_COUNT */; const DAYS_COUNT = /* REPLACE_DAYS_COUNT */; const timerDefaults = (()=>{ const obj = {}; for(let i=0;i<TIMER_COUNT;i++){ const id = i+1; obj[`sc${id}TimeActive`] = {value: false}; obj[`sc${id}TimeAction`] = {value:0}; obj[`sc${id}Timetype`] = {value:"time"}; obj[`sc${id}Time`] = {value: "00:00"}; obj[`sc${id}Zman`] = {value:"AlosHashachar"}; obj[`sc${id}Zmanoffset`] = {value:0}; obj[`sc${id}Zmanoffsettype`] = {value:60000}; } for(let i=0;i<DAYS_COUNT;i++){ const id = i+1; obj[`sc${id}DateActive`] = {value: false}; obj[`sc${id}DateAction`] = {value:0}; obj[`sc${id}Datetype`] = {value:"weekday"}; obj[`sc${id}Sun`] = {value:1}; obj[`sc${id}Mon`] = {value:1}; obj[`sc${id}Tue`] = {value:1}; obj[`sc${id}Wed`] = {value:1}; obj[`sc${id}Thu`] = {value:1}; obj[`sc${id}Fri`] = {value:1}; obj[`sc${id}Sat`] = {value:1}; obj[`sc${id}Jan`] = {value:1}; obj[`sc${id}Feb`] = {value:1}; obj[`sc${id}Mar`] = {value:1}; obj[`sc${id}Apr`] = {value:1}; obj[`sc${id}May`] = {value:1}; obj[`sc${id}Jun`] = {value:1}; obj[`sc${id}Jul`] = {value:1}; obj[`sc${id}Aug`] = {value:1}; obj[`sc${id}Sep`] = {value:1}; obj[`sc${id}Oct`] = {value:1}; obj[`sc${id}Nov`] = {value:1}; obj[`sc${id}Dec`] = {value:1}; obj[`sc${id}Nisan`] = {value:1}; obj[`sc${id}Iyar`] = {value:1}; obj[`sc${id}Sivan`] = {value:1}; obj[`sc${id}Tamuz`] = {value:1}; obj[`sc${id}Av`] = {value:1}; obj[`sc${id}Elul`] = {value:1}; obj[`sc${id}Tishri`] = {value:1}; obj[`sc${id}Heshvan`] = {value:1}; obj[`sc${id}Kislev`] = {value:1}; obj[`sc${id}Tevet`] = {value:1}; obj[`sc${id}Shvat`] = {value:1}; obj[`sc${id}Adar1`] = {value:1}; obj[`sc${id}Adar2`] = {value:1}; obj[`sc${id}jmonthdays`] = {}; obj[`sc${id}gmonthdays`] = {}; } return obj; })(); RED.nodes.registerType('jewish-timer',{ category: 'function', color: '#a6bbcf', defaults: { name: {value:""}, comment: {value: ""}, lat: {value: 0, required:true}, lon: {value: 0, required:true}, topic: {value:""}, onmsg: {value: "ON"}, offmsg: {value: "OFF"}, forceinactive: {value: true}, forceinactivefullday: {value:false}, inactiveoffset: {value:1}, inactiveoffsettype: {value:3600000}, ...timerDefaults, startoffset: {value:0}, endoffset: {value:72}, delay: {value:0}, delaytype: {value:60000} }, inputs:1, outputs:1, icon: "switch.png", label: function() { return this.name||"Jewish Timer"; }, oneditprepare: function() { if (($("#node-input-lat").val() === "0") && ($("#node-input-lon").val() === "0")) { 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))); }); } } $(".expand-collapse").click((e)=>{ const cont = $(e.target).parents(".expend-container"); if(cont.hasClass("expanded")){ cont.removeClass("expanded").addClass("collapsed") }else{ cont.removeClass("collapsed").addClass("expanded") } }); $(".js-timetype").change(e=>{ const val = e.target.value; $(e.target).parents(".js-entry").removeClass("timertype-time timertype-zman").addClass(`timertype-${val}`); }); $(".js-datetype").change(e=>{ const val = e.target.value; $(e.target).parents(".js-entry").removeClass("datetype-weekday datetype-jmonthday datetype-gmonthday").addClass(`datetype-${val}`); }); $(".js-active").change(e=>{ if(e.target.checked){ $(e.target).parents(".js-entry").addClass("active"); } else { $(e.target).parents(".js-entry").removeClass("active"); } }); $(".js-inactive").change(e=>{ if(!e.target.checked){ $(".inactive-rel").hide(); } else { $(".inactive-rel").show(); } }); $(".js-inactive-full").change(e=>{ if(e.target.checked){ $(".inactive-partial").hide(); } else { $(".inactive-partial").show(); } }); } }); </script> <script type="text/html" data-template-name="jewish-timer"> <style> div.checkbox-field{ max-width:200px; } div.checkbox-field input { width:20px; margin-bottom:4px; } .large-label { width:100%; } </style> <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="Jewish Timer"> </div> <div class="form-row"> <label for="node-input-comment"><i class="fa fa-tag"></i> Comment</label> <input type="text" id="node-input-comment" placeholder="Jewish Timer"> </div> <div class="form-row"> <label for="node-input-lat"><i class="fa fa-compass"></i> Lat</label> <input type="text" id="node-input-lat" placeholder="0"> </div> <div class="form-row"> <label for="node-input-lon"><i class="fa fa-compass"></i> Lon</label> <input type="text" id="node-input-lon" placeholder="0"> </div> <div class="form-row"> <label for="node-input-topic"><i class="fa fa-tag"></i>TOPIC</label> <input type="text" id="node-input-topic" placeholder="MQTT Topic" /> </div> <div class="form-row"> <label for="node-input-onmsg"><i class="fa fa-envelop"></i>On MSG</label> <input type="text" id="node-input-onmsg" placeholder="ON" value="ON" /> </div> <div class="form-row"> <label for="node-input-offmsg"><i class="fa fa-envelop"></i>Off MSG</label> <input type="text" id="node-input-offmsg" placeholder="OFF" value="OFF" /> </div> <div class="form-row"> <label for="node-input-forceinactive" class="auto">Force subsequent Nodes to be inactive:</label> <input type="checkbox" id="node-input-forceinactive" class="auto js-inactive" /> </div> <div class="form-row inactive-rel"> <label for="node-input-forceinactivefullday" class="auto">Force Inactive for full day(00:00 - 11:59:59):</label> <input type="checkbox" id="node-input-forceinactivefullday" class="auto js-inactive-full"/> </div> <div class="form-row inactive-rel inactive-partial"> <label for="node-input-inactiveoffset" class="auto">Inactive Offset after last msg:</label> <input type="number" id="node-input-inactiveoffset" placeholder="0"> <select id="node-input-inactiveoffsettype" > <option value="1000">Seconds</option> <option value="60000" selected="selected">Minutes</option> <option value="3600000">Hours</option> </select> </div> <hr/> <style> .expend-container.collapsed .expanded-vis { display: none!important; } .expend-container.expanded .collapsed-vis{ display: none!important; } .expand-collapse { cursor: pointer; } .timertype-time .zman-selection{ display: none!important; } .timertype-zman .time-selection{ display: none!important; } .entry{ opacity: .5; } .entry.active{ opacity: 1; } .entry{ margin: 10px 0px; background-color: #f2f2f2; padding: 10px; } .entry [data-nodetype$="Active"]{ width:18%; display:inline-block; } .entry [data-nodetype$="Active"] label{ width:40px; } .entry [data-nodetype$="Active"] input{ width:20px; vertical-align:top; } .entry [data-nodetype$="Action"] { width:32%; display:inline-block; } .entry [data-nodetype$="Action"] label{ width:44px; } .entry [data-nodetype$="Action"] select{ width: 80px; } .entry [data-nodetype="Timetype"], .entry [data-nodetype="Datetype"]{ width:40%; padding-left:14px; display:inline-block; } .entry [data-nodetype="Timetype"] label, .entry [data-nodetype="Datetype"] label{ width:70px; } .entry [data-nodetype="Timetype"] select,.entry [data-nodetype="Datetype"] select{ width:80px; } .entry [data-nodetype="Time"]{ width:40%; display:inline-block; } .entry [data-nodetype="Time"] label{ width:40px; } .entry [data-nodetype="Time"] input{ width:110px; } .entry [data-nodetype="Zman"]{ width:48%; display:inline-block; } .entry [data-nodetype="Zman"] label{ width:56px; } .entry [data-nodetype="Zman"] select{ width:138px; } .entry [data-nodetype="Zmanoffset"]{ display:inline-block; } .entry [data-nodetype="Zmanoffset"] label{ width:40px; } .entry [data-nodetype="Zmanoffset"] input, .red-ui-editor div div.inactive-partial input{ width:58px; } .entry [data-nodetype="Zmanoffset"] select, div div.inactive-partial select{ width:110px; } .datetype-jmonthday .weekday-selection, .datetype-gmonthday .weekday-selection, .datetype-weekday .jmonthday-selection, .datetype-weekday .gmonthday-selection, .datetype-jmonthday .gmonthday-selection, .datetype-gmonthday .jmonthday-selection { display: none!important; } /* handling a special include for first date selection */ .specialinclude { display: none; } #node-input-sc1DateAction .specialinclude { display: inline-block; } #node-input-sc1DateAction .onlyinclude, #node-input-sc1DateAction .reginclude { display:none; } .inline { display: inline; padding-right: 5px; } .red-ui-editor .form-row span.inline label { width:auto; } .red-ui-editor .form-row span.inline input { width: auto; vertical-align: top; } div.red-ui-editor div.form-row *.auto { width:auto; } div.red-ui-editor div.form-row input.auto{ vertical-align:top; } </style> <div id="schedule-container" class="expend-container collapsed"> <h4 class="expand-collapse"> Set Schedule Times <i class="fa fa-chevron-down collapsed-vis"></i> <i class="fa fa-chevron-up expanded-vis"></i> </h4> <!-- REPLACE_TIMER_HTML --> </div> <hr/> <div id="dates-container" class="expend-container collapsed"> <h4 class="expand-collapse"> Set Schedule Dates <i class="fa fa-chevron-down collapsed-vis"></i> <i class="fa fa-chevron-up expanded-vis"></i> </h4> <!-- REPLACE_DAYS_HTML --> </div> </script> <script type="text/html" data-help-name="jewish-timer"> <h1 id="jewish-timer">Jewish Timer</h1> <h2 id="overview">Overview</h2> <p>Jewish Timer allows you to set schedules by weekday, Gregorian Calendar and Jewish Calendar.</p> <p>Schedules can be set to a specific time or based on Jewish Zmanim.</p> <p>It allows for up to 10 schedules per day, and lets you set up to 10 date selections,<br>each date selection can either include, exclude or limit to a specific date (or group dates).</p> <p>It also allows chaining timers one on top of the other.<br>The top one can silence the next one, this allows you to<br>set a default weekly schedule and then add custom schedules for special dates.</p> <h2 id="options">Options</h2> <h3 id="lat-required-">Lat (required)</h3> <p>The Latitude to calculate the Zmanim.</p> <h3 id="lon-required-">Lon (required)</h3> <p>The Longitude to calculate the Zmanim.</p> <h3 id="topic">Topic</h3> <p>A MQTT topic to post to</p> <h3 id="on-msg">On Msg</h3> <p>The Msg to send on the ON event</p> <h3 id="off-msg">Off Msg</h3> <p>The Msg to send on the OFF event</p> <h3 id="force-subsequent-nodes-to-be-inactive">Force subsequent Nodes to be inactive</h3> <h3 id="force-inactive-for-full-day-00-00-11-59-59-">Force Inactive for full day(00:00 - 11:59:59)</h3> <h3 id="inactive-offset-after-last-msg">Inactive Offset after last msg</h3> <p>We can force schdules node behind this one to be inactive, eihter for a set time after the last schedule or for the full day.&#39;</p> <hr> <h3 id="set-schedule-times">Set Schedule Times</h3> <p>This is where you set the time and action for a schedule</p> <h4 id="active">Active</h4> <p>Allows you to temporarily inactivate a schedule</p> <h4 id="action">Action</h4> <p>The Action to happen at the set time</p> <h4 id="time-type">Time Type</h4> <p>You can set a specific time or a zman based time</p> <h4 id="time-depending-on-earlier-selection-">Time (depending on earlier selection)</h4> <p>The time for the event</p> <h4 id="zman-depending-on-earlier-selection-">Zman (depending on earlier selection)</h4> <p>At which zman the event should run</p> <h4 id="offset-depending-on-earlier-selection-">Offset (depending on earlier selection)</h4> <p>You can set A positive or negetive offset to a zman</p> <h3 id="set-schedule-dates">Set Schedule Dates</h3> <p>This is where you set the date a schedule should be active</p> <h4 id="active">Active</h4> <p>Allows you to temporarily inactivate a selection</p> <h4 id="action">Action</h4> <p>whether the selected date should be added to the active dates or excluded, from the second date selection and on you can also choose to &quot;only include&quot;, which will limit the schedule to only the current date selection (given it was enabled by a previous selection). </p> <blockquote> <p><strong><em>With these Date selection options you can combine date filters across different selections (Ex: only run on Summer Sundays, or just Shabbos Erev Pasech).</em></strong></p> </blockquote> <h4 id="date-type">Date Type</h4> <p>Which type of Date to use for the filter (greg, jewish, or weekday).<br>Based on the date type you can either select weekdays or months and the days in a Month. </p> <blockquote> <p>Note: Days in month needs to be a comma delimited list (an empty list will be not be active)</p> </blockquote> </script>