Zigbee2Mqtt - IKEA five button remote

This is working great! I have an issue tho that maybe I can get some help with:
I have an IKEA LED1732G11 light, that has the ability to adjust its color temperature. Originally I had the functionality that pressing/holding left and right increased/decreased the color temperature. Do you know by any chance how I can get that functionality back? Z2M doesnt give me an action on the lights entity to set the color temp, albeit the light card on HA does allow me to set it, so there has to be some mqtt command for it, I just don’t know how to investigate it.
Thanks!

@sztanpet My best guess would be to assign Left button - long press to a script that grabs the current color temperature, then increments along up or down. That’s a good idea, though.

Here’s some logic I’m using for holding down the brightness up/down buttons that maybe could be used in a similar way for color/temperature too.

sequence:
  - repeat:
      until:
        - condition: state
          entity_id: sensor.ikea_remote_action
          state: arrow_left_release
          attribute: action
      sequence:
        - service: light.turn_on
          data:
            # change color temp here by an increment instead of brightness
            brightness_step_pct: 10
            transition: 1
          entity_id: light.target_light
        - delay: '1'
2 Likes

So I tried multiple things, but I’m guessing this just won’t work without another variable that tracks the value of the color temperature, maybe it doesn’t update while the repeat-until is going on?
What I’m trying to do is to access the target lights state, get the current color temperature and adjust relative to it, either increasing or decreasing it.
It doesn’t work at all, maybe I’m doing it completely wrong, but there isn’t much documentation on how to access the target in the action, or I just didn’t find the relevant docs. Here is a snippet, everything else is basically the same as in the OP

- variables:
    command: '{{ trigger.to_state.state }}'
    lights: !input 'light'
- choose:
  - conditions:
    - '{{ command == ''toggle'' }}'
    sequence:
    - choose:
      - conditions: '{{ force_brightness }}'
        sequence:
        - service: light.toggle
          target: !input 'light'
          data:
            transition: 1
            brightness_pct: !input 'brightness'
      default:
      - service: light.toggle
        target: !input 'light'
        data:
          transition: 1
  - conditions:
    - '{{ command == ''brightness_up_click'' }}'
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        brightness_step_pct: 10
        transition: 1
  - conditions:
    - '{{ command == ''brightness_up_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: brightness_up_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 10
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''brightness_down_click'' }}'
    sequence:
    - service: light.turn_on
      target: !input 'light'
      data:
        brightness_step_pct: -10
        transition: 1
  - conditions:
    - '{{ command == ''brightness_down_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: brightness_down_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: -10
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''arrow_left_click'' }}'
    sequence: !input 'button_left_short'
  - conditions:
    - '{{ command == ''arrow_right_click'' }}'
    sequence: !input 'button_right_short'
  - conditions:
    - '{{ command == ''arrow_left_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: arrow_left_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            color_temp: >
              {% if state_attr(lights[0], "color_temp") | int - 100 < state_attr(lights[0], "min_mireds")  %}
                {{- state_attr(lights[0], "min_mireds") -}}
              {% else%}
                {{- state_attr(lights[0], "color_temp") | int - 100 -}}
              {% endif %}
            transition: 1
          target: !input 'light'
        - delay: '1'
  - conditions:
    - '{{ command == ''arrow_right_hold'' }}'
    sequence:
    - repeat:
        until:
        - condition: state
          entity_id: !input 'remote'
          state: arrow_right_release
          attribute: action
        sequence:
        - service: light.turn_on
          data:
            color_temp: >
              {% if state_attr(lights[0], "color_temp") | int + 100 > state_attr(lights[0], "max_mireds")  %}
                {{- state_attr(lights[0], "max_mireds") -}}
              {% else%}
                {{- state_attr(lights[0], "color_temp") | int + 100 -}}
              {% endif %}
            transition: 1
          target: !input 'light'
        - delay: '1'

It looks like you’re heading in the right direction. I’d test the templates with the /developer-tools/template section and perhaps turn the sequence into a Script to test it without the Blueprint bits. My Tradfri bulb unfortunately doesn’t support color_temp so I’m not sure how to help test your sequence.

{% if state_attr('light.bulb', "color_temp") | int - 100 < state_attr('light.bulb', "min_mireds")  %}
  {{- state_attr('light.bulb', "min_mireds") -}}
{% else%}
  {{- state_attr('light.bulb', "color_temp") | int - 100 -}}
{% endif %} 

Thanks for this excellent blueprint, that greatly simplifies setting up the remote.

It might be worth considering creating a modification of this, that uses the “recommended” MQTT Device triggers as per https://www.zigbee2mqtt.io/integration/home_assistant.html#via-mqtt-device-trigger-recommended

So that the blueprint also functions properly even if
homeassistant_legacy_triggers: false
is set in the zigbee2mqtt configuration.yaml :smile:

3 Likes

I’ve been messing with this thing, trying to increase the speed of the repeat sequence, but it seems to me that the repeat sequence doesn’t work correctly. I changed the until-state to arrow_left_click as a test, so that the brightness should continue increasing/decreasing until I press the left button. It doesn’t work. My IKEA remotes just sends a hold message every second or so until I release the brightness buttons, and the brightness step sequence only seems to activate when a new hold message is sent. Probably because the repeat sequences are preceded by - conditions: - “{{ command == ‘brightness_up_hold’ }}”. I suspect that as soon as there isn’t a brightness hold message being received, the condition is false, and thus the repeat sequence is cut short. Maybe we should have multiple trigger-action rules. I’m going to try a few things.

Did you try to adjust the delay time in the sequence to milliseconds and remove the transition?

I tried that first, yes. The behaviour remained the same as before that change. Just a change once every second or so. Even when I change it to 100 milliseconds.

EDIT: nevermind, I just discovered that it’s a limit in my lamps. Apparently, my Philips Hue does work smoothly now. My WiZ lights have some sort of limit. The problem is not with this blueprint.

@Revorge I’m using zigbee2mqtt for a while now and I’ve disabled the legacy triggers. I’m using the MQTT device triggers as you mentioned. For that reason I cannot use this kind of blueprints because the action attribute isn’t reset to the default value.

Do you know if it is possible to create blueprints using device triggers? I never found any examples/documentation about it.

WoW, just after the conference i thought of looking in to creating one for Zigbee2mqtt. But never got the time for it. I have imported it but not yet tested it. I was wondering is it possible to add 2 remotes to 1 blueprint. In my case i have 3 ikea lights which i can control from 2 side of the home. Not sure if this is the correct translating but compare it with a hotel switching where you can put on the light from on side of the room en turn it off on the other side of the room.

The quick and dirty way now would be to duplicate the automation but was wondering if it even is possible to add 2 remotes to 1 blueprint.

Again Thanks! This saves me already so much time setting up automations

I think you’re talking about a 2-way switch. Or is it a 3 way switch. Anyways! I imagine you could rewrite the blueprint to allow for multiple remotes. I think the point of the blueprints is to easily duplicate the automation with different settings, or in your case, the same target light. Or, use the blueprint to create an automation once, then from the automation, use “Duplicate automation” and select a different remote.

image

Good thinking, but when i duplicate and select edit with Yaml i don’t see the real automation but still the yaml for the blueprint. (still new to blue print so might be doing something wrong)

Oh, that’s interesting, you’re right, the Edit with YAML button on the Automation shows the blueprint yaml, but only things that I’ve configured? But the Edit with UI still seems to be normal.

In your case, I’d just use Edit with UI and after duplicating the Automation just change the remote entity. You’ll end up with two Automations but maybe that’s just a limitation of the blueprint I wrote.

That would work, but currently looking in to the blueprint yaml and found a way to select multiple remotes, but still figuring out how to connect it to the trigger. Think it has something to do with the “sequence” option but can’t find any documentation on it.

To make brightness up/down work, the sequence needs an OR added to it to accept both remotes.

Here’s a Script I just wrote using the UI editor

alias: 1New Script
sequence:
  - repeat:
      until:
        - condition: or
          conditions:
            - condition: state
              entity_id: sensor.a_remote_action
              state: brightness_up_release
            - condition: state
              entity_id: sensor.b_remote_action
              state: brightness_up_release
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 10
            transition: 1
          entity_id: light.0x7ce52400000c15aa_light
        - delay: '1'
mode: single

Then use that for brightness_up_hold and brightness_down_hold

Getting stuck for the moment and have to continue at a later time. Will post my results if i make more progress. Thanks again!

Thanks so much for this @starbuck93

I’ve recently switched over from Deconz to zigbee2mqtt due to broader device support (as is my understanding anyway), and previously used this blueprint for Ikea 5 button which worked amazing: deCONZ - IKEA five button remote for lights with color temp

I’m relatively new to HA and have been trying to follow along with the discussion on Color Temp changing with Left/Right buttons but havent been able to work it out :frowning: Is there a simple way to make this work using your blueprint for zigbee2MQTT or, is it possible for you to update the blueprint to support functionality similar to the deconz version?

Thanks Again!

@BrisbaneGuy From what I could tell, deconz has some different commands than Z2M does, so I’m not exactly sure. Maybe try out --> 🎮 ZHA, deCONZ, Zigbee2MQTT - Ikea 5-button Remote Universal blueprint - all actions + double click events - control lights, media players and more with Hooks

I also tried to create a blueprint using devices instead of entity, I think currently it just isn’t possible as there is not only a device_id, there is also a discovery_id (when looking at automations using device triggers). Still not found any other blueprints or documentation using that.
So it seems “Home Assistant legacy triggers” is required for now?

Yes! It is quite annoying now - if you don’t use legacy triggers as is recommended in z2m as well as HA docs, blueprints cannot really work as mentioned/showed/discussed here: Device triggers from zigbee2mqtt vs mqtt listen, and sometimes a bit about blueprints - #15 by kotrfa

Edit: Add firt-class support for MQTT Device Triggers (to have feature parity with legacy triggers)