Incremental Increase of Light Brightness

that was it. I need to read a little closer next time lol

Hi there, can some one help me with this automation? I can’t really figure out

- alias: Comodino Andrea Dim+
  trigger:
    platform: event
    event_type: click
    event_data:
        entity_id: binary_sensor.switch_158d00012641b4
        click_type: hold
  action:
    service: light.turn_on
    entity_id: light.comodino_andrea
    data_template:
      brightness: '{{states.light.comodino_andrea.attributes.brightness + 10}}'

Try to change this line to:
brightness: ‘{{states.light.comodino_andrea.attributes.brightness|int + 10}}’

2 Likes

Thanks mate this solved my issue :smiley:
Do you know if there is a way for dim -
I’m trying this way but it doesn’t work… maybe is the service? light.turn_on?

action:
data_template:
  brightness: '{{states.light.comodino_andrea.attributes.brightness|int - 25}}'
entity_id: light.comodino_andrea
service: light.turn_on

Hello @MastroPino, I would try something like this:

  action:
    - service: light.turn_on
      entity_id: light.comodino_andrea
      data_template:
        brightness: '{{states.light.comodino_andrea.attributes.brightness|int - 25}}'

Make sure the indentation is correct. It looks wrong the way you set it up. Check also the logs for error when you reload. The way I have set up + and - dim looks like this:

- alias: Lysere på Toalettet +10%
  trigger:
    - platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.bryter_toalett_overetasje
        scene_id: 23
  action:
    - service: light.turn_on
      entity_id: light.dimmer_toalett_overetasje_level
      data_template:
        brightness: >
            {% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int + 31 %}
            {% if suggested < 200 %}
            {{ suggested }}
            {% else %}
            200
            {% endif %}
- alias: Mørkere på Toalettet -10%
  trigger:
    - platform: event
      event_type: zwave.scene_activated
      event_data:
        entity_id: zwave.bryter_toalett_overetasje
        scene_id: 40
  action:
    - service: light.turn_on
      entity_id: light.dimmer_toalett_overetasje_level
      data_template:
        brightness: >
            {% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int - 31 %}
            {% if suggested > 25 %}
            {{ suggested }}
            {% else %}
            25
            {% endif %}

The if settings are just to define a minimum and maximum dim. This way it never gets pitch black. The last steps on the dimmer above 200 makes no difference at my house so I define 200 as max.

Good luck :slight_smile:

4 Likes

do you guys have an easy, nice, clean way of increase/decrease stepping without going above 100% or 255 and below 0?

brightness: ‘{{states.light.comodino_andrea.attributes.brightness|int + 10}}’
brightness: >
            {% set suggested = states.light.dimmer_toalett_overetasje_level.attributes.brightness|int - 31 %}
            {% if suggested > 25 %}
            {{ suggested }}
            {% else %}
            25
            {% endif %}

This is doing exactly that. This example is decrease. It first takes the current value from the attribute, detracts 31, checks if the proposed value is above 25, if yes, use the proposed. If no then use 25. The same logic for increase is used in in the example from my previous post. You can change the 25s to 0s for your example. Or 255 for increase (remember to change - to + and > to < :slight_smile:

2 Likes

that is true… overlooked this one :slight_smile:
Thanks

Thanks mate, you save me :slight_smile:

1 Like

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.

4 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 %}