UNPKG

node-red-contrib-zigbee2mqtt-devices

Version:
256 lines (233 loc) 9.88 kB
<!--- SHELLY CONFIG NODE ---> <script type="text/javascript"> RED.nodes.registerType('shelly-config', { category: 'config', defaults: { name: { value: "" }, prefix: { value: "", required: true }, }, label: function () { return this.name || "shelly 2.5"; }, }); </script> <script type="text/html" data-template-name="shelly-config"> <div class="form-row"> <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label> <input type="text" id="node-config-input-name" placeholder="Name" /> </div> <div class="form-row"> <label for="node-config-input-prefix"><i class="fa fa-tag"></i> MQTT Prefix</label> <input type="text" id="node-config-input-prefix" placeholder="shellies/<shellymodel>-<deviceid>"/> </div> </script> <script type="text/html" data-help-name="shelly-config"> <p> Configure your shelly device's MQTT topic. </p> <h3>Configuration</h3> <dl class="message-properties"> <h4>Name</h4> <p> Optional friendly name for the shelly. </p> <h4>MQTT Prefix</h4> <p> The shelly's MQTT topic it listens and publishes to. Usually, shellies publish under the "shellies" topic directly in the root followed by their unique name.<br> Example: <code>shellies/my-device</code>. </p> </dl> </script> <!--- SHELLY NODE ---> <script type="text/javascript"> RED.nodes.registerType('shelly-25', { category: 'zigbee2mqtt_non_z2m-input', defaults: { name: { value: "" }, mqtt: { type: "mqtt-broker" }, shelly: { type: "shelly-config" }, enableInput: { value: true }, state: { value: "on" }, channel: { value: "0" }, inputs: { value: 1 }, outputs: { value: 3 }, customPayload: { value: false }, payloadInput0: { value: "" }, typeInput0: { value: "str" }, payloadInput1: { value: "" }, typeInput1: { value: "str" }, }, inputs: 1, outputs: 3, outputLabels: function (i) { var no = parseInt(this.channel) + 1; var labels = ["Channel " + no, "Input " + no, "Message"]; if (no === 3) { labels[0] = "Both Channels"; labels[1] = "Both Inputs"; } return labels[i]; }, icon: "remote-black.svg", label: function () { return this.name || "shelly 2.5"; }, paletteLabel: "shelly 2.5", oneditprepare: function () { RED.bavaria.ui.addMultiInput(this, "Input0"); RED.bavaria.ui.addMultiInput(this, "Input1"); $("#node-input-customPayload").change(function () { if ($("#node-input-customPayload").is(":checked")) { $("#customInputPayload").show(); } else { $("#customInputPayload").hide(); } }); $("#node-input-channel").change(function () { var channel = $(this).val(); switch (channel) { case "0": $("#customInputPayload0").show(); $("#customInputPayload1").hide(); break; case "1": $("#customInputPayload0").hide(); $("#customInputPayload1").show(); break; case "2": $("#customInputPayload0").show(); $("#customInputPayload1").show(); break; } }); }, oneditsave: function () { if ($("#node-input-enableInput").is(":checked") && (this.inputs !== 1 || !this.inputs)) { this.inputs = 1; this.outputs = 3; } else if (!$("#node-input-enableInput").is(":checked") && (this.inputs !== 0 || !this.inputs)) { this.inputs = 0; this.outputs = 2; } RED.bavaria.ui.saveMultiInput(this, "Input0") RED.bavaria.ui.saveMultiInput(this, "Input1") } }); </script> <script type="text/html" data-template-name="shelly-25"> <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> <div class="form-row"> <label for="node-input-mqtt"><i class="fa fa-tag"></i> Broker</label> <input type="text" id="node-input-mqtt" /> </div> <div class="form-row"> <label for="node-input-shelly"><i class="fa fa-tag"></i> Device</label> <input type="text" id="node-input-shelly" /> </div> <div class="form-row"> <label for="node-input-channel"><i class="fa fa-power-off"></i> Channel</label> <select id="node-input-channel"> <option value="0">Channel 1</option> <option value="1">Channel 2</option> <option value="2">Both</option> </select> </div> <div class="form-row"> <label for="node-input-state"><i class="fa fa-power-off"></i> State</label> <select id="node-input-state"> <option value="on">On</option> <option value="off">Off</option> <option value="toggle">Toggle</option> </select> </div> <div class="form-row"> <label for="node-input-enableInput"><i class="fa fa-tag"></i> Enable Input</label> <input type="checkbox" id="node-input-enableInput"/> </div> <div class="form-row"> <label for="node-input-customPayload"><i class="fa fa-tag"></i> Enable Custom Payload</label> <input type="checkbox" id="node-input-customPayload"/> </div> <div id="customInputPayload"> <div class="form-row" id="customInputPayload0"> <label for="node-input-payloadInput0"><i class="fa fa-tag"></i> Custom Payload 1</label> <input type="text" id="node-input-payloadInput0"> </div> <div class="form-row" id="customInputPayload1"> <label for="node-input-payloadInput1"><i class="fa fa-tag"></i> Custom Payload 2</label> <input type="text" id="node-input-payloadInput1"> </div> </div> </script> <script type="text/html" data-help-name="shelly-25"> <p> The shelly 2.5 node controls the relays on a shelly and receives input, relay, and status changes. Tested with Shelly 1 and Shelly 2.5. </p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">any</span> </dt> <dd> Any input triggers the node to switch the relay. </dd> </dl> <h3>Outputs</h3> <ol class="node-ports"> <li>Relay <dl class="message-properties"> <dt>payload <span class="property-type">string</span></dt> <dd>Emits messages when the shelly's relay changes.</dd> </dl> </li> <li>Input <dl class="message-properties"> <dt>payload <span class="property-type">string</span></dt> <dd>Emits messages when the shelly's input changes.</dd> </dl> </li> <li>Message <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>Emits messages that shall be published to the shelly via connected send-messages node.</dd> </dl> </li> </ol> <h3>Configuration</h3> <dl class="message-properties"> <h4>Broker</h4> <p> Configures the MQTT broker the shelly publishes to. </p> <h4>Device</h4> <p> The device section configures a shelly's MQTT topic and, optionally, its friendly name. For example, <code>shellies/my-device</code>. The shelly node will subscribe and publish on this topic. </p> <h4>Channel</h4> <p> The channel configures which relay will be triggered when the node receives an input. Furthermore, the node only publishes relay and input changes for the selected input. Possible options are: <ul> <li><code>Channel 1</code>: Switches and subscribes to channel 1 (MQTT topic <code>relay/0</code> and <code>input/0</code>).</li> <li><code>Channel 2</code>: Switches and subscribes to channel 2 (MQTT topic <code>relay/1</code> and <code>input/1</code>).</li> <li><code>Both</code>: Switches and subscribes to channels 1 and 2.</li> </ul> </p> <h4>State</h4> <p> The state is used to control the relay when the node receives an input. <ul> <li><code>On</code>: Switches the relay for the selected channel to on.</li> <li><code>Off</code>: Switches the relay for the selected channel to off.</li> <li><code>Toggle</code>: Switches the relay for the selected channel on if it is off and vice versa.</li> </ul> </p> <h4>Enable Input</h4> <p> This option enables the input connector on the node. Only when it is enabled is it possible to switch the relays. </p> <h4>Custom payload</h4> <p> The custom payload allows you to define a specific payload to be published when the shelly's input state changes since the default are <code>0</code> and <code>1</code>, which might not be too helpful, primarily if two channels are used. </p> </dl> </script>