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

Hi I followed the script and it is working great with my Philips Hue lights. Smooth dimming and reliable. In another room I have a Fibaro2 dimmer which doesn’t seem to work with this script. Long pressing results in some flickering and sometime the light turning off completely. Another time it would suddenly jump to max brightness.

I seems to me that those Z-wave dimmers need a different kind of script. Anyone with a possible working solution?

Has anyone tried to do this with Ikea Trådfri lights? I have tried for 3 hours now and not got it working.
If anyone has successfully managed to dim Ikea tradfri I´d appreciate if you could share your code :pray:

Thanks for now!

You show us no config, or logs, or anything which would enable anyone to help you.

I tried this concept with a Ikea light bulb, so yes it works. As far as I know it works with al kinds of dimmable lights. I don’t have any code I can share with you as I’m on holiday.

This, with a few appropriate changes works for me using a xiaomi press and hold button, conbee, deconz and hue colour lights. Thank you.

Has anybody tried to adapt this to rotate thru the colours of a light?
Changing colour instead of dimming?
It is on my list of things to try…

Would you like to share?

Sure.

I had this file in my packages area:

2 Likes

I’d like to know if you have success with this as I was hoping to do the same thing but using the Xiaomi Cube rotation to scroll gradually through the colour spectrum.

I tried using zigbee2mqtt with mixed results. Zigbee2mqtt couldn’t seem to handle the rapid influx of messages.

Can anyone confirm this is still working? I’m on HA 91.3
I’ve tried following the original post with no luck, and also tried with the package that INTEL posted without any luck either.

I’m using a magic home LED controller with a xiaomi button (I have like 6 of these buttons in the house already)

I can get single clicks, double clicks to work.
I can see in the DEV tools that I am “holding the button” but the LEDs don’t dim up or down.

My code is exactly like the package INTEL posted, but I replaced all the sensor names with my own.

I’m not sure how to check logs to see where it’s faulting.
Help?

I’m trying to get this to work with my Tradfri remote and Tradfri lights, but I have not had any success with any of the scripts posted here. It should be possible as the Tradfri remote sends a 2001 event when longs pressing and a 2003 event when letting go of the button.

I have created a AppDaemon app that binds controllers with lights and media players for zigbee2mqtt, deconz and zha. You can download it from HACS. Here you have some details:

Let me know if you have any questions!

1 Like

Hello,

I’ve an issue, I can’t make this to work.
when I long press the xiaomi button, it turns the boolean “on” an “off”; if I run the scripts, after changing the state in the boolean, it dimm the light (xiaomi philips light); but can’t make it work all together.

could you help me? I used the code as you said and changed the “YOURSENSORID” “YOURLIGHT” for my xiaomi button and ligths.

thanks in advance

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