Finally - a cheap WIRELESS switch that dims! Xiaomi Switch Gen1

I’ve been trying to use this automation with light.fastled integration and the brightness only changes when I let go of the button. Anyone tried this with fastleds?

Same here with flux led.

Hi everyone,

Do you think that the newer WXKG12LM Aqara buttons (the one with the shake function) will be able to do this dimming?

From what I see in their capabilities they have a long press and a long release.

Yes of course, but the ultimate test is when you do it and tell us the answer.

I am trying for some hours now but I can’t get it to work. To be honest I am not that proficient with yaml.
I copied and pasted most parts in my scripts and automations (changing the light.MY_LIGHT of course).

I am getting no errors but it is not working either.

One thing I noticed is that the new Aqara buttons have different entities and actions than the v1 ones implemented by the OP.

For example, I created an automation for a long press to increase my TV lamp’s brightness so I can see how it is implemented. I got this for the trigger:

- id: '1611265145650'
  alias: Aqara Button Long Press
  description: ''
  trigger:
  **- device_id: 026ad770558421bb3af330debf6167b2**
**    domain: zha**
**    platform: device**
**    type: remote_button_long_press**
**    subtype: remote_button_long_press**
  condition: []
  action:
  - type: brightness_increase
    device_id: d52a35e897fe3f6e804488a1616cc1d8
    entity_id: light.tv_lamp
    domain: light
  mode: single

So the trigger part changes. The original is like this:

  trigger:
    - platform: event
      event_type: click
      event_data:
        entity_id: binary_sensor.switch_158d00019df218
        click_type: long_click_press

The thing is that the Aqara buttons don’t register any binary_sensor.switch.

I someone can help or understand how it can be done then feel free to tell.

my scripts.yaml

dim_light_landing:
sequence:

- condition: state
  entity_id: input_boolean.landing_dim
  state: 'on'

- service: light.turn_on
  entity_id: light.tv_lamp
  data_template:
    brightness: '{{states.light.tv_lamp.attributes.brightness - 10}}'

- service: script.turn_off
  entity_id: script.dim_light_landing

- service: script.turn_on
  entity_id: script.dim_light_landing

brighten_light_landing:
sequence:

- condition: state
  entity_id: input_boolean.landing_dim
  state: 'off'

- service: light.turn_on
  entity_id: light.tv_lamp
  data_template:
    brightness: '{{states.light.tv_lamp.attributes.brightness + 10}}'

- service: script.turn_off
  entity_id: script.brighten_light_landing

- service: script.turn_on
  entity_id: script.brighten_light_landing
my automation.yaml
  • alias: xiaomi landing brighten on
    initial_state: ‘on’
    trigger:

    • device_id: 026ad770558421bb3af330debf6167b2
      domain: zha
      platform: device
      type: remote_button_long_press
      subtype: remote_button_long_press
      condition:
      condition: and
      conditions:
      • condition: state
        entity_id: input_boolean.landing_dim
        state: ‘off’
      • condition: state
        entity_id: light.landing_light
        state: ‘on’
        action:
    • service: script.turn_on
      entity_id: script.brighten_light_landing
  • alias: xiaomi landing brighten off
    initial_state: ‘on’
    trigger:

    • platform: state
      entity_id: binary_sensor.switch_158d00019df218
      from: ‘on’
      to: ‘off’
      condition:
      condition: and
      conditions:
      • condition: state
        entity_id: input_boolean.landing_dim
        state: ‘off’
      • condition: state
        entity_id: light.landing_light
        state: ‘on’
        action:
    • service: input_boolean.turn_on
      entity_id: input_boolean.landing_dim
  • alias: xiaomi landing dim on
    initial_state: ‘on’
    trigger:

    • device_id: 026ad770558421bb3af330debf6167b2
      domain: zha
      platform: device
      type: remote_button_long_release
      subtype: remote_button_long_release
      condition:
      condition: and
      conditions:
      • condition: state
        entity_id: input_boolean.landing_dim
        state: ‘on’
      • condition: state
        entity_id: light.landing_light
        state: ‘on’
        action:
    • service: script.turn_on
      entity_id: script.dim_light_landing
  • alias: xiaomi landing brighten off
    initial_state: ‘on’
    trigger:

    • device_id: 026ad770558421bb3af330debf6167b2
      domain: zha
      platform: device
      type: remote_button_long_release
      subtype: remote_button_long_release
      condition:
      condition: and
      conditions:
      • condition: state
        entity_id: input_boolean.landing_dim
        state: ‘on’
      • condition: state
        entity_id: light.landing_light
        state: ‘on’
        action:
    • service: input_boolean.turn_off
      entity_id: input_boolean.landing_dim
my input_boolean
input_boolean:
  landing_dim:
    name: Landing Dim
    initial: off

Hi, for anyone interested I was finally able to (almost) make it work with the ZHA integration. The only problem I am facing now is that the script stops at the first brightness change and does not continue to brighten or dim the light fully.

I used the remote_button_long_press and the remote_button_long_release attributes so to replace the binary_sensor attribute that comes with the Xiaomi integration.

I am posting my code below and I hope it helps someone like me out there. If anyone knows how to make the script execute continuously feel free to share.

Thanks!

automations.yaml
- id: '1628596690131'
  alias: Lights Brighten On
  description: Lights Brighten On
  trigger:
  - device_id: b861b87561a22341de97450166bb955b
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: button
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'off'
    - condition: state
      entity_id: light.playroom_lamp
      state: 'on'
  action:
  - service: script.turn_on
    target:
      entity_id: script.brighten_light_landing
  mode: single
  initial_state: 'on'
- id: '1628598830171'
  alias: Lights Brighten Off
  description: Lights Brighten Off
  trigger:
  - device_id: b861b87561a22341de97450166bb955b
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: button
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'off'
    - condition: state
      entity_id: light.playroom_lamp
      state: 'on'
  action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.landing_dim
  mode: single
  initial_state: 'on'
- id: '1628599133713'
  alias: Lights Landing Dim On
  description: Lights Landing Dim On
  trigger:
  - device_id: b861b87561a22341de97450166bb955b
    domain: zha
    platform: device
    type: remote_button_long_press
    subtype: button
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'on'
    - condition: state
      entity_id: light.playroom_lamp
      state: 'on'
  action:
  - service: script.turn_on
    target:
      entity_id: script.dim_light_landing
  mode: single
  initial_state: 'on'
- id: '1628599248404'
  alias: Lights Landing Dim Off
  description: Lights Lighting Dim Off
  trigger:
  - device_id: b861b87561a22341de97450166bb955b
    domain: zha
    platform: device
    type: remote_button_long_release
    subtype: button
  condition:
  - condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.landing_dim
      state: 'on'
    - condition: state
      entity_id: light.playroom_lamp
      state: 'on'
  action:
  - service: input_boolean.turn_off
    target:
      entity_id: input_boolean.landing_dim
  mode: single
  initial_state: 'on'
scripts.yaml
dim_light_landing:
  sequence:
  - condition: state
    entity_id: input_boolean.landing_dim
    state: 'on'
  - service: light.turn_on
    entity_id: light.playroom_lamp
    data_template:
      brightness: '{{states.light.playroom_lamp.attributes.brightness - 10}}'
  - service: script.turn_off
    entity_id: script.dim_light_landing
  - service: script.turn_on
    entity_id: script.dim_light_landing
  mode: single
  alias: Dim Light Landing
brighten_light_landing:
  sequence:
  - condition: state
    entity_id: input_boolean.landing_dim
    state: 'off'
  - service: light.turn_on
    entity_id: light.playroom_lamp
    data_template:
      brightness: '{{states.light.playroom_lamp.attributes.brightness + 10}}'
  - service: script.turn_off
    entity_id: script.brighten_light_landing
  - service: script.turn_on
    entity_id: script.brighten_light_landing
  mode: single
  alias: Brighten Light Landing

Edit: I have contacted jodur on this post who has figured out a workaround for the Xiaomi round button when paired through ZHA for the long press event. Let’s hope he can help on this.

1 Like

Hello. I am trying to use your example to control the lights. But I can’t figure out where and how to insert the codes. Can you please advise how to set up the entire automation?
Thank you

Necroposter, who are you replying to?

For first comment - badgerhome