0.0.5 • Published 5 months ago

node-red-contrib-multi-action-switch v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

node-red-contrib-multi-action-switch

Multi Action Switch is a custom Node-RED node for handling various button press events, including:

  • Single Click
  • Double Click
  • Triple Click
  • Long Press
  • Press & Release

It is designed for smart home systems and integrates well with MQTT, Home Assistant, and Apple HomeKit.

🛠 Installation

To install the node directly from Node-RED: 1. Open Node-RED. 2. Go to Manage PaletteInstall. 3. Search for "node-red-contrib-multi-action-switch". 4. Click Install.

Alternatively, you can install it manually using:

cd ~/.node-red
npm install node-red-contrib-multi-action-switch

Then restart Node-RED:

node-red-restart

🎛 Node Configuration

After installing, the Multi Action Switch node will be available in the "function" category.

🔧 Node Properties

PropertyTypeDefaultDescription
Trigger ValueString"true"The value that triggers the switch.
Double Click TimeNumber400 msThe maximum time window for a double click.
Long Press TimeNumber700 msThe minimum time required for a long press.
Toggle StateBooleanfalseWhether the node should manage on/off state.
Include TimestampBooleanfalseIf enabled, the node adds a timestamp to each event.
Output TopicString(optional)MQTT-style topic for event output. If left blank, the node will pass through the incoming message's topic (msg.topic).

🔄 How It Works

Event Handling

The node processes button inputs and generates output messages based on how the button is pressed. The supported events:

Event TypeDescription
pressTriggered immediately when the button is pressed.
releaseTriggered when the button is released.
singleclickSent after a single press and release.
doubleclickSent after two quick presses.
tripleclickSent after three quick presses.
longpressSent if the button is held longer than the configured Long Press Time.

Example Usage with MQTT

If Output Topic is set to "home/livingroom/switch", the node will send messages like:

{
  "topic": "home/livingroom/switch",
  "payload": {
    "eventType": "singleclick",
    "timestamp": 1700000000000
  }
}

🚀 Example Flows

Basic Usage

The following flow demonstrates how to connect a button input to a multi-action-switch node and print the output.

[
    {
        "id": "n1",
        "type": "multi-action-switch",
        "triggerValue": "true",
        "doubleClickTime": "400",
        "longPressTime": "700",
        "toggleState": false,
        "includeTimestamp": true,
        "outputTopic": "home/test",
        "wires": [["n2"]]
    },
    {
        "id": "n2",
        "type": "debug",
        "name": "Debug Output"
    }
]

Using with MQTT

If you're integrating this with Home Assistant via MQTT, you can set up an MQTT Out node with:

  • Topic: home/livingroom/switch
  • Payload: msg.payload

Then, Home Assistant can listen for events like "singleclick" or "longpress".


🔄 State Management

If Toggle State is enabled (toggleState: true), the node will remember its current state ("on" or "off"). The state will be included in singleclick events:

{
  "eventType": "singleclick",
  "state": "on",
  "timestamp": 1700000000000
}

The state toggles on each singleclick.


🛠 Troubleshooting

ProblemPossible Solution
The node is not responding to button pressesEnsure that the Trigger Value matches the expected input ("true", 1, etc.).
Double click or triple click events are not detectedIncrease the Double Click Time slightly to allow for slower clicking.
Long press fires too earlyIncrease the Long Press Time value.

📜 License

This project is licensed under the MIT License.


🔗 Links


✅ Summary

The Multi Action Switch node makes handling button presses in smart home systems easy. It supports multi-click events, long press detection, and state toggling. It is useful for integrating physical switches into Home Assistant, MQTT, and Apple HomeKit.

If you have any questions or need help, feel free to open an issue on GitHub! 🚀

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago