-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShelly pro 4PM - Buttons
More file actions
36 lines (29 loc) · 1.17 KB
/
Copy pathShelly pro 4PM - Buttons
File metadata and controls
36 lines (29 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// === Shelly Pro 4PM Input Event Publisher ===
// Publishes all 4 input events to MQTT without controlling switches
// Inputs are in detached mode - they only publish events to MQTT
// --- Get MQTT topic prefix ---
var mqttPrefix = Shelly.getComponentConfig("mqtt").topic_prefix;
// --- Configure all 4 inputs as detached (no switch control) ---
for (var i = 0; i <= 3; i++) {
Shelly.call("Input.SetConfig", {
id: i,
config: { type: "button" }
});
}
// --- Publish input event to MQTT ---
function publishInputEvent(btnID, eventInfo) {
var inputStatus = Shelly.getComponentStatus("input:" + btnID);
// Add the event to the status
inputStatus.event = eventInfo.event;
MQTT.publish(mqttPrefix + "/status/input:" + btnID, JSON.stringify(inputStatus), 0, false);
print("Input", btnID, "event:", eventInfo.event);
}
// --- Event Handler for all 4 inputs ---
Shelly.addEventHandler(function (e) {
if (e.component.indexOf("input:") === 0) {
var btnID = parseInt(e.component.split(":")[1]);
// Publish the event to MQTT for all inputs (0-3)
publishInputEvent(btnID, e.info);
}
});
print("Pro 4PM Input Publisher initialized - monitoring inputs 0-3");