Skip to content

Instantly share code, notes, and snippets.

@nblasgen
Last active January 2, 2025 01:37
Show Gist options
  • Save nblasgen/02d579dd8acc76206a02881977c7eaaa to your computer and use it in GitHub Desktop.
Save nblasgen/02d579dd8acc76206a02881977c7eaaa to your computer and use it in GitHub Desktop.
Home Assistant - Tuya Smart Button v1
blueprint:
name: ZHA - Tuya Smart Button v1.1
description: 'Control lights with a Tuya Smart Button. Pressing the button once will toggle the lights. Nothing else (yet)
is defined for double press or long press. Based on the great work of richlee91, bjpetit!'
domain: automation
input:
remote:
name: Tuya Smart Button
description: Tuya TS0041
selector:
device:
integration: zha
manufacturer: _TZ3000_qgwcxxws
model: TS0041
entity:
domain: sensor
device_class: battery
light:
name: Light(s)
description: The light(s) to control
selector:
target:
entity:
domain: light
mode: restart
max_exceeded: silent
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input 'remote'
action:
- variables:
selected_light: !input 'light'
command: '{{ trigger.event.data.command }}'
prior_brightness: '{{ brightness | default }}'
brightness_up: '{{ (prior_brightness|int) + 25 }}'
brightness_down: '{{ (prior_brightness|int) - 25 }}'
- choose:
- conditions:
# Short Button Press - Light On, Brightness Up
- '{{ command == ''remote_button_short_press'' }}'
- '{{ brightness_up <= 255 }}'
sequence:
- service: light.turn_on
target: '{{ selected_light }}'
data:
brightness: '{{ brightness_up }}'
- conditions:
# Short Button Press - Light On, Brightness Up (but max of 255)
- '{{ command == ''remote_button_short_press'' }}'
- '{{ brightness_up > 255 }}'
sequence:
- service: light.turn_on
target: '{{ selected_light }}'
data:
brightness: '255'
- conditions:
# Double Button Press - Brightness Down
- '{{ command == ''remote_button_double_press'' }}'
- '{{ brightness_down > 0 }}'
sequence:
- service: light.turn_on
target: '{{ selected_light }}'
data:
brightness: '{{ brightness_down }}'
- conditions:
# Double Button Press - Brightness Down (but turn off at zero)
- '{{ command == ''remote_button_double_press'' }}'
- '{{ brightness_down <= 0 }}'
sequence:
- service: light.turn_off
target: '{{ selected_light }}'
- conditions:
# Long Button Press - Toggle Light
- '{{ command == ''remote_button_long_press'' }}'
sequence:
- service: light.toggle
target: '{{ selected_light }}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment