OK, so I’ve been looking for a wireless switch that capable of dimming a WiFi enabled Bulb for some time. I’m using This WiFi Bulb which has been flashed and is running the wonderful AiLight firmware by @stelgenhof but you could use any bulb, switch or remote capable of dimming.
This assumes you have already added your Gen1 Button using the Xiaomi Component
NOTE: The square Aqara (Square Gen2) Version is not capable of this as it does not have the required “long_press_press” click type.
There’s probably a better way of doing this, but it works really well!
CODE:
Input Boolean
input_boolean:
landing_dim:
name: Landing Dim
initial: off
Script - Dim Light
script:
dim_light_landing:
sequence:
- condition: state
entity_id: input_boolean.landing_dim
state: 'on'
- service: light.turn_on
entity_id: light.landing_light
data_template:
brightness: '{{states.light.landing_light.attributes.brightness - 10}}'
- service: script.turn_off
entity_id: script.dim_light_landing
- service: script.turn_on
entity_id: script.dim_light_landing
Script - Brighten Light
script:
brighten_light_landing:
sequence:
- condition: state
entity_id: input_boolean.landing_dim
state: 'off'
- service: light.turn_on
entity_id: light.landing_light
data_template:
brightness: '{{states.light.landing_light.attributes.brightness + 10}}'
- service: script.turn_off
entity_id: script.brighten_light_landing
- service: script.turn_on
entity_id: script.brighten_light_landing
Automations - Using TWO Xiaomi Switched to control one light
- alias: xiaomi landing brighten on
initial_state: 'on'
trigger:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00019df218
click_type: long_click_press
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00016c0bac
click_type: long_click_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'
- platform: state
entity_id: binary_sensor.switch_158d00016c0bac
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:
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00019df218
click_type: long_click_press
- platform: event
event_type: click
event_data:
entity_id: binary_sensor.switch_158d00016c0bac
click_type: long_click_press
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:
- platform: state
entity_id: binary_sensor.switch_158d00019df218
from: 'on'
to: 'off'
- platform: state
entity_id: binary_sensor.switch_158d00016c0bac
from: 'on'
to: 'off'
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
When you press and hold the switch, the light will brighten, 10 steps at a time, when you release the switch the light will stay at the brightness you release on. When you then press and hold the switch the the second time the light will do the opposite and start to dim, 10 steps at a time, when you release the button the light will stay as the desired brightness!
Hope this is useful to some people and please do let me know if this can be simplified!
Here’s a demo: