Increase/Decrease Brightness on Button Press

Hi,

Happy new year :partying_face:.

So I am facing a small issue here and after a lot of reading I must conclude that I still can’t figure it out.
What I need is a bit of help getting my Wireless Buttons to be able to dim and bright the light when the button is pressed (single click).
I simply want it to either do a brightness +10 or -10% depending on whats pressed. It is okay if the light is turned off that it turns it on when brightening and also turning off the light if we get below 0%

I do have something similar with turning the volume up and down, but that doesn’t seem to be that easy with the light.

Here is my two automations:

### IHC Wireless Click Left Button ###
  - alias: '[Outdoor] IHC Click - Light Bright'
    trigger:
      platform: state
      entity_id: light.ihc_click_left
    action:
    - entity_id: light.backyard
      type: brightness_increase

    ### IHC Wireless Click Right Button ##
  - alias: '[Outdoor] IHC Click - Light Dim'
    trigger:
      platform: state
      entity_id: light.ihc_click_right
    action:
    - entity_id: light.backyard
      type: brightness_decrease

I get an error and I understand that I can’t get the type thing working here. Tried a lot of things, so I hope someone out there can help me out.

Thanks!

1 Like
  - alias: '[Outdoor] IHC Click - Light Control'
    trigger:
      platform: state
      entity_id:
        - light.ihc_lick_left
        - light.ihc_lick_right
    action:
      service: light.turn_on
      data:
        entity_id: light.backyard
        brightness_step_pct: "{{ 10 if trigger.to_state.entity_id == 'light.ihc_lick_left' else -10 }}"
6 Likes

Oh really :flushed:

How could I not have tried that! It works like a charm. Thanks for helping a newbie here :slight_smile:

1 Like

As I’m a non-educated IT guy so unfortunately I have to copy/paste examples from others to get things work. Each time I try to understand what I copied in order to teach myself.

I bought a Zigbee remote control with 3 buttons and finally it works to toggle a light.
This is my automation:

- id: '1613205616972'
  alias: Zigbee remote button 1
  description: ''
  trigger:
  - platform: mqtt
    payload: 1_single
    topic: zigbee2mqtt/3-button remote/action
  condition: []
  action:
  - service: light.toggle
    data: {}
    entity_id: light.bulb.kitchen
  mode: single

The above basic automation works.
Now I’d like to use another button to increase/decrease the brightness.
I came accross this thread so I copy/paste the data to my situation:

- id: '1613243606262'
  alias: Zigbee remote button 2
  description: ''
  trigger:
  - platform: mqtt
    payload: 2_single
    topic: zigbee2mqtt/3-button remote/action
  condition: []
  action:
    service: light.turn_on
    data:
      entity_id: light.all_bulbs_living
      brightness_step_pct: "{{ 10 if trigger.to_state.entity_id == 'light.all_bulbs_living' else -10 }}"

But it doesn’t work.
Any clever guy who knows why and how to solve it?
MANY THANKS !

I can certainly explain why it doesn’t work…

At the moment you have an mqtt trigger that says "when the payload ‘2_single’ is received in the ‘zigbee2mqtt/3-button remote/action’ topic, execute the action.

In that action you have a template that relies on a state trigger object to decide whether to put 10 or -10 based on which entity_id the state change occurred on. You don’t have a state change from a state trigger, so it won’t work.

As for fixing it…

What do you actually want it to do? What do you want to be the signal for +10% brightness, and what signal for -10%?

Hi, thanks for your reply!
The mqtt trigger works.
With the action I’d like to achieve that the brightness increases with steps of 10% till 100% is reached and with the next press that the brightness decreases again in steps of 10% to 0 and this in a kind of loop.
Each button has 3 states: single, double and hold
Unfortunately the 3 states are only sent when the button is released which means it’s not possible to have the above ‘brightness loop’ as long as the button is pressed (hold).
Corret me if I’m wrong.
The only solution and most practice I see is:
Single press: 1 step in the ‘brightness loop’
Double press: toggle.light on/off

Many thanks for your help!

So let’s say the light is off and you press this button - what do you want the automation to do? Turn the light on at 10%? Do nothing?

Also, let’s say the light is currently 80%, and you press the button - how am I to decide whether to go to 90% or 70%?

That’s a good one. Maybe just increase and if 100 is reached, go back to 0. Seems better

- id: '1613243606262'
  alias: Zigbee remote button 2
  description: ''
  trigger:
  - platform: mqtt
    payload: 2_single
    topic: zigbee2mqtt/3-button remote/action
  action:
    service: light.turn_on
    data:
      entity_id: light.all_bulbs_living
      brightness_step_pct: "{{ 10 if state_attr('light.all_bulbs_living', 'brightness')|int <= 250 else -90 }}"

So basically, tap the button, that sends the mqtt payload, triggers this automation. Brightness level is measured out of 255, so if it’s less than 250 increase brightness by 10%, if not reduce brightness by 90% (ie drop to 10%)

1 Like

Thanks, it works!

1 Like