Node red flow for Aqara Oppo button(s)

Tags: #<Tag:0x00007f7397cf9178> #<Tag:0x00007f7397cf9038> #<Tag:0x00007f7397cf8f70> #<Tag:0x00007f7397cf8e80>

I was searching for a good node red flow for integrating the Xiaomi Aqara Oppo 6 button switch. Couldn’t find any so posting mine here.

You could use these with the 2 or 4 buttons as well of course. Idea is that for each pair of buttons (left/right) I want to control 1 light(group). Press left is less light, right is more light.
I’m using the brightness_step_pct to increase/decrease as it nicely doesn’t need you to read the current status first.

Here’s what the flow looks like:

and code:

[{"id":"971342b4.e988d","type":"tab","label":"Oppo aqara 6 button","disabled":false,"info":""},{"id":"97db648b.da8968","type":"server-state-changed","z":"971342b4.e988d","name":"Aqara Oppo 6 button pressed","server":"b7fede2d.075c6","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.0x04cf8cdf3c7973e0","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":340,"y":260,"wires":[["1eb3961e.2ef3ca"]]},{"id":"87ce290e.8450b8","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1250,"y":100,"wires":[["d8480a96.2a6638"],[]]},{"id":"1eb3961e.2ef3ca","type":"switch","z":"971342b4.e988d","name":"button switch","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_1_[a-z]+","vt":"str","case":false},{"t":"regex","v":"button_2_[a-z]+","vt":"str","case":false},{"t":"regex","v":"button_3_[a-z]+","vt":"str","case":false},{"t":"regex","v":"button_4_[a-z]+","vt":"str","case":false},{"t":"regex","v":"button_5_[a-z]+","vt":"str","case":false},{"t":"regex","v":"button_6_[a-z]+","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":6,"x":600,"y":260,"wires":[["e8eb730.d7fa49"],["9e2c9846.c26448"],["bb8eea0e.20a9b8"],["6c92873.9ad4d78"],["e503d99c.0de428"],["f839ed68.3d9ab"]]},{"id":"e8eb730.d7fa49","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":840,"y":180,"wires":[["d8480a96.2a6638"],["71e86deb.a7f264"],["5c2cc833.ea59c8"],["87ce290e.8450b8"],["9dc7a31c.574cc"]]},{"id":"9dc7a31c.574cc","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":260,"wires":[["87ce290e.8450b8"]]},{"id":"d8480a96.2a6638","type":"change","z":"971342b4.e988d","name":"-10","rules":[{"t":"set","p":"payload","pt":"msg","to":"-10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":140,"wires":[["2c97c6b9.6ffefa"]]},{"id":"5c2cc833.ea59c8","type":"change","z":"971342b4.e988d","name":"-100","rules":[{"t":"set","p":"payload","pt":"msg","to":"-100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":200,"wires":[["2c97c6b9.6ffefa"]]},{"id":"71e86deb.a7f264","type":"change","z":"971342b4.e988d","name":"-50","rules":[{"t":"set","p":"payload","pt":"msg","to":"-50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":260,"wires":[["2c97c6b9.6ffefa"]]},{"id":"bde9d920.9cea28","type":"api-call-service","z":"971342b4.e988d","name":"change kitchen light by value","server":"b7fede2d.075c6","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1880,"y":320,"wires":[[]]},{"id":"f5579a.e8159868","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1270,"y":340,"wires":[["81b16ca3.029ce"],[]]},{"id":"9e2c9846.c26448","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":860,"y":420,"wires":[["81b16ca3.029ce"],["85de51e3.4be85"],["f507e474.dda1d8"],["f5579a.e8159868"],["4edfbba0.bd96a4"]]},{"id":"4edfbba0.bd96a4","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":500,"wires":[["f5579a.e8159868"]]},{"id":"81b16ca3.029ce","type":"change","z":"971342b4.e988d","name":"10","rules":[{"t":"set","p":"payload","pt":"msg","to":"10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":380,"wires":[["2c97c6b9.6ffefa"]]},{"id":"f507e474.dda1d8","type":"change","z":"971342b4.e988d","name":"100","rules":[{"t":"set","p":"payload","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":440,"wires":[["2c97c6b9.6ffefa"]]},{"id":"85de51e3.4be85","type":"change","z":"971342b4.e988d","name":"50","rules":[{"t":"set","p":"payload","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":500,"wires":[["2c97c6b9.6ffefa"]]},{"id":"2c97c6b9.6ffefa","type":"function","z":"971342b4.e988d","name":"create payload","func":"var newMsg =  {  \n   payload:{  \n      \"data\":{  \n         \"brightness_step_pct\":msg.payload\n       }\n   }\n}\nreturn newMsg;","outputs":1,"noerr":0,"x":1650,"y":320,"wires":[["bde9d920.9cea28"]]},{"id":"91f76e71.eb639","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1250,"y":600,"wires":[["a1741730.f97988"],[]]},{"id":"bb8eea0e.20a9b8","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":840,"y":680,"wires":[["a1741730.f97988"],["83f79cb3.6c25a"],["7bfbe87f.6b8568"],["91f76e71.eb639"],["6cb265a.5ea339c"]]},{"id":"6cb265a.5ea339c","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":760,"wires":[["91f76e71.eb639"]]},{"id":"a1741730.f97988","type":"change","z":"971342b4.e988d","name":"-10","rules":[{"t":"set","p":"payload","pt":"msg","to":"-10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":640,"wires":[["c54cfb9e.acb788"]]},{"id":"7bfbe87f.6b8568","type":"change","z":"971342b4.e988d","name":"-100","rules":[{"t":"set","p":"payload","pt":"msg","to":"-100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":700,"wires":[["c54cfb9e.acb788"]]},{"id":"83f79cb3.6c25a","type":"change","z":"971342b4.e988d","name":"-50","rules":[{"t":"set","p":"payload","pt":"msg","to":"-50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":760,"wires":[["c54cfb9e.acb788"]]},{"id":"1c100fc9.1bfe3","type":"api-call-service","z":"971342b4.e988d","name":"change dining light by value","server":"b7fede2d.075c6","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.dining","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1880,"y":820,"wires":[[]]},{"id":"2389f779.b8cde8","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1270,"y":840,"wires":[["9c4b95c0.e9fe88"],[]]},{"id":"6c92873.9ad4d78","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":860,"y":920,"wires":[["9c4b95c0.e9fe88"],["951472d.72fbd9"],["324bbcc.5ad2e44"],["2389f779.b8cde8"],["7ac1a6bf.881478"]]},{"id":"7ac1a6bf.881478","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":1000,"wires":[["2389f779.b8cde8"]]},{"id":"9c4b95c0.e9fe88","type":"change","z":"971342b4.e988d","name":"10","rules":[{"t":"set","p":"payload","pt":"msg","to":"10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":880,"wires":[["c54cfb9e.acb788"]]},{"id":"324bbcc.5ad2e44","type":"change","z":"971342b4.e988d","name":"100","rules":[{"t":"set","p":"payload","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":940,"wires":[["c54cfb9e.acb788"]]},{"id":"951472d.72fbd9","type":"change","z":"971342b4.e988d","name":"50","rules":[{"t":"set","p":"payload","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1420,"y":1000,"wires":[["c54cfb9e.acb788"]]},{"id":"c54cfb9e.acb788","type":"function","z":"971342b4.e988d","name":"create payload","func":"var newMsg =  {  \n   payload:{  \n      \"data\":{  \n         \"brightness_step_pct\":msg.payload\n       }\n   }\n}\nreturn newMsg;","outputs":1,"noerr":0,"x":1650,"y":820,"wires":[["1c100fc9.1bfe3"]]},{"id":"edb64243.697b5","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1270,"y":1140,"wires":[["c19f92d4.ef50d"],[]]},{"id":"e503d99c.0de428","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":860,"y":1220,"wires":[["c19f92d4.ef50d"],["103a8b5e.db3395"],["7f50f1e0.97335"],["edb64243.697b5"],["4ec4668d.952df8"]]},{"id":"4ec4668d.952df8","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1070,"y":1300,"wires":[["edb64243.697b5"]]},{"id":"c19f92d4.ef50d","type":"change","z":"971342b4.e988d","name":"-10","rules":[{"t":"set","p":"payload","pt":"msg","to":"-10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1460,"y":1180,"wires":[["438ccb16.2b4864"]]},{"id":"7f50f1e0.97335","type":"change","z":"971342b4.e988d","name":"-100","rules":[{"t":"set","p":"payload","pt":"msg","to":"-100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1460,"y":1240,"wires":[["438ccb16.2b4864"]]},{"id":"103a8b5e.db3395","type":"change","z":"971342b4.e988d","name":"-50","rules":[{"t":"set","p":"payload","pt":"msg","to":"-50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1460,"y":1300,"wires":[["438ccb16.2b4864"]]},{"id":"5c19aa67.8bb524","type":"api-call-service","z":"971342b4.e988d","name":"change living lights","server":"b7fede2d.075c6","version":1,"debugenabled":true,"service_domain":"light","service":"turn_on","entityId":"light.living_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1890,"y":1360,"wires":[[]]},{"id":"f839ed68.3d9ab","type":"switch","z":"971342b4.e988d","name":"push type: 1/2/3/h/r","property":"payload","propertyType":"msg","rules":[{"t":"regex","v":"button_[0-9]_single","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_double","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_triple","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_hold","vt":"str","case":false},{"t":"regex","v":"button_[0-9]_release","vt":"str","case":false}],"checkall":"true","repair":false,"outputs":5,"x":880,"y":1460,"wires":[["f76f30d1.18907"],["f33fbc7c.b5e6c"],["3a047956.3ad446"],["68e207b1.396f18"],["67d16d88.7b1fd4"]]},{"id":"67d16d88.7b1fd4","type":"change","z":"971342b4.e988d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1090,"y":1540,"wires":[["68e207b1.396f18"]]},{"id":"f76f30d1.18907","type":"change","z":"971342b4.e988d","name":"10","rules":[{"t":"set","p":"payload","pt":"msg","to":"10","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":1420,"wires":[["438ccb16.2b4864"]]},{"id":"3a047956.3ad446","type":"change","z":"971342b4.e988d","name":"100","rules":[{"t":"set","p":"payload","pt":"msg","to":"100","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":1480,"wires":[["438ccb16.2b4864"]]},{"id":"f33fbc7c.b5e6c","type":"change","z":"971342b4.e988d","name":"50","rules":[{"t":"set","p":"payload","pt":"msg","to":"50","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1440,"y":1540,"wires":[["438ccb16.2b4864"]]},{"id":"438ccb16.2b4864","type":"function","z":"971342b4.e988d","name":"create payload","func":"var newMsg =  {  \n   payload:{  \n      \"data\":{  \n         \"brightness_step_pct\":msg.payload\n       }\n   }\n}\nreturn newMsg;","outputs":1,"noerr":0,"x":1670,"y":1360,"wires":[["5c19aa67.8bb524"]]},{"id":"68e207b1.396f18","type":"looptimer","z":"971342b4.e988d","duration":".5","units":"Second","maxloops":"12","maxtimeout":"6","maxtimeoutunits":"Second","name":"","x":1270,"y":1380,"wires":[["f76f30d1.18907"],[]]},{"id":"64a4e3e5.2a63cc","type":"comment","z":"971342b4.e988d","name":"which button was pressed?","info":"","x":570,"y":180,"wires":[]},{"id":"47897055.91f3c","type":"comment","z":"971342b4.e988d","name":"how was the button pressed","info":"","x":860,"y":120,"wires":[]},{"id":"fd7bec24.2ac68","type":"comment","z":"971342b4.e988d","name":"Percent change as numeric value","info":"","x":1510,"y":100,"wires":[]},{"id":"b7fede2d.075c6","type":"server","z":"","name":"Home Assistant"}]

You can of course use it also to cycle through colours or whatever (not really my thing).
Hope this helps for those looking to use the buttons!