Instantly share code, notes, and snippets.
Last active
February 23, 2021 02:55
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save yuri-vashchenko/de7e477b47b6cf4dd842cd30865eddbb to your computer and use it in GitHub Desktop.
Control Yeelight 650 ceiling light with Xiaomi Wireless Button (MQTT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Control Yeelight 650 with Xiaomi Button | |
source_url: https://gist.github.com/yuri-vashchenko/de7e477b47b6cf4dd842cd30865eddbb | |
description: > | |
Control Yeelight 650 ceiling light with Xiaomi button: | |
- Single press: If the night light or main light is on, turns if off, otherwise turns on last active mode (night light or main light) | |
- Double press: Toggles main/night light; If night light is on, switches it to main light and vice versa. | |
- Long press: User action. In my case it triggers LED strip on/off. | |
Required inputs: | |
- Trigger Entity (Button) | |
- Mainlight entity (Yeelight 650 Main light entity) | |
- Nightlight entity (Yeelignt 650 Nightlight entity) | |
- Mode entity (Yeelight 650 Nightlight binary sensor | |
Optional inputs: | |
- Action on long press (default is 'none' - do nothing) | |
- Ambilight Entity (Yeelight 650 Ambilight entity, will turn on/off at the same time with main/night light) | |
- Enabling Entity (the automation will execute only when enabling_entity is in Enabling Entity State) | |
- Enabling Entity State (see Enabling Entity above) | |
domain: automation | |
input: | |
trigger_entity: | |
name: Trigger Entity | |
description: When trigger entity enters trigger entity state (see below) it will trigger light change | |
selector: | |
entity: | |
mainlight_entity: | |
name: mainlight_entity | |
description: Target Entity (Yeelight 650 Main light entity) | |
selector: | |
entity: | |
domain: light | |
nightlight_entity: | |
name: nightlight_entity | |
description: Nightlight Entity (Yeelight 650 Night light entity) | |
selector: | |
entity: | |
domain: light | |
mode_entity: | |
name: mode_entity | |
description: Mode Entity (Yeelight 650 Nightlight binary sensor) | |
selector: | |
entity: | |
domain: binary_sensor | |
ambilight_entity: | |
name: (Optional) Ambilight entity | |
description: Ambilight entity will be turened on/off with main or nighlight entity | |
default: [] | |
selector: | |
entity: | |
domain: light | |
hold_action: | |
name: (Optional) Action to execute on holding button | |
description: This optional action will execute on long button press (see trigger_entity and trigger_entity_state3) | |
default: [] | |
selector: | |
action: | |
enabling_entity: | |
name: (Optional) Enabling entity | |
description: If this entity's state is set to enable entity state (see below) automation will trigger. | |
This may be used to make automation triggering based on other entity state | |
default: | |
selector: | |
entity: {} | |
enabling_entity_state: | |
name: (Optional) Enabling entity state | |
description: If enabling entity is in this state the automation will trigger | |
default: 'on' | |
selector: | |
entity: | |
domain: input_text | |
variables: | |
trigger_entity: !input trigger_entity | |
trigger_entity_state_value: '{{ states[trigger_entity].state }}' | |
mainlight_entity: !input mainlight_entity | |
nightlight_entity: !input nightlight_entity | |
mode_entity: !input mode_entity | |
toggle_entity: > | |
{% if states[mode_entity].state == 'off' %} | |
{{mainlight_entity}} | |
{% else %} | |
{{nightlight_entity}} | |
{% endif %} | |
light_mode: > | |
{% if states[mode_entity].state == 'off' %} | |
moonlight | |
{% else %} | |
normal | |
{% endif %} | |
change_mode_entity: > | |
{% if states[mode_entity].state == 'on' %} | |
{{ mainlight_entity }} | |
{% else %} | |
{{ nightlight_entity }} | |
{% endif %} | |
ambilight_service: > | |
{% if states[mainlight_entity].state == 'off' and states[nightlight_entity].state == 'off' %} | |
light.turn_on | |
{% else %} | |
light.turn_off | |
{% endif %} | |
hold_action: !input 'hold_action' | |
enabling_entity: !input 'enabling_entity' | |
enabling_entity_state: !input 'enabling_entity_state' | |
trigger: | |
- platform: state | |
entity_id: !input trigger_entity | |
to: | |
- 'single' | |
- 'double' | |
- 'hold' | |
condition: '{{ enabling_entity == none or is_state(enabling_entity, enabling_entity_state) }}' | |
action: | |
- choose: | |
- conditions: '{{ trigger.to_state.state == ''single'' }}' | |
sequence: | |
- service: light.toggle | |
data_template: | |
entity_id: '{{ toggle_entity }}' | |
- service: '{{ambilight_service}}' | |
entity_id: !input ambilight_entity | |
- conditions: '{{ trigger.to_state.state == ''double'' }}' | |
sequence: | |
- service: yeelight.set_mode | |
data_template: | |
entity_id: '{{ mainlight_entity }}' | |
mode: '{{ light_mode }}' | |
- service: light.turn_on | |
entity_id: !input ambilight_entity | |
- conditions: | |
- '{{ hold_action != "" }}' | |
- '{{ trigger.to_state.state == ''hold'' }}' | |
sequence: !input hold_action | |
default: [] | |
mode: single | |
max_exceeded: silent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment