Switch between lights with left and right button IKEA STYRBAR

Dear community,

Is it possible to use de left en right button of de IKEA STYRBAR to switch between lights to brighten up or brighten down with the upper and lower button?

I have a group of 4x TRÅDFRI Led-lamp E27 250 lumen bulbs grouped in Zigbee2MQTT as a enitity. This group forms 1 lamp above the dinner table. The other lamp consists only at 1 bulb let’s call it the owl lamp above the coffee table. What I try to automate is with the use of one IKEA STYRBAR remote to adjust the brightness independent of each other. The left en right button I like to program as a select button either select the owl lamp or the lamp above the dinner table. When selecting they blink as a indector that I select one of the lamps and than brighten up or brighten down with de upper and lower button.

I found 🎮 ZHA, deCONZ, Zigbee2MQTT - IKEA E2001/E2002 STYRBAR Remote control Universal blueprint - all actions + double click events - control lights, media players and more with Hooks. But I don’t know how to assign a dynamic/variable ‘call services’ for brighten up or brighten down (either owl lamp or above the de coffe table).

I hope someone can help. Thanks in advance!

I would say it’s possible but I wouldn’t know how to do it in HA automation.
In node red I would use flow variables that is the light entity and use this in the automation.

Can you give me a starting point? Is it a simple as make a flow variable with a switch function and two entitities?

I think this could work.
I have replaced device nodes with inject nodes because they wont be imported correctly anyways, but just replace them with device nodes set to what the inject says.

[{"id":"96bcbdbc741846ae","type":"inject","z":"ebaa69a9.649708","name":"left","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":900,"wires":[["816d530237c78286"]]},{"id":"911dca1d344fa08e","type":"inject","z":"ebaa69a9.649708","name":"right","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":960,"wires":[["23c83c044a41d038"]]},{"id":"816d530237c78286","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"light","pt":"flow","to":"light.coffe","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":900,"wires":[[]]},{"id":"23c83c044a41d038","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"light","pt":"flow","to":"light.owl","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":960,"wires":[[]]},{"id":"db480f080ad6a430","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"hold_down","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1200,"wires":[["46a99cbc4f7b4efc"]]},{"id":"46a99cbc4f7b4efc","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{flow.light}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1110,"y":1200,"wires":[["2872d8e5f1ac5127"]]},{"id":"ec5a14db5927710a","type":"api-call-service","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{flow.light}}","data":"{\t    \"brightness\": msg.data.attributes.brightness\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1570,"y":1200,"wires":[["e09e1071ade9c31a"]]},{"id":"e09e1071ade9c31a","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1770,"y":1200,"wires":[["69c26b69e3cd2007"]]},{"id":"69c26b69e3cd2007","type":"switch","z":"ebaa69a9.649708","name":"","property":"hold_down","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1110,"y":1120,"wires":[["46a99cbc4f7b4efc"]]},{"id":"a3c431606152051e","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"hold_down","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":1140,"wires":[[]]},{"id":"22ecb8e69b338888","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"hold_up","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1400,"wires":[["44036526d2a5d765"]]},{"id":"ba8eba367071d402","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{flow.light}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1210,"y":1400,"wires":[["7ef5423af353569f"]]},{"id":"e5e889d3d74b2444","type":"api-call-service","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{flow.light}}","data":"{\t    \"brightness\": msg.data.attributes.brightness\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1690,"y":1400,"wires":[["e132fd2c25d79ac7"]]},{"id":"e132fd2c25d79ac7","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1890,"y":1400,"wires":[["9e5a74e1c2408a8b"]]},{"id":"9e5a74e1c2408a8b","type":"switch","z":"ebaa69a9.649708","name":"","property":"hold_up","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1230,"y":1320,"wires":[["ba8eba367071d402"]]},{"id":"81b8517c400ca25d","type":"change","z":"ebaa69a9.649708","name":"","rules":[{"t":"set","p":"hold_up","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":1340,"wires":[[]]},{"id":"2872d8e5f1ac5127","type":"function","z":"ebaa69a9.649708","name":"","func":"msg.data.attributes.brightness = Math.max(msg.data.attributes.brightness-6, 5);                  \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":1200,"wires":[["ec5a14db5927710a"]]},{"id":"7ef5423af353569f","type":"function","z":"ebaa69a9.649708","name":"","func":"msg.data.attributes.brightness = Math.min(msg.data.attributes.brightness+6, 255);                  \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1500,"y":1400,"wires":[["e5e889d3d74b2444"]]},{"id":"3384d07f2daa7944","type":"api-call-service","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"{{flow.light}}","data":"{\t    \"brightness\": 5\t}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1250,"y":1500,"wires":[["e50c3234e16fa6cb"]]},{"id":"e50c3234e16fa6cb","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1760,"y":1500,"wires":[["e132fd2c25d79ac7"]]},{"id":"44036526d2a5d765","type":"api-current-state","z":"ebaa69a9.649708","name":"","server":"4bbca37b.1700ec","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"{{flow.light}}","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":850,"y":1400,"wires":[["ba8eba367071d402"],["3384d07f2daa7944"]]},{"id":"29ffa364e9aebca1","type":"delay","z":"ebaa69a9.649708","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"allowrate":false,"outputs":1,"x":360,"y":1400,"wires":[["22ecb8e69b338888"]]},{"id":"0f68f09a45d4220e","type":"comment","z":"ebaa69a9.649708","name":"change to actual entity names","info":"","x":360,"y":840,"wires":[]},{"id":"22f23aabfa9faddf","type":"inject","z":"ebaa69a9.649708","name":"device, small sun release","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":1140,"wires":[["a3c431606152051e"]]},{"id":"501f674330724ab3","type":"inject","z":"ebaa69a9.649708","name":"device, small sun hold","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":1200,"wires":[["db480f080ad6a430"]]},{"id":"9bbba7592e0a0f4b","type":"inject","z":"ebaa69a9.649708","name":"device, large sun release","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":1340,"wires":[["81b8517c400ca25d"]]},{"id":"2ee9ccff068e746e","type":"inject","z":"ebaa69a9.649708","name":"device, large sun hold","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":1400,"wires":[["29ffa364e9aebca1"]]},{"id":"4bbca37b.1700ec","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

First happy “anniversary”! Thank you so much. I will post me result.

@Betrame did you tried this? This is exactly what I had in mind as well.

I know this topic may be slightly outdated but I very recently made my own automation blueprint that is meant for exactly this. Feel free to check it out.

In case of any bugs/ideas for improvement feel free to comment on this post.

Hi @Zuulcode,
I’ve integrated the Styrbar button via ZHA but it doesn’t work with your script since your script only permit to add “sensor” entities as I see in line 13 domain: sensor: I this way I can only select “IKEA of Sweden Remote Control N2 Battery” instead of “IKEA of Sweden Remote Control N2”.
So I’ve forked your code removing line 13, I can select the Styrbar button (integrated via ZHA) but it still doesn’t work, I mean the automation is never triggered.

Hi @bit111,

I believe this issue might be related to u using ZHA instead of Z2M. This blueprint was specificly designed for use with Z2M. Maybe the trigger wasn’t triggered because the specific state for the trigger isn’t the same for ZHA. I think this might be the place where you would need to start looking. Also make shure you created the input helper used for determining the current light.

I am sorry I couldn’t provide anymore useful input regarding to this specific usecase using ZHA.

I would have approached this as follows:

  • Create an input_select.light_to_control with the entity_ids of the lights you want to control (e.g., light.bedroom_1, light.bedroom_2)
  • On each left/right press use the input_select.select_next or select_previous to cycle between them.
  • On a bright/dim, use the input_select to get the entity_id from the input_select to choose which item to change

This requires just one template, something like this in your light.turn_on for bright/dimmer:

data_template:
  entity_id: "{{ states('input_select.light_to_control') }}"

-David

Smart approach,

This is the first HA blueprint I have ever made without a lot of experience developing automations for ha,
so thanks for the suggestion. I will sertainly keep this in mind for future automations/blueprints.

I use an identical approach as mentioned by @dbs on my styrbar remote.
Up and down control the ‘main lights’, and long press up and down dim or brighten those lights.

Left cycles through a list of scenes, which turn on (or off) side lamps.
And the right button cycles through present values for the main lights, to quickly get to a known setting (colour, brightness etc) that I want. You could as easily make it cycle through entity_ids, so that the up and down arrows then control the on/off or dimmer of that newly targetted device.

It uses the EPMatts blueprint from here:

But iirc, I had to make some tweaks to it to fix some button press events that got broken if you are using ZHA. I’m not sure those fixes are through PR yet, so you might need to grab the latest file from the PR and patch it manually.