@avantics/node-red-home-automation 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +340 -70
- package/contract-examples/room-lighting.mjs +39 -27
- package/dist/lib/activity-lighting-controller.d.ts +7 -2
- package/dist/lib/activity-lighting-controller.js +75 -16
- package/dist/lib/avr-controller.d.ts +2 -2
- package/dist/lib/avr-controller.js +21 -26
- package/dist/lib/circadian-policy.d.ts +47 -0
- package/dist/lib/circadian-policy.js +111 -0
- package/dist/lib/circadian-publishing.d.ts +33 -0
- package/dist/lib/circadian-publishing.js +154 -0
- package/dist/lib/circadian-schedule.d.ts +4 -0
- package/dist/lib/circadian-schedule.js +12 -0
- package/dist/lib/command-echo.d.ts +8 -1
- package/dist/lib/command-echo.js +37 -6
- package/dist/lib/cover-controller.js +4 -0
- package/dist/lib/denon-protocol.js +3 -2
- package/dist/lib/enable-input.d.ts +3 -0
- package/dist/lib/enable-input.js +18 -0
- package/dist/lib/house-schedule.js +2 -2
- package/dist/lib/light-contract.d.ts +53 -0
- package/dist/lib/light-contract.js +11 -0
- package/dist/lib/motion-policy.d.ts +0 -1
- package/dist/lib/motion-policy.js +9 -8
- package/dist/lib/motion-publishing.js +2 -1
- package/dist/lib/mqtt-message.d.ts +6 -0
- package/dist/lib/mqtt-message.js +21 -0
- package/dist/lib/room-controller.d.ts +38 -27
- package/dist/lib/room-controller.js +310 -204
- package/dist/lib/room-lighting-discovery.d.ts +0 -14
- package/dist/lib/room-lighting-discovery.js +19 -125
- package/dist/lib/room-publishing.d.ts +7 -12
- package/dist/lib/room-publishing.js +65 -125
- package/dist/lib/shelly-cover.d.ts +2 -4
- package/dist/lib/shelly-cover.js +30 -70
- package/dist/lib/shelly-gen2.d.ts +25 -0
- package/dist/lib/shelly-gen2.js +58 -0
- package/dist/lib/shelly-switch.d.ts +95 -0
- package/dist/lib/shelly-switch.js +237 -0
- package/dist/lib/theatre-state-contract.js +12 -4
- package/dist/lib/z2m-cover.d.ts +49 -0
- package/dist/lib/z2m-cover.js +120 -0
- package/dist/lib/z2m-light-adapter.d.ts +62 -0
- package/dist/lib/z2m-light-adapter.js +195 -0
- package/dist/lib/z2m-light.d.ts +2 -2
- package/dist/lib/z2m-light.js +11 -14
- package/dist/nodes/activity-lighting-controller.html +14 -5
- package/dist/nodes/activity-lighting-controller.js +21 -0
- package/dist/nodes/avr-controller.html +15 -18
- package/dist/nodes/avr-controller.js +4 -4
- package/dist/nodes/circadian-policy.d.ts +3 -0
- package/dist/nodes/circadian-policy.html +140 -0
- package/dist/nodes/circadian-policy.js +162 -0
- package/dist/nodes/cover-controller.html +4 -3
- package/dist/nodes/display-mode-controller.html +14 -17
- package/dist/nodes/display-mode-controller.js +4 -1
- package/dist/nodes/house-schedule.html +3 -3
- package/dist/nodes/motion-policy.html +5 -2
- package/dist/nodes/motion-policy.js +3 -0
- package/dist/nodes/refused-enable.d.ts +7 -0
- package/dist/nodes/refused-enable.js +24 -0
- package/dist/nodes/room-controller.html +215 -82
- package/dist/nodes/room-controller.js +70 -96
- package/dist/nodes/shelly-switch.d.ts +3 -0
- package/dist/nodes/shelly-switch.html +82 -0
- package/dist/nodes/shelly-switch.js +48 -0
- package/dist/nodes/theatre-state-contract.html +4 -3
- package/dist/nodes/z2m-cover.d.ts +3 -0
- package/dist/nodes/z2m-cover.html +68 -0
- package/dist/nodes/z2m-cover.js +41 -0
- package/dist/nodes/z2m-light.d.ts +3 -0
- package/dist/nodes/z2m-light.html +72 -0
- package/dist/nodes/z2m-light.js +50 -0
- package/examples/Cover control.json +24 -56
- package/examples/Home theatre activity.json +49 -4
- package/examples/House schedule.json +106 -24
- package/examples/Room lighting.json +54 -11
- package/examples/Shelly switch.json +197 -0
- package/package.json +12 -4
- package/dist/lib/room-schedule.d.ts +0 -8
- package/dist/lib/room-schedule.js +0 -41
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
(function () {
|
|
3
|
+
function clockTime(v) { return /^([01]\d|2[0-3]):[0-5]\d$/.test(String(v || "")); }
|
|
4
|
+
RED.nodes.registerType("home-circadian-lighting-policy", {
|
|
5
|
+
category: "home automation",
|
|
6
|
+
color: "#ffd27f",
|
|
7
|
+
defaults: {
|
|
8
|
+
name: {value: ""},
|
|
9
|
+
// Required only when the node publishes, and then with a letter or
|
|
10
|
+
// digit, from which its topics are made.
|
|
11
|
+
area: {value: "", validate: function (v) {
|
|
12
|
+
var publishing = $("#node-input-publishState").length
|
|
13
|
+
? $("#node-input-publishState").prop("checked") || $("#node-input-discovery").prop("checked")
|
|
14
|
+
: this.publishState === true || this.discovery === true;
|
|
15
|
+
return !publishing || /[a-z0-9]/i.test(String(v || ""));
|
|
16
|
+
}},
|
|
17
|
+
// The house schedule it follows; none: its own wake and bed times.
|
|
18
|
+
houseSchedule: {value: "", type: "home-house-schedule", required: false},
|
|
19
|
+
wakeTime: {value: "07:00", validate: function (v) { return Boolean(this.houseSchedule) || clockTime(v); }},
|
|
20
|
+
bedTime: {value: "23:00", validate: function (v) { return Boolean(this.houseSchedule) || clockTime(v); }},
|
|
21
|
+
maxBrightnessPct: {value: 100, required: true, validate: RED.validators.number()},
|
|
22
|
+
maxColorTempKelvin: {value: 6500, required: true, validate: RED.validators.number()},
|
|
23
|
+
sleepBrightnessPct: {value: 1, required: true, validate: RED.validators.number()},
|
|
24
|
+
sleepColorTempKelvin: {value: 2200, required: true, validate: RED.validators.number()},
|
|
25
|
+
refreshTransitionSeconds: {value: 60, required: true, validate: RED.validators.number()},
|
|
26
|
+
refreshSeconds: {value: 60, required: true, validate: function (v) { return RED.validators.number()(v) && Number(v) >= 10; }},
|
|
27
|
+
initialSleep: {value: false},
|
|
28
|
+
publishState: {value: false},
|
|
29
|
+
discovery: {value: false},
|
|
30
|
+
discoveryPrefix: {value: "homeassistant", required: true, validate: function (v) { var prefix = String(v || "").trim().replace(/^\/+|\/+$/g, ""); return Boolean(prefix) && !/[+#]/.test(prefix); }},
|
|
31
|
+
// A new node, so its Home Assistant entities are named after it.
|
|
32
|
+
idScheme: {value: "node"}
|
|
33
|
+
},
|
|
34
|
+
oneditprepare: function () {
|
|
35
|
+
// Discovery describes the published state, so it needs it.
|
|
36
|
+
function follow() {
|
|
37
|
+
var publishing = $("#node-input-publishState").prop("checked");
|
|
38
|
+
if (!publishing) $("#node-input-discovery").prop("checked", false);
|
|
39
|
+
$("#node-input-discovery").prop("disabled", !publishing);
|
|
40
|
+
$("#node-input-area").trigger("change");
|
|
41
|
+
}
|
|
42
|
+
$("#node-input-publishState, #node-input-discovery").on("change", follow);
|
|
43
|
+
follow();
|
|
44
|
+
// Following a house, the times are the house's.
|
|
45
|
+
function times() {
|
|
46
|
+
var own = !$("#node-input-houseSchedule").val() || $("#node-input-houseSchedule").val() === "_ADD_";
|
|
47
|
+
$(".circadian-own-times").toggle(own);
|
|
48
|
+
}
|
|
49
|
+
$("#node-input-houseSchedule").on("change", times);
|
|
50
|
+
times();
|
|
51
|
+
},
|
|
52
|
+
inputs: 1,
|
|
53
|
+
outputs: 2,
|
|
54
|
+
outputLabels: ["style, to room lighting controllers", "publications (MQTT out)"],
|
|
55
|
+
icon: "font-awesome/fa-sun-o",
|
|
56
|
+
label: function () { return this.name || (this.area ? this.area + " " : "") + "circadian lighting"; }
|
|
57
|
+
});
|
|
58
|
+
})();
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<script type="text/html" data-template-name="home-circadian-lighting-policy">
|
|
62
|
+
<div class="form-row"><label for="node-input-name">Name</label><input type="text" id="node-input-name"></div>
|
|
63
|
+
<div class="form-row"><label for="node-input-houseSchedule">Schedule</label><input type="text" id="node-input-houseSchedule"></div>
|
|
64
|
+
<div class="form-row circadian-own-times"><label for="node-input-wakeTime">Wake time</label><input type="text" id="node-input-wakeTime" placeholder="07:00"></div>
|
|
65
|
+
<div class="form-row circadian-own-times"><label for="node-input-bedTime">Bed time</label><input type="text" id="node-input-bedTime" placeholder="23:00"></div>
|
|
66
|
+
<div class="form-row"><label for="node-input-maxBrightnessPct">Daytime brightness %</label><input type="number" id="node-input-maxBrightnessPct"></div>
|
|
67
|
+
<div class="form-row"><label for="node-input-maxColorTempKelvin">Daytime kelvin</label><input type="number" id="node-input-maxColorTempKelvin"></div>
|
|
68
|
+
<div class="form-row"><label for="node-input-sleepBrightnessPct">Sleep brightness %</label><input type="number" id="node-input-sleepBrightnessPct"></div>
|
|
69
|
+
<div class="form-row"><label for="node-input-sleepColorTempKelvin">Sleep kelvin</label><input type="number" id="node-input-sleepColorTempKelvin"></div>
|
|
70
|
+
<div class="form-row"><label for="node-input-refreshTransitionSeconds">Restyle transition (s)</label><input type="number" id="node-input-refreshTransitionSeconds"></div>
|
|
71
|
+
<div class="form-row"><label for="node-input-refreshSeconds">Restyle interval (s)</label><input type="number" min="10" id="node-input-refreshSeconds"></div>
|
|
72
|
+
<div class="form-row"><label for="node-input-initialSleep">Start in sleep mode</label><input type="checkbox" id="node-input-initialSleep" style="display:inline-block; width:auto;"></div>
|
|
73
|
+
<div class="form-row"><label for="node-input-area">Area</label><input type="text" id="node-input-area" placeholder="needed when publishing"></div>
|
|
74
|
+
<div class="form-row"><label for="node-input-publishState">Publish state over MQTT</label><input type="checkbox" id="node-input-publishState" style="display:inline-block; width:auto;"></div>
|
|
75
|
+
<div class="form-row"><label for="node-input-discovery">Home Assistant discovery</label><input type="checkbox" id="node-input-discovery" style="display:inline-block; width:auto;"> <span>(needs Publish state)</span></div>
|
|
76
|
+
<div class="form-row"><label for="node-input-discoveryPrefix">Discovery prefix</label><input type="text" id="node-input-discoveryPrefix"></div>
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<script type="text/html" data-help-name="home-circadian-lighting-policy">
|
|
80
|
+
<p>Works out how lights should look over the day and sends it to room lighting controllers as a <i>style</i>: a
|
|
81
|
+
brightness and colour temperature for lights that nobody has set otherwise. Wire its first output to one or more
|
|
82
|
+
room lighting controllers. A room without it styles nothing: its lights just go on and off.</p>
|
|
83
|
+
<p>The lights rise to the daytime level over the hour after waking, stay there through the day, and wind down to
|
|
84
|
+
the sleep levels over the three hours before bed. Sleep mode holds the sleep levels whatever the time. Times are
|
|
85
|
+
the Node-RED host's local time.</p>
|
|
86
|
+
<h3>What a room does with a style</h3>
|
|
87
|
+
<p>A style is not a request to change a light: it never switches one on or off, and never reaches a light that an
|
|
88
|
+
owner (such as an activity) holds or a person set. A room uses it when a light it controls comes on with no values
|
|
89
|
+
given (motion, a wall-switch press), on each new style for lights that are on, after someone else's bare ON, and
|
|
90
|
+
when an owner releases a light. Switching circadian lighting on is the one exception: it takes back the lights a
|
|
91
|
+
person set, even when it is already on, so a flow can send it to bring lights back into step.</p>
|
|
92
|
+
<p>It sends a style once the flows start, every <b>Restyle interval</b>, at its startup message, and at once when
|
|
93
|
+
circadian lighting, sleep or the times change. Each style lasts three intervals: if the policy stops (deleted,
|
|
94
|
+
disabled, or its flow stopped), rooms stop styling soon after. Deleted with a modified deploy, it tells rooms at
|
|
95
|
+
once. While circadian lighting is off it sends a style with no values, and rooms style nothing.</p>
|
|
96
|
+
<h3>Inputs</h3>
|
|
97
|
+
<dl class="message-properties">
|
|
98
|
+
<dt>lighting.kind = "circadian" or "sleep"</dt>
|
|
99
|
+
<dd><code>lighting.enabled</code> <code>true</code> or <code>false</code> switches circadian lighting or sleep. Any
|
|
100
|
+
other value, such as <code>"on"</code>, is refused: nothing changes, and the node logs a warning once per deploy
|
|
101
|
+
and shows it on its status.</dd>
|
|
102
|
+
<dt>lighting.kind = "schedule"</dt>
|
|
103
|
+
<dd><code>lighting.wakeTime</code> and <code>lighting.bedTime</code>, <code>"HH:MM"</code>, either alone. A time set
|
|
104
|
+
this way lasts until the node is deployed with a different setting for it.</dd>
|
|
105
|
+
<dt>lighting.kind = "startup"</dt>
|
|
106
|
+
<dd>Sends the style, and with publishing on, its availability, state and discovery. Send it a few seconds after
|
|
107
|
+
the flows start, as the examples do.</dd>
|
|
108
|
+
<dt>topic = home/<area>/circadian/set, home/<area>/sleep/set</dt>
|
|
109
|
+
<dd><code>ON</code> or <code>OFF</code> from Home Assistant, as <code>lighting.kind = "circadian"</code> or
|
|
110
|
+
<code>"sleep"</code> does. Read only while <b>Publish state</b> is on. Retained messages and other payloads are
|
|
111
|
+
ignored.</dd>
|
|
112
|
+
<dt>topic = home/<area>/wake-time/set or bed-time/set</dt>
|
|
113
|
+
<dd>A time from Home Assistant, with its own times only.</dd>
|
|
114
|
+
</dl>
|
|
115
|
+
<h3>Outputs</h3>
|
|
116
|
+
<ol class="node-ports">
|
|
117
|
+
<li>Style, to room lighting controllers: <code>msg.lighting = {kind: "style", source: "circadian", values:
|
|
118
|
+
{brightnessPct, colorTempKelvin} | null, transitionSeconds, until, takeBack?}</code>.</li>
|
|
119
|
+
<li>Publications, to an MQTT out node with no topic set: availability on
|
|
120
|
+
<code>home/<area>/circadian/availability</code>, the circadian and sleep state on
|
|
121
|
+
<code>home/<area>/circadian/state</code> and <code>home/<area>/sleep/state</code>, its own wake and
|
|
122
|
+
bed times on <code>home/<area>/wake-time/state</code> and <code>…/bed-time/state</code>, and discovery.</li>
|
|
123
|
+
</ol>
|
|
124
|
+
<h3>Settings</h3>
|
|
125
|
+
<dl class="message-properties">
|
|
126
|
+
<dt>Schedule</dt><dd>A house schedule, so several rooms share one wake and bed time; none uses its own
|
|
127
|
+
<b>Wake time</b> and <b>Bed time</b>. Following a house, it has no time entities of its own: the house schedule
|
|
128
|
+
MQTT node offers them.</dd>
|
|
129
|
+
<dt>Daytime and sleep brightness and kelvin</dt><dd>The levels at full day and in sleep.</dd>
|
|
130
|
+
<dt>Restyle transition</dt><dd>How long a room takes to move a light that is on to a new style. A light turning
|
|
131
|
+
on uses the room's own transition.</dd>
|
|
132
|
+
<dt>Restyle interval</dt><dd>How often it sends its style, at least 10 seconds.</dd>
|
|
133
|
+
<dt>Publish state over MQTT, Home Assistant discovery</dt><dd>Off unless switched on. With both on, Home Assistant
|
|
134
|
+
shows Circadian lighting and Sleep switches and, with its own times, Wake time and Bed time, named after this
|
|
135
|
+
node. The topics keep the names the room controller used before 6.0, so a flow already writing
|
|
136
|
+
<code>home/<area>/circadian/set</code> keeps working when this node has that area. Before announcing, it
|
|
137
|
+
clears the circadian entities older room controllers in its area published, migrated or not, in the same batch,
|
|
138
|
+
so Home Assistant can give the new ones the same entity IDs.</dd>
|
|
139
|
+
</dl>
|
|
140
|
+
</script>
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const circadian_1 = require("../lib/circadian");
|
|
3
|
+
const circadian_policy_1 = require("../lib/circadian-policy");
|
|
4
|
+
const circadian_publishing_1 = require("../lib/circadian-publishing");
|
|
5
|
+
const circadian_schedule_1 = require("../lib/circadian-schedule");
|
|
6
|
+
const ha_discovery_1 = require("../lib/ha-discovery");
|
|
7
|
+
const publishing_node_1 = require("../lib/publishing-node");
|
|
8
|
+
const settings_1 = require("../lib/settings");
|
|
9
|
+
const topic_names_1 = require("../lib/topic-names");
|
|
10
|
+
const adapter_1 = require("./adapter");
|
|
11
|
+
const publishing_lifecycle_1 = require("./publishing-lifecycle");
|
|
12
|
+
const refused_enable_1 = require("./refused-enable");
|
|
13
|
+
const shared_schedule_1 = require("./shared-schedule");
|
|
14
|
+
const registerCircadianPolicy = (RED) => {
|
|
15
|
+
function HomeCircadianLightingPolicy(config) {
|
|
16
|
+
RED.nodes.createNode(this, config);
|
|
17
|
+
const node = this;
|
|
18
|
+
const context = node.context();
|
|
19
|
+
let tickTimer;
|
|
20
|
+
// A schedule that is set but not running, as when it was deleted: the
|
|
21
|
+
// policy keeps to its own times and says so.
|
|
22
|
+
const { schedule: house, missing: houseMissing } = (0, shared_schedule_1.referencedSchedule)(RED, config.houseSchedule);
|
|
23
|
+
let policyConfig;
|
|
24
|
+
let publishing;
|
|
25
|
+
try {
|
|
26
|
+
const area = (0, adapter_1.optionalArea)(config);
|
|
27
|
+
const levels = {
|
|
28
|
+
maxBrightnessPct: (0, settings_1.numberSetting)(config.maxBrightnessPct, "daytime brightness", 100),
|
|
29
|
+
maxColorTempKelvin: (0, settings_1.numberSetting)(config.maxColorTempKelvin, "daytime colour temperature", 6500),
|
|
30
|
+
sleepBrightnessPct: (0, settings_1.numberSetting)(config.sleepBrightnessPct, "sleep brightness", 1),
|
|
31
|
+
sleepColorTempKelvin: (0, settings_1.numberSetting)(config.sleepColorTempKelvin, "sleep colour temperature", 2200)
|
|
32
|
+
};
|
|
33
|
+
const schedule = house
|
|
34
|
+
? house.schedule()
|
|
35
|
+
: (0, circadian_schedule_1.resolveSchedule)((0, settings_1.textSetting)(config.wakeTime, "wake time", "07:00"), (0, settings_1.textSetting)(config.bedTime, "bed time", "23:00"));
|
|
36
|
+
policyConfig = {
|
|
37
|
+
lighting: (0, circadian_1.scheduledLighting)(schedule, levels),
|
|
38
|
+
schedule,
|
|
39
|
+
timesFrom: house ? "house" : "own",
|
|
40
|
+
initialSleep: (0, settings_1.booleanSetting)(config.initialSleep, "initial sleep", false),
|
|
41
|
+
transitionSeconds: (0, settings_1.numberSetting)(config.refreshTransitionSeconds, "restyle transition", 60),
|
|
42
|
+
intervalSeconds: Math.max(10, (0, settings_1.numberSetting)(config.refreshSeconds, "restyle interval", 60))
|
|
43
|
+
};
|
|
44
|
+
// Off unless switched on; a new node, so its entities are named after
|
|
45
|
+
// it.
|
|
46
|
+
const publishState = (0, settings_1.optionalBooleanSetting)(config.publishState, "publish state") ?? false;
|
|
47
|
+
const discovery = (0, settings_1.optionalBooleanSetting)(config.discovery, "Home Assistant discovery") ?? false;
|
|
48
|
+
if (publishState || discovery)
|
|
49
|
+
(0, topic_names_1.publishingArea)(area, true);
|
|
50
|
+
publishing = {
|
|
51
|
+
area,
|
|
52
|
+
publishState,
|
|
53
|
+
discovery,
|
|
54
|
+
discoveryPrefix: (0, ha_discovery_1.discoveryPrefixSetting)(config.discoveryPrefix),
|
|
55
|
+
nodeId: node.id,
|
|
56
|
+
// Always named after the node, so its entries never share a topic
|
|
57
|
+
// with the area-named ones older rooms published, which it clears.
|
|
58
|
+
idScheme: "node",
|
|
59
|
+
timesFrom: policyConfig.timesFrom
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
(0, adapter_1.invalidConfig)(node, error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
function savedState() {
|
|
67
|
+
return (0, circadian_policy_1.createCircadianState)(policyConfig, context.get("state"));
|
|
68
|
+
}
|
|
69
|
+
// The room controllers in the flows with this area, migrated or not:
|
|
70
|
+
// their old circadian entries named after them are cleared with this
|
|
71
|
+
// node's own (see circadianStartingOutputs).
|
|
72
|
+
function roomsInArea() {
|
|
73
|
+
const ids = [];
|
|
74
|
+
RED.nodes.eachNode((entry) => {
|
|
75
|
+
const room = entry;
|
|
76
|
+
if (room.type === "home-room-lighting-controller" && typeof room.area === "string" && publishing.area !== "" &&
|
|
77
|
+
(0, topic_names_1.areaId)(room.area) === (0, topic_names_1.areaId)(publishing.area))
|
|
78
|
+
ids.push(room.id);
|
|
79
|
+
});
|
|
80
|
+
return ids;
|
|
81
|
+
}
|
|
82
|
+
// Styles go to rooms on the first output; MQTT publications on the
|
|
83
|
+
// second.
|
|
84
|
+
const lifecycle = (0, publishing_lifecycle_1.publishingLifecycle)(RED, node, {
|
|
85
|
+
retainedTopics: () => (0, circadian_publishing_1.circadianRetainedTopics)(publishing),
|
|
86
|
+
possible: { owner: publishing, topics: () => (0, publishing_node_1.publishesState)(publishing) ? (0, circadian_publishing_1.circadianRetainedTopics)({ ...publishing, publishState: true, discovery: true }) : [] },
|
|
87
|
+
starting: () => (0, circadian_publishing_1.circadianStartingOutputs)(publishing, savedState(), roomsInArea()),
|
|
88
|
+
stopping: () => (0, circadian_publishing_1.circadianStoppingOutputs)(publishing),
|
|
89
|
+
output: 1,
|
|
90
|
+
outputs: 2
|
|
91
|
+
});
|
|
92
|
+
function updateStatus(status) {
|
|
93
|
+
const values = status.values;
|
|
94
|
+
node.status(values
|
|
95
|
+
? { fill: "green", shape: "dot", text: (status.sleeping ? "sleep" : "day") + " · " +
|
|
96
|
+
Math.round(values.brightnessPct) + "% " + Math.round(values.colorTempKelvin) + "K" +
|
|
97
|
+
(houseMissing ? " · schedule missing: own times" : "") }
|
|
98
|
+
: { fill: "grey", shape: "dot", text: "off" + (houseMissing ? " · schedule missing: own times" : "") });
|
|
99
|
+
}
|
|
100
|
+
const showRefused = (0, refused_enable_1.refusedEnables)(node, (source) => `${source}'s enabled`);
|
|
101
|
+
function process(event, send, inboundTraces = [], fromSetTopic = false) {
|
|
102
|
+
const result = (0, adapter_1.runReducer)(node, { area: publishing.area, component: "circadian-policy" }, (saved, now) => {
|
|
103
|
+
const decided = (0, circadian_policy_1.transitionCircadian)(saved, event, policyConfig, now);
|
|
104
|
+
return { ...decided, traces: [...inboundTraces, ...decided.traces] };
|
|
105
|
+
});
|
|
106
|
+
if (result.style)
|
|
107
|
+
send([{ payload: undefined, lighting: result.style }, null]);
|
|
108
|
+
// Published whenever it changes, and in answer to a set, so Home
|
|
109
|
+
// Assistant shows what is in use.
|
|
110
|
+
if (result.stateChanged || fromSetTopic)
|
|
111
|
+
lifecycle.publish(send, (0, circadian_publishing_1.circadianStateOutputs)(publishing, result.state));
|
|
112
|
+
updateStatus(result.status);
|
|
113
|
+
showRefused(result.traces);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
// Once the flows have started: the house's times (this node may have
|
|
117
|
+
// restarted alone) and the style. Its publications go out then too, from
|
|
118
|
+
// the lifecycle.
|
|
119
|
+
(0, adapter_1.whenFlowsStarted)(RED, node, (0, adapter_1.guarded)(node, () => {
|
|
120
|
+
const send = node.send.bind(node);
|
|
121
|
+
if (house)
|
|
122
|
+
process({ kind: "schedule", ...house.schedule() }, send);
|
|
123
|
+
process({ kind: "tick" }, send);
|
|
124
|
+
}));
|
|
125
|
+
if (house) {
|
|
126
|
+
node.on("close", house.subscribe((0, adapter_1.guarded)(node, () => {
|
|
127
|
+
process({ kind: "schedule", ...house.schedule() }, node.send.bind(node));
|
|
128
|
+
})));
|
|
129
|
+
}
|
|
130
|
+
(0, adapter_1.onInput)(node, (msg, send) => {
|
|
131
|
+
const lighting = (0, adapter_1.objectField)(msg, "lighting");
|
|
132
|
+
if (lighting?.kind === "startup") {
|
|
133
|
+
lifecycle.startup(send, (0, circadian_publishing_1.circadianStartingOutputs)(publishing, savedState(), roomsInArea()));
|
|
134
|
+
process({ kind: "tick" }, send);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
// Home Assistant's set topics become the policy's own events; a flow
|
|
138
|
+
// sends the same shapes the room controller took before 6.0.
|
|
139
|
+
const inbound = (0, circadian_publishing_1.circadianInbound)(msg, publishing);
|
|
140
|
+
if (inbound) {
|
|
141
|
+
process(inbound.event, send, inbound.traces, true);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
process(lighting ?? { kind: undefined }, send);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
tickTimer = setInterval((0, adapter_1.guarded)(node, () => process({ kind: "tick" }, node.send.bind(node))), policyConfig.intervalSeconds * 1000);
|
|
148
|
+
// Deleted: rooms stop styling at once rather than when the last style
|
|
149
|
+
// runs out.
|
|
150
|
+
node.on("close", (removed, done) => {
|
|
151
|
+
clearInterval(tickTimer);
|
|
152
|
+
if ((0, adapter_1.wasDeleted)(RED, node, removed)) {
|
|
153
|
+
node.send([{ payload: undefined, lighting: { ...(0, circadian_policy_1.styleMessage)(policyConfig, savedState(), new Date()), values: null } }, null]);
|
|
154
|
+
}
|
|
155
|
+
done();
|
|
156
|
+
});
|
|
157
|
+
updateStatus((0, circadian_policy_1.transitionCircadian)(context.get("state"), { kind: "tick" }, policyConfig).status);
|
|
158
|
+
}
|
|
159
|
+
RED.nodes.registerType("home-circadian-lighting-policy", HomeCircadianLightingPolicy);
|
|
160
|
+
};
|
|
161
|
+
module.exports = registerCircadianPolicy;
|
|
162
|
+
//# sourceMappingURL=circadian-policy.js.map
|
|
@@ -137,8 +137,8 @@
|
|
|
137
137
|
<ol class="node-ports">
|
|
138
138
|
<li>Device commands, in a neutral shape: <code>msg.cover_command = {operation, position, requestId, generation,
|
|
139
139
|
attempt}</code>, where <code>operation</code> is <code>set_position</code>, <code>stop</code> or
|
|
140
|
-
<code>observe</code> (read the cover now).
|
|
141
|
-
|
|
140
|
+
<code>observe</code> (read the cover now). Wire them to a device adapter, such as the zigbee2mqtt cover or
|
|
141
|
+
shelly cover node, as the example flows do.</li>
|
|
142
142
|
<li>State and results: <code>msg.theatre = {kind: "target_state", target: "cover", status, details}</code>, with
|
|
143
143
|
the confirmed and observed positions and any failure or manual override.</li>
|
|
144
144
|
<li>Whether the cover is moving, <code>msg.payload</code> <code>true</code> or <code>false</code> with
|
|
@@ -159,7 +159,8 @@
|
|
|
159
159
|
<code>…/set</code>, and a position on <code>…/position/set</code>, as requests like any other, carried out and
|
|
160
160
|
confirmed as above; wire an MQTT in node on <code>home/<area>/cover/<name>/+</code> (and
|
|
161
161
|
<code>…/position/set</code>) into this node. Nothing commands the device through Home Assistant. With
|
|
162
|
-
<b>Home Assistant discovery</b>, a cover entity
|
|
162
|
+
<b>Home Assistant discovery</b>, a cover entity named by <b>Name in topics</b>, with open, close and stop, and
|
|
163
|
+
for a position cover also its position and set position.</p>
|
|
163
164
|
<h3>Open, close and stop only</h3>
|
|
164
165
|
<p>For a motor with no reliable position, set <b>Cover</b> to <i>Open, close and stop only</i>. It takes
|
|
165
166
|
<code>"open"</code>, <code>"close"</code> and <code>"stop"</code> (positions and presets are ignored), and sends
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
area: {value: ""},
|
|
8
8
|
tvHost: {value: "", required: true},
|
|
9
9
|
screenHost: {value: "", required: true},
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
projectorPowerMeterHost: {value: ""
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//
|
|
10
|
+
// Optional: without one, the flow reports the projector's power. A node
|
|
11
|
+
// still naming only the old key is invalid until this is set.
|
|
12
|
+
projectorPowerMeterHost: {value: "", validate: function (v) {
|
|
13
|
+
return String(v || "").trim() !== "" || String(this.projectorMeterHost || "").trim() === "";
|
|
14
|
+
}},
|
|
15
|
+
// The name before 5.0, removed in 6.0 but kept here, with no form row,
|
|
16
|
+
// so the editor carries it: dropped, a deploy from the editor would
|
|
17
|
+
// quietly switch the node to having no built-in meter. With it, the
|
|
18
|
+
// node stays an invalid configuration until the new host is set.
|
|
16
19
|
projectorMeterHost: {value: ""},
|
|
17
20
|
// Empty: the screen's own open command. No shared default position: a
|
|
18
21
|
// node saved with one keeps it.
|
|
@@ -37,16 +40,9 @@
|
|
|
37
40
|
transportTimeoutMs: {value: 5000, required: true, validate: RED.validators.number()}
|
|
38
41
|
},
|
|
39
42
|
credentials: {tvPsk: {type: "password"}},
|
|
40
|
-
|
|
41
|
-
// A flow saved before 5.0: show its meter host, so saving the dialog keeps it.
|
|
42
|
-
if (!this.projectorPowerMeterHost && this.projectorMeterHost) {
|
|
43
|
-
$("#node-input-projectorPowerMeterHost").val(this.projectorMeterHost);
|
|
44
|
-
}
|
|
45
|
-
},
|
|
43
|
+
// Once the new host is set, the removed name goes.
|
|
46
44
|
oneditsave: function () {
|
|
47
|
-
|
|
48
|
-
// the user's choice, including none.
|
|
49
|
-
this.projectorMeterHost = "";
|
|
45
|
+
if (String($("#node-input-projectorPowerMeterHost").val() || "").trim() !== "") this.projectorMeterHost = "";
|
|
50
46
|
},
|
|
51
47
|
inputs: 1,
|
|
52
48
|
outputs: 3,
|
|
@@ -97,8 +93,9 @@
|
|
|
97
93
|
that knows where it is: one that doesn't is closed first, and if it still has no position (not calibrated), the
|
|
98
94
|
request fails with reason <code>screen-not-calibrated</code>; calibrate it, or clear the viewing position. The
|
|
99
95
|
<b>Projector power meter host</b>, if set, is a Shelly Gen2 switch with power metering on the projector's supply
|
|
100
|
-
(switch 1), read against <b>Projector on watts</b> and <b>Projector standby watts</b>. A
|
|
101
|
-
that host <code>projectorMeterHost</code>,
|
|
96
|
+
(switch 1), read against <b>Projector on watts</b> and <b>Projector standby watts</b>. A node still naming
|
|
97
|
+
that host <code>projectorMeterHost</code>, as before 5.0, is an invalid configuration, in the editor and when
|
|
98
|
+
deployed: that name was removed in 6.0, so set <b>Projector power meter host</b>.</p>
|
|
102
99
|
<p>Output 1 carries the projector power toggle (<code>msg.payload = "power"</code> with <code>msg.display_command</code>) for your infrared transport, commanded directly rather than through Home Assistant. Enable “Projector power is fallback” to include its use in activity metrics. Output 2 emits observed state plus ready, manual-override, failed, rejected and superseded results, and <code>msg.theatre</code> target state for the theatre activity controller: wire it straight back to that controller. Output 3 asks for the projector's power when there is no meter host (below).</p>
|
|
103
100
|
<h3>Projector power from your own flow</h3>
|
|
104
101
|
<p>Leave <b>Projector power meter host</b> empty to report the projector's power from any meter or adapter: send
|
|
@@ -17,7 +17,10 @@ const registerDisplayModeController = (RED) => {
|
|
|
17
17
|
controllerConfig = (0, display_mode_controller_1.normaliseConfig)(config);
|
|
18
18
|
// Optional: without a meter of its own, the node asks the flow for the
|
|
19
19
|
// projector's power on its third output, and reads what comes back.
|
|
20
|
-
projectorPowerMeterHost = String(config.projectorPowerMeterHost ?? "").trim()
|
|
20
|
+
projectorPowerMeterHost = String(config.projectorPowerMeterHost ?? "").trim();
|
|
21
|
+
if (!projectorPowerMeterHost && String(config.projectorMeterHost ?? "").trim()) {
|
|
22
|
+
throw new Error("projectorMeterHost was removed in 6.0: set Projector power meter host");
|
|
23
|
+
}
|
|
21
24
|
transport = new display_transport_1.DisplayTransport({
|
|
22
25
|
// No defaults: these name the user's own devices.
|
|
23
26
|
tvHost: (0, settings_1.textSetting)(config.tvHost, "TV host"),
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
24
|
<script type="text/html" data-help-name="home-house-schedule">
|
|
25
|
-
<p>One wake and bed time shared by every
|
|
26
|
-
|
|
27
|
-
<p>The
|
|
25
|
+
<p>One wake and bed time shared by every circadian lighting policy whose <b>Schedule</b> is this one. A policy
|
|
26
|
+
that keeps its own times (for a child's room, say) chooses none.</p>
|
|
27
|
+
<p>The policies hear of every change as it happens, without wires. Times change from a message or from Home Assistant
|
|
28
28
|
through a <i>house schedule MQTT</i> node; a time changed that way lasts until this schedule is deployed with a
|
|
29
29
|
different <b>Wake time</b> or <b>Bed time</b>, which then applies.</p>
|
|
30
30
|
<p>The <b>Name</b> labels it and names its topics, <code>home/<name>/schedule/...</code>.</p>
|
|
@@ -81,14 +81,17 @@
|
|
|
81
81
|
<dl class="message-properties">
|
|
82
82
|
<dt>occupancy</dt><dd><code>msg.payload.occupied</code>, from the occupancy fusion node.</dd>
|
|
83
83
|
<dt>illuminance</dt><dd>the light level in lux.</dd>
|
|
84
|
-
<dt>area-enabled</dt><dd>
|
|
84
|
+
<dt>area-enabled</dt><dd><code>true</code> or <code>false</code> for this node; <code>global-enabled</code> for every
|
|
85
|
+
motion node. Any other value, such as <code>"ON"</code> (accepted before 6.0), is refused: nothing changes, the
|
|
86
|
+
node logs a warning once per deploy and shows it on its status.</dd>
|
|
85
87
|
<dt>delay</dt><dd>a new vacancy time, in <b>seconds</b>, the same unit as <b>Vacancy seconds</b>.</dd>
|
|
86
88
|
<dt>illuminance-cut-off</dt><dd>a new lux cutoff.</dd>
|
|
87
89
|
<dt>pause</dt><dd><code>true</code> pauses motion lighting, <code>false</code> releases it, for the owner in
|
|
88
90
|
<code>msg.owner</code> (for example a cover's name), which is required. A pause lasts at most the
|
|
89
91
|
<b>Maximum pause</b> unless sent again, so a lost release can't stop motion lighting for good. Motion lighting acts only while no owner holds a pause,
|
|
90
92
|
and a pause cancels a pending vacancy timer, as switching it off does. A pause never changes the enables,
|
|
91
|
-
which are the user's own: wire a cover's <i>moving</i> output here to pause motion while it moves
|
|
93
|
+
which are the user's own: wire a cover's <i>moving</i> output here to pause motion while it moves. Any value but
|
|
94
|
+
<code>true</code> or <code>false</code> is refused, as for the enables.</dd>
|
|
92
95
|
</dl>
|
|
93
96
|
<p>A <code>delay</code> or <code>illuminance-cut-off</code> message overrides the setting, and lasts across
|
|
94
97
|
restarts until the node is deployed with a different <b>Vacancy seconds</b> or <b>Lux cutoff</b>, which then
|
|
@@ -7,6 +7,7 @@ const topic_names_1 = require("../lib/topic-names");
|
|
|
7
7
|
const adapter_1 = require("./adapter");
|
|
8
8
|
const publishing_node_1 = require("../lib/publishing-node");
|
|
9
9
|
const publishing_lifecycle_1 = require("./publishing-lifecycle");
|
|
10
|
+
const refused_enable_1 = require("./refused-enable");
|
|
10
11
|
const registerMotionPolicy = (RED) => {
|
|
11
12
|
function HomeMotionLightingPolicy(config) {
|
|
12
13
|
RED.nodes.createNode(this, config);
|
|
@@ -100,8 +101,10 @@ const registerMotionPolicy = (RED) => {
|
|
|
100
101
|
lifecycle.publish(send, (0, motion_publishing_1.motionStateOutputs)(publishing, result.state));
|
|
101
102
|
}
|
|
102
103
|
updateStatus(result.status);
|
|
104
|
+
showRefused(result.traces);
|
|
103
105
|
return result;
|
|
104
106
|
}
|
|
107
|
+
const showRefused = (0, refused_enable_1.refusedEnables)(node);
|
|
105
108
|
// With a configured context store (see the README) the node's state
|
|
106
109
|
// survives a redeploy or restart, but timers never do: a pending
|
|
107
110
|
// off-timer is re-armed. Without one, it starts with nothing saved, and
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refusedEnables = refusedEnables;
|
|
4
|
+
const enable_input_1 = require("../lib/enable-input");
|
|
5
|
+
// `named` gives the input's name as the warning says it, such as
|
|
6
|
+
// "circadian's enabled".
|
|
7
|
+
function refusedEnables(node, named = (source) => source) {
|
|
8
|
+
const warned = new Set();
|
|
9
|
+
// Shows the first refusal among these traces, if any; true when there was
|
|
10
|
+
// one, so the caller leaves the status as set.
|
|
11
|
+
return function show(traces) {
|
|
12
|
+
const refused = traces.find(({ reason }) => reason === enable_input_1.NOT_TRUE_OR_FALSE);
|
|
13
|
+
if (!refused)
|
|
14
|
+
return false;
|
|
15
|
+
const { source, payload } = refused.details;
|
|
16
|
+
if (!warned.has(source)) {
|
|
17
|
+
warned.add(source);
|
|
18
|
+
node.warn(`${named(source)} takes only true or false: ${payload} was refused, and nothing changed`);
|
|
19
|
+
}
|
|
20
|
+
node.status({ fill: "yellow", shape: "ring", text: `refused ${source} ${payload}: send true or false` });
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=refused-enable.js.map
|