Incremental Increase of Light Brightness

So i have been struggling with this case my self from 2 days now.
I have read and tested deferent things around the forum and reddit and did not find working solution. Obviously I am missing something somewhere.
I am trying to do a simple automation.
If i press a button (Ikea E1524 remote connected via Zigbee2MQTT) i want to increase or decrease the brightness of a light. Ether by percent or value. The simple on/off automation works with no problems.
I have no Idea where to put the pointed solution

  data_template:
    brightness: '{{states.light.light_name.attributes.brightness + 10}}'

CAN somebody paste/publish a complete working code from automation.yaml for reference.
Thank you.

1 Like

@TGR I got one :slight_smile: just build it today with the same config as you have.

  • Zigbee2MQTT configuration (with latest release 1.21 and firmware, you must upgrade for use with the E1524 button).

  • Ikea TRADFRI E1524 button

  • Ikea TRADFRI LED bulb E27 LED1623G12 (light)

My dimmer E1524 button is showing as 0xd0cf5efffe276402_action and the bulb has multiple entities 2 of them has a attribute with brightness in it. I renamed the entity within zigbee2mqtt but that’s somehow not done for al the HASS entries :thinking: The bulb has this address x000b57fffe307869
and in HASS this entities:

  1. light.0x000b57fffe307869_light
  2. sensor.zb_ikea_lamp_badkamer_linkquality

So first I tried to use states.sensor.light.0x000b57fffe307869_light .attributes.brightness but that failed with the validation. But it works with states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness

So this is the complete example script:

 - alias: ZB badroom ON/OFF
   trigger:
     platform: state
     entity_id: sensor.0xd0cf5efffe276402_action
     to: 'toggle'
   action:
     entity_id: light.0x000b57fffe307869_light
     service: light.toggle

 - alias: ZB badroom - dimmer UP
   trigger:
      platform: state
      entity_id: sensor.0xd0cf5efffe276402_action
      to: 'brightness_up_click'
   action:
     - service: light.turn_on
       entity_id: light.0x000b57fffe307869_light
       data_template:
         brightness: >
             {% set suggested = states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness|int + 31 %}
             {% if suggested < 200 %}
             {{ suggested }}
             {% else %}
             200
             {% endif %}
 - alias: ZB badroom - dimmer DOWN
   trigger:
      platform: state
      entity_id: sensor.0xd0cf5efffe276402_action
      to: 'brightness_down_click'
   action:
     - service: light.turn_on
       entity_id: light.0x000b57fffe307869_light
       data_template:
         brightness: >
             {% set suggested = states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness|int - 31 %}
             {% if suggested > 25 %}
             {{ suggested }}
             {% else %}
             25
             {% endif %} 

So you can use this for reference, just put your own entity ID’s in it.
And the Ikea E1524 dimmer is quite fancy, it has multiple states when you press a button. short and long presses gives different states:

  1. “toggle”

  2. “brightness_up_hold”

  3. “brightness_up_release”

  4. “brightness_up_click”

  5. “brightness_down_click”

  6. “brightness_down_release”

  7. “brightness_down_click”

  8. “arrow_right_click”

  9. “arrow_left_click”

Next step is to get this states working in a script so that way when I long press the brightness button the bulb will continue to in/decrease the levels.

5 Likes

I do no get only this:

states.sensor.zb_ikea_lamp_badkamer_linkquality.attributes.brightness

My light does not support such state.sensor
My light is Philips Xiaomi wifi

my brightness is set in an other sensor than the switch for the light ON/OFF.
on/off is in light.0x000b57fffe307869_light and brightness is in sensor.zb_ikea_lamp_badkamer_linkquality

so according to https://www.home-assistant.io/components/light.xiaomi_miio/ you can set brightness. so look for it in your entity list.

OK, I need help then in other direction then.
How can I read/use the current brightness of switched on light as condition?
What condition TYPE should I use: numeric state, state, or template?
I did try state, but all I tried to put in numeric state does not work.
Examples or suggestions anyone?

I have somewhat the same configuration as @alco has above, but I don’t use the discovery mode from zigbee2mqtt. I define all of my devices (sensors) manually in yaml.

An example with the IKEA Tradfri LED bulb E27 600 lumen dimmable, color, opal white light (LED1624G9):

light:
  - platform: mqtt
    name: living_room
    state_topic: 'zigbee2mqtt/light_living_room'
    command_topic: 'zigbee2mqtt/light_living_room/set'
    availability_topic: 'zigbee2mqtt/bridge/state'
    json_attributes_topic: 'zigbee2mqtt/light_living_room'
    brightness: true
    xy: true
    schema: json

Notice the fact that I’m using json_attributes_topic in there, which adds all of the attributes (which are available in the zigbee2mqtt JSON) to the light sensor in Home Assistant.

So, by adding that I can simply call states.light.living_room.attributes.brightness or state_attr('light.living_room', 'brightness') to retrieve its brightness, whichever you prefer.

And this is my automation which is based on percentages:

automation:
  - alias: remote_brightness_up
    initial_state: true
    trigger:
      platform: mqtt
      topic: 'zigbee2mqtt/remote_living_room'
    condition:
      condition: template
      value_template: "{{ trigger.payload_json.action == 'brightness_up_click' }}"
    action:
      service: light.turn_on
      data_template:
        entity_id: light.living_room
        brightness_pct: >
          {% set brightness_pct = (state_attr('light.living_room', 'brightness') / 2.55) | int | round(0) %}
          {% set new_brightness = brightness_pct + 10 %}
          {% if new_brightness < 100 %}
            {{ new_brightness }}
          {% else %}
            100
          {% endif %}

In this automation you see zigbee2mqtt/remote_living_room as the topic. remote_living_room is the friendly_name of my IKEA Tradfri remote control in the zigbee2mqtt configuration itself.

1 Like

@alco, did you ever figure out how to use the long press to continuously brighten/dim? If so, I’d be very grateful to see the solution!

1 Like

HI Corvy,

was trying to use this action on the UI and it doesnt let me save it so I went manual on the yaml file however is not working, Im trying to regulate the brightness of my yeelights with the rotatetion of a xiaomi cube

id: '000000001'    
  alias: Tesseract_rl
  trigger:
  - entity_id: sensor.0x00158d0001038f7c_action
    platform: state
    to: rotate_left
  condition:
  - condition: state
    entity_id: light.la_luz_del_estudio
    state: 'on'
  action:
  - data:
      brightness: >
            {% set suggested = states.light.light.la_luz_del_estudio.attributes.brightness|int + 31 %}
            {% if suggested < 200 %}
            {{ suggested }}
            {% else %}
            200
            {% endif %} 

Am I doing anything wrong? checked the indentation but the configurator says its alright

Not sure, looks more or less right but you need a - before id on the first line at least.

- id: '000000001'    
  alias: Tesseract_rl
  trigger:
  - entity_id: sensor.0x00158d0001038f7c_action
    platform: state
    to: rotate_left
  condition:
  - condition: state
    entity_id: light.la_luz_del_estudio
    state: 'on'
  action:
  - data:
      brightness: >
            {% set suggested = states.light.light.la_luz_del_estudio.attributes.brightness|int + 31 %}
            {% if suggested < 200 %}
            {{ suggested }}
            {% else %}
            200
            {% endif %} 

Hey guys,

I created an app for AppDaemon to bring full functionality to IKEA E1524/E1810 and IKEA E1743. If you have more than one controller you can add a new instance app and that’s it. I don’t support group of lights, just 1 sensor connected with 1 light. However, you can connect them by creating different apps with multiple lights and the same controller in all of them. You can see the post about it here.

I have another twist of the same challange. I want to repeatedly increase the brightness stepwise but my code does not achieve that. Any ideas?

- id: '1570867369747'
  alias: Time
  trigger:
  - at: '23:15'
    platform: time
  condition:
  - condition: state
    entity_id: input_boolean.automation_sunrise
    state: 'on'
  action:
    - service: light.turn_on
      data_template:
        entity_id: light.hall_tak
        brightness: >
          {% if states.light.hall_tak.attributes.brightness < 50 %}
          {% set steps = (250 - states.light.hall_tak.attributes.brightness) // 20 %}
          {% for i in range(1, steps+1) %}
          {{ states.light.hall_tak.attributes.brightness + i*20 }}
          {% endfor %}
          {% endif %}

Somewhere between the latest reply and now this has become a built-in feature of the light.turn_on service:

alias: Dimmer - increase
trigger:
  - platform: device
    domain: mqtt
    device_id: #redacted#
    type: action
    subtype: up_press
    discovery_id: #redacted# action_up_press
condition:
  - condition: device
    type: is_on
    device_id: #redacted#
    entity_id: light.living
    domain: light
action:
  - service: light.turn_on
    data:
      transition: 1
      brightness_step_pct: 10
    target:
      entity_id: light.living
mode: single
5 Likes

Thanks, man! You really saved me from going down a rabbit hole there! Was considering if I was going to create a custom component for this. Glad I saw your reply first. Can’t say putting the functionality in light.turn_on is the most intuitive… Should probably have been its own service?

Anyways, @Method, is there any way you could mark @robv’s answer as the correct one? I think it could help others coming across this topic :slight_smile:

Have a nice day folks!

PS: Sorry about the ping.

2 Likes