# Need help with huemagic

**URL:** <https://discourse.nodered.org/t/need-help-with-huemagic/87596>\
**Category:** General\
**Created:** [29 April 2024 20:11 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596 "2024-04-29T20:11:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aredhone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aredhone/32/90359_2.png) [@aredhone](https://discourse.nodered.org/u/aredhone)\
**Post date:** [29 April 2024 20:11 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/1 "2024-04-29T20:11:58Z")

</div>

so here i am again  
most posible asking you guys aa easy quistion  
i have trouble setting up somthing that recieves a singnal of my hue dot and do somthing with it i got

```auto
[{"id":"79f1f61985718e40","type":"debug","z":"d5d4a606.0f05","name":"Information","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload.action","targetType":"msg","statusVal":"payload","statusType":"auto","x":760,"y":140,"wires":[],"icon":"font-awesome/fa-info-circle"},{"id":"74f3cdad2b625d5c","type":"inject","z":"d5d4a606.0f05","name":"Status","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":true}","payloadType":"json","x":110,"y":160,"wires":[["664e68b0b62d7e4e"]],"icon":"node-red/alert.svg"},{"id":"664e68b0b62d7e4e","type":"hue-buttons","z":"d5d4a606.0f05","name":"Dot Light Switch Desk","bridge":"6465e98b22084718","sensorid":"455397cf-1fab-4eb6-98ae-05aaf4110dc1","skipevents":false,"initevents":true,"x":480,"y":160,"wires":[["7acc494c2cf71b83","79f1f61985718e40","b2ff50f06ff3cc76"]]},{"id":"b2ff50f06ff3cc76","type":"debug","z":"d5d4a606.0f05","name":"Information","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload.button","targetType":"msg","statusVal":"payload","statusType":"auto","x":760,"y":80,"wires":[],"icon":"font-awesome/fa-info-circle"},{"id":"25ca7b9c17693660","type":"switch","z":"d5d4a606.0f05","name":"","property":"payload.result","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":810,"y":200,"wires":[["dc80c78f8055effe"]]},{"id":"dc80c78f8055effe","type":"wled2","z":"d5d4a606.0f05","address":"192.168.1.190","brightness":128,"delay":0,"color1":"#ffffff","color2":"#ffffff","color3":"#ffffff","effect":0,"effectIntensity":128,"effectSpeed":128,"name":"","palette":"0","preset":0,"state":"toggle","x":950,"y":200,"wires":[[]]},{"id":"bcac79974de13aa4","type":"debug","z":"d5d4a606.0f05","name":"Information function","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"msg.payload.result","targetType":"msg","statusVal":"payload","statusType":"auto","x":780,"y":260,"wires":[],"icon":"font-awesome/fa-info-circle"},{"id":"7acc494c2cf71b83","type":"function","z":"d5d4a606.0f05","name":"function 1","func":"// Initialize a variable to track the state\ncontext.toggleState = context.toggleState || false;\n\n// Check if msg.payload.button is a number and msg.payload.action is a string with the specified value\nif (\n msg.payload &&\n typeof msg.payload.button === 'number' &&\n msg.payload.button === 3 &&\n typeof msg.payload.action === 'string' &&\n msg.payload.action === 'initial_press'\n) {\n // Toggle the state\n context.toggleState = !context.toggleState;\n}\n\n// Set msg.payload.result based on the state\nmsg.payload.result = context.toggleState;\n\n// Return the modified message object\nreturn msg;\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":200,"wires":[["25ca7b9c17693660","bcac79974de13aa4"]]},{"id":"6465e98b22084718","type":"hue-bridge","name":"Hue Bridge (Aredhone)","bridge":"xxx.xxx,x.xx","key":"xaaMhr4WOurTpaoriPyDffAX59V23PhyvLIll4Fw","worker":"10","autoupdates":true,"disableupdates":false}]

```

---

<div class="post-metadata">

**Author:** ![homeplayer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homeplayer/32/12388_2.png) [@homeplayer](https://discourse.nodered.org/u/homeplayer)\
**Post date:** [30 April 2024 13:08 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/2 "2024-04-30T13:08:04Z")

</div>

see updates in function node

```auto
// Initialize a variable to track the state
var toggleState = context.get("toggleState") || false;

// Check if msg.payload.button is a number and msg.payload.action is a string with the specified value
if (
    msg.payload &&
    typeof msg.payload.button === 'number' &&
    msg.payload.button === 3 &&
    typeof msg.payload.action === 'string' &&
    msg.payload.action === 'initial_press'
) {
    // Toggle the state
    toggleState = !context.toggleState;
    // save state
    context.set("toggleState", toggleState)
}

// Set msg.payload.result based on the state
msg.payload.result = toggleState;

// Return the modified message object
return msg;

```

---

<div class="post-metadata">

**Author:** ![aredhone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aredhone/32/90359_2.png) [@aredhone](https://discourse.nodered.org/u/aredhone)\
**Post date:** [30 April 2024 17:02 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/3 "2024-04-30T17:02:31Z")

</div>

i have the same problem with this no mather witch button i press on the hue tap it toggles the light i only want it to toggle when i press button 3

---

<div class="post-metadata">

**Author:** ![homeplayer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homeplayer/32/12388_2.png) [@homeplayer](https://discourse.nodered.org/u/homeplayer)\
**Post date:** [30 April 2024 17:44 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/4 "2024-04-30T17:44:04Z")

</div>

Please share the incoming msg , then i can help, of al 3 buttons pressed

---

<div class="post-metadata">

**Author:** ![aredhone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aredhone/32/90359_2.png) [@aredhone](https://discourse.nodered.org/u/aredhone)\
**Post date:** [30 April 2024 17:48 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/5 "2024-04-30T17:48:25Z")

</div>

i hope this helps

```auto
4/30/2024, 7:46:21 PMnode: Complete msg
msg : Object
{ payload: object, info: object, updated: object, lastState: object, command: object … }
4/30/2024, 7:46:21 PMnode: Information function
msg.msg.payload.result : boolean
true
4/30/2024, 7:46:22 PMnode: Complete msg
msg : Object
{ payload: object, info: object, updated: object, lastState: object, command: object … }
4/30/2024, 7:46:22 PMnode: Information function
msg.msg.payload.result : boolean
true
4/30/2024, 7:46:28 PMnode: Complete msg
msg : Object
{ payload: object, info: object, updated: object, lastState: object, command: object … }
4/30/2024, 7:46:28 PMnode: Information function
msg.msg.payload.result : boolean
true
4/30/2024, 7:46:29 PMnode: Complete msg
msg : Object
{ payload: object, info: object, updated: object, lastState: object, command: object … }
4/30/2024, 7:46:29 PMnode: Information function
msg.msg.payload.result : boolean
true

```

---

<div class="post-metadata">

**Author:** ![homeplayer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homeplayer/32/12388_2.png) [@homeplayer](https://discourse.nodered.org/u/homeplayer)\
**Post date:** [30 April 2024 19:53 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/6 "2024-04-30T19:53:09Z")

</div>

> [@aredhone](#):
>
> i hope this helps

nope cant see what this contains  
payload: object, info: object, updated: object

---

<div class="post-metadata">

**Author:** ![aredhone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/aredhone/32/90359_2.png) [@aredhone](https://discourse.nodered.org/u/aredhone)\
**Post date:** [30 April 2024 19:58 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/7 "2024-04-30T19:58:25Z")

</div>

Thanks for your efford but i found another way how to do it through devices and functions lessen for me not all extensions make life easier  
Well thanks for all the help all

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 July 2024 19:58 UTC](https://discourse.nodered.org/t/need-help-with-huemagic/87596/8 "2024-07-29T19:58:35Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
