/
cube.yaml
134 lines (127 loc) · 4.56 KB
/
cube.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
#-
# _
# ___ _ _| |__ ___
# / __| | | | '_ \ / _ \
# | (__| |_| | |_) | __/
# \___|\__,_|_.__/ \___|
#
#
#- from github.com/basnijholt/home-assistant-config
- alias: "Cube: perform operation"
mode: parallel
trigger:
platform: event
event_type: deconz_event
event_data:
id: mi_magic_cube
variables:
event: "{{ trigger.event.data.event }}"
condition: "{{ (event | string)[1:-1] == '00' }}"
action:
choose:
# Change cube mode by shifting on one side, or rotating from one side to another side
- conditions: >
{% set event = event | string %}
{% set correct_start = event[:3] in ("100", "200", "300") %}
{% set first_last_different = event[0] != event[-1] %}
{% set last_is_zero = event[-1] == 0 %}
{{ correct_start and (first_last_different or last_is_zero) }}
sequence:
- service: input_select.select_option
entity_id: input_select.cube_mode
data:
option: >
{% set event = event | string %}
{{ {"100": "Volume", "200": "Hue", "300": "Brightness"}[event[:3]] }}
- condition: state
entity_id: media_player.tv
state: "on"
- service: notify.tv
data:
message: >
Cube set to {{ states("input_select.cube_mode") }}
# Shuffle Spotify song by shaking cube
- conditions:
- "{{ event == 7007 }}"
- "{{ is_state_attr('media_player.spotify', 'source', 'LS50 Wireless') }}"
sequence:
- service: media_player.shuffle_set
entity_id: media_player.spotify
data:
shuffle: true
- service: media_player.media_next_track
entity_id: media_player.spotify
# Pause and play Spotify song by tapping cube on side 1
- conditions:
- "{{ event in (1001, 2002, 3003, 4004, 5005, 6006) }}"
- "{{ is_state_attr('media_player.spotify', 'source', 'LS50 Wireless') }}"
sequence:
service: media_player.media_play_pause
entity_id: media_player.spotify
# Start music by throwing the cube
- conditions: "{{ event == 7008 }}"
sequence:
service: script.start_spotify_playlist_of_nearest_person
data:
source: LS50 Wireless
entity_id: media_player.kef_ls50
- alias: "Cube: rotate the cube"
trigger:
platform: event
event_type: deconz_event
event_data:
id: mi_magic_cube
variables:
event: "{{ trigger.event.data.event }}"
condition: "{{ (event | string)[1:-1] != '00' or event < 0 }}"
action:
choose:
- conditions: # Change hue of living room lights
condition: state
entity_id: input_select.cube_mode
state: "Hue"
sequence:
- variables:
hue_sat: "{{ state_attr('light.sphere_1', 'hs_color') or [30, 56] }}"
- service: light.turn_on
entity_id: light.living_room_lights
data:
hs_color:
- >
{% set delta = event / 200 %}
{% set new_hue = [([0, (hue_sat[0] + delta)]|max), 360]|min %}
{{ new_hue|round(3) }}
- "{{ hue_sat[1] }}"
- conditions: # Change brightness of living room lights
condition: state
entity_id: input_select.cube_mode
state: "Brightness"
sequence:
service: light.turn_on
entity_id: light.living_room_lights
data:
brightness: >
{% set brightness = state_attr('light.sphere_1', 'brightness') %}
{% set delta = event / 450 %}
{% set new_brightness = [([0, (brightness + delta)]|max), 255]|min %}
{{ new_brightness|int }}
- conditions: # Change speaker volume
condition: state
entity_id: input_select.cube_mode
state: "Volume"
sequence:
- service: media_player.volume_set
entity_id: media_player.kef_ls50
data: # 90 deg is 10%
volume_level: >
{% set max_change = 0.15 %}
{% set dV = [event / 100 / 900, max_change] | min %}
{{ (states.media_player.kef_ls50.attributes.volume_level + dV)|round(2) }}
- condition: state
entity_id: media_player.tv
state: "on"
- service: notify.tv
data:
message: >
Volume set to {{ state_attr("media_player.kef_ls50", "volume_level") }}