-
Notifications
You must be signed in to change notification settings - Fork 29
/
ha-switches.yaml
51 lines (50 loc) · 1.64 KB
/
ha-switches.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
name: ha-switches
doc: |-
A demo to link to switches. When the (parameter) triggerSwitch is
turned on, the (parameter) targetSwitch is turned on. When the
trigger is turned off, the target is turned off.
This spec assumes "home" machine with the "homeassistant" spec is
running. See cmd/mcrew/README.md.
paramspecs:
triggerSwitch:
doc: The Home Assistant entity_id for the triggering switch.
primitiveType: string
targetSwitch:
doc: The Home Assistant entity_id for the switch to change.
primitiveType: string
patternsyntax: json
nodes:
start:
branching:
type: message
branches:
- pattern: |
{"type":"event","event":{"data":{"service":"turn_on", "service_data":{"entity_id":"?triggerSwitch"}}}}
target: on
on:
action:
interpreter: ecmascript
source: |-
var target = _.bindings["?targetSwitch"];
_.out({to: {mid: "home"}, send: {type:"call_service", "domain":"switch","service": "turn_on","service_data":{"entity_id":target}}});
return _.bindings;
branching:
branches:
- target: waitForOff
waitForOff:
branching:
type: message
branches:
- pattern: |
{"type":"event","event":{"data":{"service":"turn_off", "service_data":{"entity_id":"?triggerSwitch"}}}}
target: off
off:
action:
interpreter: ecmascript
source: |-
var target = _.bindings["?targetSwitch"];
_.out({to: {mid: "home"}, send: {type:"call_service","domain":"switch","service": "turn_off","service_data":{"entity_id":target}}});
return _.bindings;
branching:
branches:
- target: start