1 contributor
<script type="text/x-red" data-template-name="pa-44z-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="kitchen">
</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="smoke-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="pa-44z-homekit-adapter">
<p>
Consumes HomeBus telemetry for a single <code>PA-44Z</code> smoke detector endpoint and projects it to HomeKit services.
</p>
<p>
Output 3 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 bootstrap is held open for <code>10s</code>, then emits a complete snapshot and unsubscribes from <code>.../last</code>.
</p>
<h3>Capabilities</h3>
<p>
Mappings:
<code>smoke -> Smoke Sensor</code>,
<code>battery + battery_low -> Battery</code>,
<code>device_fault -> StatusFault</code>.
</p>
<p>
<code>silence</code>, <code>test</code>, and <code>smoke_concentration</code> are carried on HomeBus but are not exposed to HomeKit by this adapter.
</p>
<h3>Outputs</h3>
<ol>
<li>Smoke Sensor: <code>{ SmokeDetected, StatusActive, StatusFault, StatusLowBattery }</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>Smoke Sensor</code></p>
<pre><code>{"StatusActive":{},"StatusFault":{},"StatusLowBattery":{}}</code></pre>
<p><code>Battery</code></p>
<pre><code>{"BatteryLevel":{},"ChargingState":{}}</code></pre>
</script>
<script>
function requiredText(v) {
return !!(v && String(v).trim());
}
RED.nodes.registerType("pa-44z-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-fire-extinguisher",
label: function() {
return this.name || "pa-44z-homekit-adapter";
},
paletteLabel: "pa-44z homekit"
});
</script>