1 contributor
<script type="text/x-red" data-template-name="snzb-05p-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="bathroom">
</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="sink-sensor">
</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-05p-homekit-adapter">
<p>
Consumes HomeBus telemetry for a single <code>SNZB-05P</code> endpoint and projects it to HomeKit services.
</p>
<p>
Output 3 is not a publish stream anymore. It controls a Node-RED <code>mqtt in</code> node with dynamic subscriptions.
</p>
<p>
On start, the node emits:
<code>subscribe <site>/home/<location>/+/<accessory>/last</code>,
<code>subscribe <site>/home/<location>/+/<accessory>/value</code>, and
<code>subscribe <site>/home/<location>/+/<accessory>/availability</code>.
</p>
<p>
The node keeps <code>.../last</code> subscribed until the cold-start bootstrap is complete for all required values.
A value is considered satisfied when it arrived either from <code>last</code> or from live <code>value</code>.
Only then does the node emit <code>unsubscribe .../last</code>.
</p>
<p>
Supported input topic shape:
<code><site>/home/<location>/<capability>/<accessory>/value</code>,
<code><site>/home/<location>/<capability>/<accessory>/last</code>, and
<code><site>/home/<location>/<capability>/<accessory>/availability</code>.
</p>
<p>
The node accepts scalar <code>value</code> payloads, string/boolean <code>availability</code> payloads,
and timestamped <code>last</code> envelopes of the form
<code>{ value, observed_at, quality }</code>. For <code>last</code>, only <code>payload.value</code> is used.
</p>
<h3>Capabilities</h3>
<p>
Mappings:
<code>water_leak -> Leak Sensor</code>,
<code>battery + battery_low -> Battery</code>.
Optional <code>tamper</code> updates are folded into HomeKit status flags when available.
</p>
<p>
Subscription topics are generated from the configured <code>site</code>, <code>location</code>, and
<code>accessory</code>. The bus segment remains fixed to <code>home</code>.
</p>
<h3>Outputs</h3>
<ol>
<li>Leak Sensor: <code>{ LeakDetected, 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>
The linked <code>homekit-service</code> nodes should explicitly materialize the optional characteristics used by this adapter.
Set the Battery service node <code>characteristicProperties</code> to:
</p>
<pre><code>{"BatteryLevel":{},"ChargingState":{}}</code></pre>
<p>
Without these optional characteristics, HomeKit may keep default values until a later update or ignore the fields during startup.
</p>
</script>
<script>
function requiredText(v) {
return !!(v && String(v).trim());
}
RED.nodes.registerType("snzb-05p-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 },
mqttSite: { value: "" },
mqttRoom: { value: "" },
mqttSensor: { value: "" },
batteryLowThreshold: { value: 20, validate: RED.validators.number() },
publishCacheWindowSec: { value: "" }
},
inputs: 1,
outputs: 3,
icon: "font-awesome/fa-tint",
label: function() {
return this.name || "snzb-05p-homekit-adapter";
},
paletteLabel: "snzb-05p homekit"
});
</script>