-
Notifications
You must be signed in to change notification settings - Fork 14
/
dimwithme.groovy
118 lines (106 loc) · 3.37 KB
/
dimwithme.groovy
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
/**
* dim-with-me.app.groovy
* Dim With Me
*
* Author: [email protected]
* Date: 2013-11-12
*/
/**
* App Name: Dim With Me
* lgk 2020 port to hubitat
* Author: Todd Wackford
* Date: 2013-11-12
* Version: 0.2
*
* Use this program with a virtual dimmer as the master for best results.
*
* This app lets the user select from a list of dimmers to act as a triggering
* master for other dimmers or regular switches. Regular switches come on
* anytime the master dimmer is on or dimmer level is set to more than 0%.
* of the master dimmer.
*
******************************************************************************
* Changes
******************************************************************************
*
* Change 1: 2014-10-22 (wackford)
* Fixed bug in setlevelwhen on/off was coming in
*
* Change 2: 2014-11-01 (wackford)
* added subscription to switch.level event. Shouldn't change much
* but some devices only sending level event and not setLevel.
*
******************************************************************************
Other Info: Special thanks to Danny Kleinman at ST for helping me get the
state stuff figured out. The Android state filtering had me
stumped.
*
******************************************************************************
*/
// Automatically generated. Make future change here.
definition(
name: "Dim With Me",
namespace: "wackware",
author: "[email protected]",
description: "Follows the dimmer level of another dimmer",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png"
)
preferences {
section("When this...") {
input "masters", "capability.switchLevel",
multiple: false,
title: "Master Dimmer Switch...",
required: true
}
section("Then these will follow with on/off...") {
input "slaves2", "capability.switch",
multiple: true,
title: "Slave On/Off Switch(es)...",
required: false
}
section("And these will follow with dimming level...") {
input "slaves", "capability.switchLevel",
multiple: true,
title: "Slave Dimmer Switch(es)...",
required: true
}
}
def installed()
{
subscribe(masters, "switch.on", switchOnHandler)
subscribe(masters, "switch.off", switchOffHandler)
subscribe(masters, "switch.setLevel", switchSetLevelHandler)
subscribe(masters, "switch", switchSetLevelHandler)
}
def updated()
{
unsubscribe()
subscribe(masters, "switch.on", switchOnHandler)
subscribe(masters, "switch.off", switchOffHandler)
subscribe(masters, "switch.setLevel", switchSetLevelHandler)
subscribe(masters, "switch", switchSetLevelHandler)
log.info "subscribed to all of switches events"
}
def switchSetLevelHandler(evt)
{
if ((evt.value == "on") || (evt.value == "off" ))
return
def level = evt.value.toFloat()
level = level.toInteger()
log.info "switchSetLevelHandler Event: ${level}"
slaves?.setLevel(level)
}
def switchOffHandler(evt) {
log.info "switchoffHandler Event: ${evt.value}"
slaves?.off()
slaves2?.off()
}
def switchOnHandler(evt) {
log.info "switchOnHandler Event: ${evt.value}"
def dimmerValue = masters.latestValue("level") //can be turned on by setting the level
slaves?.on()
slaves2?.on()
}