1 contributor
<script type="text/x-red" data-template-name="snzb-04p-homekit-adapter">
<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-site"><i class="fa fa-globe"></i> Site</label>
<input type="text" id="node-input-site" placeholder="vad">
</div>
<div class="form-row">
<label for="node-input-location"><i class="fa fa-home"></i> Location</label>
<input type="text" id="node-input-location" placeholder="entry">
</div>
<div class="form-row">
<label for="node-input-accessory"><i class="fa fa-dot-circle-o"></i> Accessory</label>
<input type="text" id="node-input-accessory" placeholder="front-door">
</div>
<div class="form-row">
<label for="node-input-sensorUsage">Usage</label>
<select id="node-input-sensorUsage">
<option value="door-window">Door / Window sensor</option>
<option value="contact">Generic contact sensor</option>
<option value="dual-contact">Dual contact: magnetic + mechanical</option>
</select>
</div>
<div class="form-row">
<label for="node-input-batteryLowThreshold">Battery low threshold (%)</label>
<input type="number" id="node-input-batteryLowThreshold" min="0" max="100" placeholder="20">
</div>
</script>
<script type="text/x-red" data-help-name="snzb-04p-homekit-adapter">
<p>
Consumes HomeBus telemetry for a single <code>SNZB-04P</code> endpoint and projects it to HomeKit services.
</p>
<p>
This adapter supports three usage modes. In all cases the HomeKit service type remains <code>ContactSensor</code>;
the usage setting documents the intended role of the device in the flow and controls whether a secondary contact output is emitted.
</p>
<p>
<code>Door / Window sensor</code>: use the magnetic contact as the primary contact sensor for doors and windows.
</p>
<p>
<code>Generic contact sensor</code>: use the same primary contact output where the endpoint is not modeled as a door or window in the flow.
</p>
<p>
<code>Dual contact: magnetic + mechanical</code>: expose the magnetic contact on output 1 and the mechanical/tamper contact on output 2.
</p>
<p>
Mappings:
<code>contact -> Contact Sensor</code>,
<code>battery + battery_low -> Battery</code>,
and in <code>dual-contact</code> mode <code>tamper -> secondary Contact Sensor</code>.
Optional <code>tamper</code> updates are folded into HomeKit status flags when available.
</p>
<ol>
<li>Contact magnetic: <code>{ ContactSensorState, StatusActive, StatusFault, StatusLowBattery, StatusTampered }</code></li>
<li>Contact mecanic din <code>tamper</code> in modul <code>dual-contact</code>: <code>{ ContactSensorState, StatusActive, StatusFault, StatusLowBattery, StatusTampered }</code></li>
<li>Battery Service: <code>{ StatusLowBattery, BatteryLevel, ChargingState }</code></li>
<li><code>mqtt in</code> dynamic control messages: <code>{ action, topic }</code></li>
</ol>
<h3>HomeKit Service Setup</h3>
<p><code>Battery</code></p>
<pre><code>{"BatteryLevel":{},"ChargingState":{}}</code></pre>
<p><code>Contact</code></p>
<pre><code>{"StatusActive":{},"StatusFault":{},"StatusLowBattery":{},"StatusTampered":{}}</code></pre>
<p><code>Secondary contact</code> in <code>dual-contact</code> mode</p>
<pre><code>{"StatusActive":{},"StatusFault":{},"StatusLowBattery":{},"StatusTampered":{}}</code></pre>
</script>
<script>
function requiredText(v) {
return !!(v && String(v).trim());
}
RED.nodes.registerType("snzb-04p-homekit-adapter", {
category: "myNodes",
color: "#d7f0d1",
defaults: {
name: { value: "" },
outputTopic: { value: "" },
mqttBus: { value: "" },
site: { value: "", validate: requiredText },
location: { value: "", validate: requiredText },
accessory: { value: "", validate: requiredText },
sensorUsage: { value: "door-window" },
mqttSite: { value: "" },
mqttRoom: { value: "" },
mqttSensor: { value: "" },
batteryLowThreshold: { value: 20, validate: RED.validators.number() },
publishCacheWindowSec: { value: "" }
},
inputs: 1,
outputs: 4,
icon: "font-awesome/fa-exchange",
label: function() {
return this.name || "snzb-04p-homekit-adapter";
},
paletteLabel: "snzb-04p homekit"
});
</script>