|
Bogdan Timofte
authored
2 weeks ago
|
1
|
<script type="text/x-red" data-template-name="zg-204zv-homekit-adapter">
|
|
|
2
|
<div class="form-row">
|
|
|
3
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
|
4
|
<input type="text" id="node-input-name" placeholder="Name">
|
|
|
5
|
</div>
|
|
|
6
|
<div class="form-row">
|
|
|
7
|
<label for="node-input-site"><i class="fa fa-globe"></i> Site</label>
|
|
|
8
|
<input type="text" id="node-input-site" placeholder="vad">
|
|
|
9
|
</div>
|
|
|
10
|
<div class="form-row">
|
|
|
11
|
<label for="node-input-location"><i class="fa fa-home"></i> Location</label>
|
|
|
12
|
<input type="text" id="node-input-location" placeholder="balcon">
|
|
|
13
|
</div>
|
|
|
14
|
<div class="form-row">
|
|
|
15
|
<label for="node-input-accessory"><i class="fa fa-dot-circle-o"></i> Accessory</label>
|
|
|
16
|
<input type="text" id="node-input-accessory" placeholder="south">
|
|
|
17
|
</div>
|
|
|
18
|
<div class="form-row">
|
|
|
19
|
<label for="node-input-batteryLowThreshold">Battery low threshold (%)</label>
|
|
|
20
|
<input type="number" id="node-input-batteryLowThreshold" min="0" max="100" placeholder="20">
|
|
|
21
|
</div>
|
|
|
22
|
<div class="form-row">
|
|
|
23
|
<label for="node-input-occupancyFadingTimeSec">Occupancy fading time (s)</label>
|
|
|
24
|
<input type="number" id="node-input-occupancyFadingTimeSec" min="0" step="1" placeholder="300">
|
|
|
25
|
</div>
|
|
|
26
|
</script>
|
|
|
27
|
|
|
|
28
|
<script type="text/x-red" data-help-name="zg-204zv-homekit-adapter">
|
|
|
29
|
<p>
|
|
|
30
|
Consumes HomeBus telemetry for a single <code>ZG-204ZV</code> endpoint and projects it to HomeKit services.
|
|
|
31
|
</p>
|
|
|
32
|
<p>
|
|
|
33
|
Output 7 is not a publish stream anymore. It controls a Node-RED <code>mqtt in</code> node with dynamic subscriptions.
|
|
|
34
|
</p>
|
|
|
35
|
<p>
|
|
|
36
|
On start, the node emits:
|
|
|
37
|
<code>subscribe <site>/home/<location>/+/<accessory>/last</code> and
|
|
|
38
|
<code>subscribe <site>/home/<location>/+/<accessory>/value</code>.
|
|
|
39
|
</p>
|
|
|
40
|
<p>
|
|
|
41
|
The node keeps <code>.../last</code> subscribed until the cold-start bootstrap is complete for all required values.
|
|
|
42
|
A value is considered satisfied when it arrived either from <code>last</code> or from live <code>value</code>.
|
|
|
43
|
Only then does the node emit <code>unsubscribe .../last</code>.
|
|
|
44
|
</p>
|
|
|
45
|
<p>
|
|
|
46
|
Supported input topic shape:
|
|
|
47
|
<code><site>/home/<location>/<capability>/<accessory>/value</code> and
|
|
|
48
|
<code><site>/home/<location>/<capability>/<accessory>/last</code>.
|
|
|
49
|
</p>
|
|
|
50
|
<p>
|
|
|
51
|
The node accepts scalar <code>value</code> payloads and timestamped <code>last</code> envelopes of the form
|
|
|
52
|
<code>{ value, observed_at, quality }</code>. For <code>last</code>, only <code>payload.value</code> is used.
|
|
|
53
|
</p>
|
|
|
54
|
<h3>Capabilities</h3>
|
|
|
55
|
<p>
|
|
|
56
|
Mappings:
|
|
|
57
|
<code>motion -> Motion + Occupancy</code>,
|
|
|
58
|
<code>temperature -> Temperature</code>,
|
|
|
59
|
<code>humidity -> Humidity</code>,
|
|
|
60
|
<code>illuminance -> Light Level</code>,
|
|
|
61
|
<code>battery + battery_low -> Battery</code>.
|
|
|
62
|
</p>
|
|
|
63
|
<p>
|
|
|
64
|
Occupancy is synthesized locally from <code>motion</code> and the configured <code>Occupancy fading time</code>.
|
|
|
65
|
A <code>motion=true</code> sample sets occupancy, while <code>motion=false</code> only clears the Motion service immediately;
|
|
|
66
|
Occupancy clears when the local timer expires.
|
|
|
67
|
</p>
|
|
|
68
|
<p>
|
|
|
69
|
Subscription topics are generated from the configured <code>site</code>, <code>location</code>, and
|
|
|
70
|
<code>accessory</code>. The bus segment remains fixed to <code>home</code>.
|
|
|
71
|
</p>
|
|
|
72
|
<p>
|
|
|
73
|
For compatibility with existing flows, legacy accessory ids such as <code>radar-south</code> are normalized to
|
|
|
74
|
<code>south</code>.
|
|
|
75
|
</p>
|
|
|
76
|
<h3>Outputs</h3>
|
|
|
77
|
<ol>
|
|
|
78
|
<li>Motion Sensor: <code>{ MotionDetected, StatusActive, StatusFault, StatusLowBattery, StatusTampered }</code></li>
|
|
|
79
|
<li>Occupancy Sensor: <code>{ OccupancyDetected, StatusActive, StatusFault, StatusLowBattery, StatusTampered }</code></li>
|
|
|
80
|
<li>Temperature Sensor: <code>{ CurrentTemperature }</code></li>
|
|
|
81
|
<li>Humidity Sensor: <code>{ CurrentRelativeHumidity }</code></li>
|
|
|
82
|
<li>Light Sensor: <code>{ CurrentAmbientLightLevel }</code></li>
|
|
|
83
|
<li>Battery Service: <code>{ StatusLowBattery, BatteryLevel, ChargingState }</code></li>
|
|
|
84
|
<li><code>mqtt in</code> dynamic control messages: <code>{ action, topic }</code></li>
|
|
|
85
|
</ol>
|
|
|
86
|
<h3>HomeKit Service Setup</h3>
|
|
|
87
|
<p>
|
|
|
88
|
The linked <code>homekit-service</code> nodes should explicitly materialize the optional characteristics used by this adapter.
|
|
|
89
|
</p>
|
|
|
90
|
<p>
|
|
|
91
|
Recommended <code>characteristicProperties</code> values:
|
|
|
92
|
</p>
|
|
|
93
|
<p><code>Battery</code></p>
|
|
|
94
|
<pre><code>{"BatteryLevel":{},"ChargingState":{}}</code></pre>
|
|
|
95
|
<p><code>Motion</code></p>
|
|
|
96
|
<pre><code>{"StatusActive":{},"StatusFault":{},"StatusLowBattery":{},"StatusTampered":{}}</code></pre>
|
|
|
97
|
<p><code>Occupancy</code></p>
|
|
|
98
|
<pre><code>{"StatusActive":{},"StatusFault":{},"StatusLowBattery":{},"StatusTampered":{}}</code></pre>
|
|
|
99
|
<p>
|
|
|
100
|
Temperature, Humidity, and Light Level currently publish only their main reading, so no extra optional characteristics are required for those services.
|
|
|
101
|
</p>
|
|
|
102
|
</script>
|
|
|
103
|
|
|
|
104
|
<script>
|
|
|
105
|
function requiredText(v) {
|
|
|
106
|
return !!(v && String(v).trim());
|
|
|
107
|
}
|
|
|
108
|
|
|
|
109
|
RED.nodes.registerType("zg-204zv-homekit-adapter", {
|
|
|
110
|
category: "myNodes",
|
|
|
111
|
color: "#d7f0d1",
|
|
|
112
|
defaults: {
|
|
|
113
|
name: { value: "" },
|
|
|
114
|
outputTopic: { value: "" },
|
|
|
115
|
mqttBus: { value: "" },
|
|
|
116
|
site: { value: "", validate: requiredText },
|
|
|
117
|
location: { value: "", validate: requiredText },
|
|
|
118
|
accessory: { value: "", validate: requiredText },
|
|
|
119
|
mqttSite: { value: "" },
|
|
|
120
|
mqttRoom: { value: "" },
|
|
|
121
|
mqttSensor: { value: "" },
|
|
|
122
|
batteryLowThreshold: { value: 20, validate: RED.validators.number() },
|
|
|
123
|
occupancyFadingTimeSec: { value: 300, validate: RED.validators.number() },
|
|
|
124
|
publishCacheWindowSec: { value: "" }
|
|
|
125
|
},
|
|
|
126
|
inputs: 1,
|
|
|
127
|
outputs: 7,
|
|
|
128
|
icon: "font-awesome/fa-eye",
|
|
|
129
|
label: function() {
|
|
|
130
|
return this.name || "zg-204zv-homekit-adapter";
|
|
|
131
|
},
|
|
|
132
|
paletteLabel: "zg-204zv-homekit-adapter"
|
|
|
133
|
});
|
|
|
134
|
</script>
|