Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This function is for use in Node-Red within Home Assistant for the IKEA
- // Trafdri Shortcut Button (or similar device from other manufacturers). The
- // function can turn toggle a light (or group of lights) based on how the
- // button was pressed: single press, double press, or press and hold.
- // Usage: An Events: All node with an Event Type of zha_event is used to handle
- // the events. It is connected to a Switch node with a Property of
- // msg.payload.event.device_ieee. The outputs correspond to the device_ieee of
- // the remote being used. This allows for multiple remotes to use different
- // functions. The output is connected to this Function node. Multiple outputs
- // can be connected to this function. The output is connected to an empty
- // Service Call node.
- // The function requires an entities to be defined. A group defined in Home
- // Assistant can also be used to control multiple lights simultaneously. To
- // disable a specific button press, replace the entity name with double quotes
- // ("").
- var single_press_entity = "light.stove";
- var double_press_entity = "light.kitchen";
- var push_and_hold_entity = "group.kitchen";
- // Assign output variable based on how the button was pressed
- var output_entity = "";
- switch(msg.payload.event.command) {
- case "toggle":
- output_entity = single_press_entity;
- break;
- case "on":
- output_entity = double_press_entity;
- break;
- case "off":
- output_entity = push_and_hold_entity;
- break;
- }
- // Payload to be passed to service call node
- msg.payload = {domain: "light", service: "toggle",
- data: {
- entity_id: output_entity, }
- };
- return msg;
Add Comment
Please, Sign In to add comment