Skip to content

Instantly share code, notes, and snippets.

@D3SOX
Last active April 10, 2025 16:49
Show Gist options
  • Save D3SOX/3aead771514d2a192b9bc88191d37f35 to your computer and use it in GitHub Desktop.
Save D3SOX/3aead771514d2a192b9bc88191d37f35 to your computer and use it in GitHub Desktop.
Dim a light with an Aqara Cube (depending on the side it lays)
alias: Aqara Cube Light Dimmer (Side-Aware)
description: Dim a light with an Aqara Cube (depending on the side it lays)
triggers:
- entity_id: sensor.aqara_cube_action_angle
trigger: state
conditions:
- condition: template
value_template: >-
{{ trigger.to_state.state != 'unknown' and
trigger.to_state.state|float|abs > 5 }}
actions:
- choose:
- conditions:
- condition: state
entity_id: sensor.aqara_cube_side
state: "1"
- condition: device
type: is_on
device_id: c7886385db52fb38934f3a8593df1e42
entity_id: cd17765642a26f17a335fceaba0a8317
domain: light
sequence:
- target:
entity_id: light.cob_strip_light
data:
brightness: >-
{% set current = state_attr('light.cob_strip_light',
'brightness') | int(100) %} {% set angle =
trigger.to_state.state | float %} {% if angle > 0 %}
{% set new_brightness = current + (angle|abs * brightness_multiplier)|int %}
{{ [new_brightness, 255]|min }}
{% else %}
{% set new_brightness = current - (angle|abs * brightness_multiplier)|int %}
{{ [new_brightness, 1]|max }}
{% endif %}
action: light.turn_on
- conditions:
- condition: state
entity_id: sensor.aqara_cube_side
state: "4"
- condition: device
type: is_on
device_id: 52beae62da83e748048aa5012cdc5c23
entity_id: a454f00f4d511075b674c73e0b68aaf6
domain: light
sequence:
- target:
entity_id: light.herbert
data:
brightness: >-
{% set current = state_attr('light.herbert', 'brightness') |
int(100) %} {% set angle = trigger.to_state.state | float %} {%
if angle > 0 %}
{% set new_brightness = current + (angle|abs * brightness_multiplier)|int %}
{{ [new_brightness, 255]|min }}
{% else %}
{% set new_brightness = current - (angle|abs * brightness_multiplier)|int %}
{{ [new_brightness, 1]|max }}
{% endif %}
action: light.turn_on
variables:
brightness_multiplier: 1.5
mode: restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment