UNPKG

node-red-contrib-esplogin

Version:

This node is specifically designed to work with ESP-GO home control software - link and info at https://tech.scargill.net

89 lines (79 loc) 4.32 kB
<!-- Mostly - apart from the Sunrise module on which this depends this 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 purpose of this node is to send out time and date information to ESP8266 units - either as a blanket update via MQTT to all units once a day or on request when a unit "logs in". Specific requests result in a message being returned to a specific unit. The information includes time un Unix format and dusk and dawn in minutes past midnight. --> <script type="text/x-red" data-template-name="esplogin"> <div class="form-row"> <label for="node-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-input-name" value="ESP LOGIN" placeholder="Name"> </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-duskoff"><i class="fa fa-clock-o"></i> Dusk Offs</label> <input type="text" id="node-input-duskoff" placeholder="0"> </div> <div class="form-row"> <label for="node-input-dawnoff"><i class="fa fa-clock-o"></i> Dawn Offs</label> <input type="text" id="node-input-dawnoff" placeholder="0"> </div> </script> <script type="text/x-red" data-help-name="esplogin"> <h3>ESPLOGIN Node</h3> <p>The node is designed to work with ESP 21-based boards using ESP-Go software and the open-source project "Home control 2018" <a target="_blank" href="https://tech.scargill.net/home-control-2018/">based at the tech blog https://tech.scargill.net.</a></p> <p>The node generates timie, dusk, dawn and logging output on powerup then every 12 hours, also on demand from specific WSP12 units.</p> <p>The time will be summer/winter corrected. Dusk and dawn offsets are in minutes past midnight.</p> <p> The first output generates MQTT topic "toesp" and a payload which contains time, dusk and dawn on demand for a specified longitude and latitude, OR the same with the topic prefixed by the input payload on demand from a particular unit (which has sent a JSON payload including its ID i.e. xxx.id).</p> <p>The second output (optional) is legacy log info in MYSQL format, the third output (optional) is text for a log file, the 4th output (optional) is SQLITE logging info. Output 5 (optional) is merely as per output 1 but in valid JSON format.</p> <p>The node gives status info underneath, showing the last logged-in unit.</p> </script> <script type="text/javascript"> RED.nodes.registerType('esplogin',{ category: 'advanced-input', color:"#FFDD55", outputLabels: ["ESP8266 time and dusk/dawn","MYSQL","Text","SQLITE logging info","JSON format out"], defaults: { name: {value:""}, 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}, duskoff: {value:"0", required: true}, dawnoff: {value:"0", required: true} }, inputs:1, outputs:5, icon: "sun.png", label: function() { return this.name||"ESP Login"; }, 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>