-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_contollers_script.yaml
106 lines (95 loc) · 3.79 KB
/
update_contollers_script.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
alias: UpdateLevitonControllers
variables:
dev_db: |
{#
UpdateLevitonControllers
Toggles the state of the switches/lights controlled by
the network of VRCZ4 controllers based on device events.
Also updates controller LEDs to match the state of the
switches/lights.
Can be called in 3 ways:
1. When a controller button is pressed.
Expected parameters:
- ctrl_device_id(string) - zwave device_id of the controller.
- value(int) - 1-4 if "On" side of the corresponding
button was pressed. 5-8 if "Off" side was pressed.
2. When a switch/light is toggled (physically or in UI)
Expected parameters:
- switch_entity_id(string) - entity name of the toggled
switch/light.
3. When controller level button is pressed.
Expected parameters:
- ctrl_device_id(string) - zwave device_id of the controller.
- direction(string) - "up" or "down"
(this is equivalent to "On" operation on the last controller
button, followed by +/-40 brightness adjustment)
Setup:
Define below 'dev_db' dictionary of lists to represent the
mapping of the controller buttons to the corresponding
switches/lights in your network.
Element 0 in each list corresponds to the 1st button,
element 1 to the 2nd and so on. Up to 4 elements per list.
E.g.
{
'abc': ['switch.entity1', 'light.entity2'],
'xyz': ['light.entity3', 'light.entity2', 'switch.entity4']
}
represents a network of 2 controllers with device ids 'abc' and 'xyz'.
Controller 'abc' has buttons 1 and 2 assigned to entity1 and entity2.
Controller 'xyz' has buttons 1, 2, 3 assigend to entity3, entity2
and entity4 in that order.
#}
{{ >>> DEFINE DICTIONARY HERE <<< }}
sequence:
- if:
- condition: template
alias: Is this is a controller key press?
value_template: "{{ ctrl_device_id is defined }}"
then:
- choose:
- conditions:
- condition: template
alias: Is this a Level key press?
value_template: "{{ direction is defined }}"
sequence:
- variables:
switch_entity_id: >
{{ dev_db[ctrl_device_id][int(states('input_number.' +
ctrl_device_id))] }}
- service: script.switchturnon
data:
switch_entity_id: "{{switch_entity_id}}"
offset: "{{ 40 if direction == 'up' else -40 }}"
- conditions:
- condition: template
alias: Is this is an On key press?
value_template: "{{ value < 5 }}"
sequence:
- service: script.switchturnon
data:
switch_entity_id: "{{dev_db[ctrl_device_id][value - 1]}}"
- service: input_number.set_value
data:
value: "{{value - 1}}"
target:
entity_id: input_number.{{ctrl_device_id}}
- conditions:
- condition: template
alias: Is this is an Off key press?
value_template: "{{ value > 4 }}"
sequence:
- service: script.switchturnoff
data:
switch_entity_id: "{{dev_db[ctrl_device_id][value - 5]}}"
- service: input_number.set_value
data:
value: "{{value - 5}}"
target:
entity_id: input_number.{{ctrl_device_id}}
else:
- service: script.updatelevitonleds
data:
dev_db: "{{dev_db}}"
switch_entity_id: "{{switch_entity_id}}"
mode: queued
icon: mdi:microsoft-xbox-controller-menu