Help with parsing zha_event with switch node

I’ve got a Sonoff SNZB-01 button, which on a single click outputs:

{
    "event_type": "zha_event",
    "data": {
        "device_ieee": "00:12:4b:00:1c:d6:0f:66",
        "unique_id": "00:12:4b:00:1c:d6:0f:66:1:0x0006",
        "endpoint_id": 1,
        "cluster_id": 6,
        "command": "toggle",
        "args": []
    },
    "origin": "LOCAL",
    "time_fired": "2020-08-15T15:19:19.567805+00:00",
    "context": {
        "id": "b0b71de5df0a11ea9377b72c061ccbbc",
        "parent_id": null,
        "user_id": null
    }
}

I’m trying to parse this with a switch node to output to a light, with red for a single click (“toggle”), and blue for a double click (“on”). This is what I’ve got so far - which doesn’t work:

[{"id":"3a6725d4.62d622","type":"switch","z":"be4429a7.7b2b3","name":"","property":"payload.data.command","propertyType":"msg","rules":[{"t":"eq","v":"\"toggle\"","vt":"str"},{"t":"eq","v":"\"on\"","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":300,"wires":[["85ee1c58.53547"],["61570751.41b5d"]]}]

I’d be grateful for any assistance, please.
Jim

Got it!

[{"id":"be4429a7.7b2b3","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"3a6725d4.62d622","type":"switch","z":"be4429a7.7b2b3","name":"","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":270,"y":300,"wires":[["85ee1c58.53547"],["61570751.41b5d"],["3a5eeed8.15850a"]]},{"id":"46fd050.9989afc","type":"server-events","z":"be4429a7.7b2b3","name":"Button","server":"93de20d5.59f72","event_type":"zha_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"x":110,"y":300,"wires":[["3a6725d4.62d622","fa00e868.4ea0e8"]]},{"id":"61570751.41b5d","type":"api-call-service","z":"be4429a7.7b2b3","name":"Blue","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"blue\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":470,"y":300,"wires":[[]]},{"id":"85ee1c58.53547","type":"api-call-service","z":"be4429a7.7b2b3","name":"Red","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":470,"y":220,"wires":[[]]},{"id":"fa00e868.4ea0e8","type":"debug","z":"be4429a7.7b2b3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":290,"y":160,"wires":[]},{"id":"3a5eeed8.15850a","type":"api-call-service","z":"be4429a7.7b2b3","name":"Off","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lohas_bulb2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":470,"y":380,"wires":[[]]},{"id":"93de20d5.59f72","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]

This help page was very useful:
https://nodered.org/docs/user-guide/messages
I’d used the debug node before, but was unaware of the little buttons to the right of the elements. I’m using an old 14 inch laptop and they’re rather indistinct.
Jim

2 Likes

Thanks for this, got me all the way to 1 step away as i have two buttons, for others looking at this point you need another switch first to filter out which button like this.

[{"id":"3a6725d4.62d622","type":"switch","z":"be4429a7.7b2b3","name":"Choose Press Type","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":80,"wires":[["85ee1c58.53547"],["61570751.41b5d"],["3a5eeed8.15850a"]]},{"id":"46fd050.9989afc","type":"server-events","z":"be4429a7.7b2b3","name":"Sonoff Button","server":"93de20d5.59f72","event_type":"zha_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":90,"y":160,"wires":[["52fef741.946288"]]},{"id":"61570751.41b5d","type":"api-call-service","z":"be4429a7.7b2b3","name":"Blue","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"blue\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":80,"wires":[[]]},{"id":"85ee1c58.53547","type":"api-call-service","z":"be4429a7.7b2b3","name":"Red","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":20,"wires":[[]]},{"id":"3a5eeed8.15850a","type":"api-call-service","z":"be4429a7.7b2b3","name":"Off","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lohas_bulb2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":140,"wires":[[]]},{"id":"6365d73e.94cf18","type":"switch","z":"be4429a7.7b2b3","name":"Choose Press Type","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":490,"y":260,"wires":[["3c1b8859.4487e8"],["733e06ee.8ca898"],["3c3470e6.e77f2"]]},{"id":"733e06ee.8ca898","type":"api-call-service","z":"be4429a7.7b2b3","name":"Blue","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"blue\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":260,"wires":[[]]},{"id":"3c1b8859.4487e8","type":"api-call-service","z":"be4429a7.7b2b3","name":"Red","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lohas_bulb2","data":"{\"color_name\": \"red\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":200,"wires":[[]]},{"id":"3c3470e6.e77f2","type":"api-call-service","z":"be4429a7.7b2b3","name":"Off","server":"93de20d5.59f72","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lohas_bulb2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":670,"y":320,"wires":[[]]},{"id":"52fef741.946288","type":"switch","z":"be4429a7.7b2b3","name":"Choose Button","property":"payload.event.device_ieee","propertyType":"msg","rules":[{"t":"eq","v":"00:12:4b:00:22:66:52:12","vt":"str"},{"t":"eq","v":"00:12:4b:00:22:e9:5e:a9","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":260,"y":160,"wires":[["3a6725d4.62d622"],["6365d73e.94cf18"]]},{"id":"93de20d5.59f72","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false,"cacheJson":true}]
1 Like