There is a lot of complexity in my button press handler right now, which is specific to my setup and I am working to simplify. I wanted a generic automation that can work for multiple pico remotes dealing with multiple adaptive switches and multiple light switches through the use of configuration variables. So I am going to share an edited snippet of what should work for you, rather than my actual automation. It assumes some hard-coded entity IDs, rather than the variables that I use.
################################################################################
# AUTOMATION: pico_light_buttonhandler
# Handler for Pico light-controlling remotes
################################################################################
- alias: pico_light_on_buttonpress
mode: single
trigger:
platform: event
event_type: pico_buttonpress
action:
- variables:
pico_id: "{{ trigger.event.data.entity_id }}"
button_pressed: "{{ trigger.event.data.button_pressed }}"
press_type: "{{ trigger.event.data.press_type }}"
# NOTE: Configure your own entity IDs for the AL switch and corresponding light below
adaptivelighting_id:
light_id:
- choose:
# On-Tap: Turn lights on with adaptive brightness & color
- conditions: "{{ button_pressed == 'on' and press_type == 'tap' }}"
sequence:
# You cannot apply both brightness and color when turning a light on from an off state.
# Manually apply the AL brightness first. This prevents a light from briefly going to
# its previous brightness before the AL component takes control. This way you don't blind
# yourself in the middle of the night.
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness_pct: "{{ state_attr(adaptivelighting_id, 'brightness_pct') }}"
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
color_temp: "{{ state_attr(adaptivelighting_id, 'color_temp_mired') }}"
# On-DoubleTap: Turn lights on at max brightness, keep color
- conditions: "{{ button_pressed == 'on' and press_type == 'doubletap' }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness_pct: 100
# Off-Tap: Turn lights off
- conditions: "{{ button_pressed == 'off' and press_type == 'tap' }}"
sequence:
- service: light.turn_off
data:
entity_id: "{{ light_id }}"
# Off-DoubleTap: Turn light on at min brightness, keep color
- conditions: "{{ button_pressed == 'off' and press_type == 'doubletap' }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness_pct: 1
# Up-Hold: Increase brightness at each interval
- conditions: "{{ button_pressed == 'up' }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness_step_pct: 15
# Down-Hold: Decrease brightness at each interval
- conditions: "{{ button_pressed == 'down' }}"
sequence:
- choose:
# Don't allow dimming below a value of 1, which would turn off the light
- conditions: "{{ (1-(255 - state_attr(light_id, 'brightness')|int)/255)*100 <= 15 }}"
sequence:
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness: 1
default:
- service: light.turn_on
data:
entity_id: "{{ light_id }}"
brightness_step_pct: -15
# Action-Tap:
- conditions: "{{ button_pressed == 'action' and press_type == 'tap' }}"
# NOTE: This sequence has been removed as it was heavily customized to iterate through multiple lighting 'profiles'
sequence: []
# Action-DoubleTap: Restore adaptive lighting
- conditions: "{{ button_pressed == 'action' and press_type == 'doubletap' }}"
sequence:
# Remove the light from manual control
- service: adaptive_lighting.set_manual_control
data:
entity_id: "{{ adaptivelighting_id }}"
lights: "{{ light_id }}"
manual_control: false