|
|
|
@@ -369,7 +369,6 @@ def addBulbs() {
|
|
|
|
if (d) {
|
|
|
|
if (d) {
|
|
|
|
log.debug "created ${d.displayName} with id $dni"
|
|
|
|
log.debug "created ${d.displayName} with id $dni"
|
|
|
|
d.completedSetup = true
|
|
|
|
d.completedSetup = true
|
|
|
|
d.refresh()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.debug "$dni in not longer paired to the Hue Bridge or ID changed"
|
|
|
|
log.debug "$dni in not longer paired to the Hue Bridge or ID changed"
|
|
|
|
@@ -426,9 +425,11 @@ def addBridge() {
|
|
|
|
d.completedSetup = true
|
|
|
|
d.completedSetup = true
|
|
|
|
log.debug "created ${d.displayName} with id ${d.deviceNetworkId}"
|
|
|
|
log.debug "created ${d.displayName} with id ${d.deviceNetworkId}"
|
|
|
|
def childDevice = getChildDevice(d.deviceNetworkId)
|
|
|
|
def childDevice = getChildDevice(d.deviceNetworkId)
|
|
|
|
|
|
|
|
childDevice?.sendEvent(name: "status", value: "Online")
|
|
|
|
|
|
|
|
childDevice?.sendEvent(name: "DeviceWatch-DeviceStatus", value: "online", displayed: false, isStateChange: true)
|
|
|
|
updateBridgeStatus(childDevice)
|
|
|
|
updateBridgeStatus(childDevice)
|
|
|
|
childDevice.sendEvent(name: "idNumber", value: idNumber)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
childDevice?.sendEvent(name: "idNumber", value: idNumber)
|
|
|
|
if (vbridge.value.ip && vbridge.value.port) {
|
|
|
|
if (vbridge.value.ip && vbridge.value.port) {
|
|
|
|
if (vbridge.value.ip.contains(".")) {
|
|
|
|
if (vbridge.value.ip.contains(".")) {
|
|
|
|
childDevice.sendEvent(name: "networkAddress", value: vbridge.value.ip + ":" + vbridge.value.port)
|
|
|
|
childDevice.sendEvent(name: "networkAddress", value: vbridge.value.ip + ":" + vbridge.value.port)
|
|
|
|
@@ -705,10 +706,14 @@ def doDeviceSync(){
|
|
|
|
private void updateBridgeStatus(childDevice) {
|
|
|
|
private void updateBridgeStatus(childDevice) {
|
|
|
|
// Update activity timestamp if child device is a valid bridge
|
|
|
|
// Update activity timestamp if child device is a valid bridge
|
|
|
|
def vbridges = getVerifiedHueBridges()
|
|
|
|
def vbridges = getVerifiedHueBridges()
|
|
|
|
def vbridge = vbridges.find {"${it.value.mac}".toUpperCase() == childDevice?.device?.deviceNetworkId?.toUpperCase()}
|
|
|
|
def vbridge = vbridges.find {
|
|
|
|
|
|
|
|
"${it.value.mac}".toUpperCase() == childDevice?.device?.deviceNetworkId?.toUpperCase()
|
|
|
|
|
|
|
|
}
|
|
|
|
vbridge?.value?.lastActivity = now()
|
|
|
|
vbridge?.value?.lastActivity = now()
|
|
|
|
if(vbridge) {
|
|
|
|
if (vbridge && childDevice?.device?.currentValue("status") == "Offline") {
|
|
|
|
|
|
|
|
log.debug "$childDevice is back Online"
|
|
|
|
childDevice?.sendEvent(name: "status", value: "Online")
|
|
|
|
childDevice?.sendEvent(name: "status", value: "Online")
|
|
|
|
|
|
|
|
childDevice?.sendEvent(name: "DeviceWatch-DeviceStatus", value: "online", displayed: false, isStateChange: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -730,16 +735,24 @@ private void checkBridgeStatus() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (it.value.lastActivity < time) { // it.value.lastActivity != null &&
|
|
|
|
if (it.value.lastActivity < time) { // it.value.lastActivity != null &&
|
|
|
|
log.warn "Bridge $it.value.idNumber is Offline"
|
|
|
|
if (d.currentStatus == "Online") {
|
|
|
|
|
|
|
|
log.warn "$d is Offline"
|
|
|
|
d.sendEvent(name: "status", value: "Offline")
|
|
|
|
d.sendEvent(name: "status", value: "Offline")
|
|
|
|
|
|
|
|
d.sendEvent(name: "DeviceWatch-DeviceStatus", value: "offline", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
|
|
|
|
state.bulbs?.each {
|
|
|
|
Calendar currentTime = Calendar.getInstance()
|
|
|
|
it.value.online = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
getChildDevices().each {
|
|
|
|
getChildDevices().each {
|
|
|
|
it.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", isStateChange: true, displayed: false)
|
|
|
|
def id = getId(it)
|
|
|
|
|
|
|
|
if (state.bulbs[id]?.online == true) {
|
|
|
|
|
|
|
|
state.bulbs[id]?.online = false
|
|
|
|
|
|
|
|
state.bulbs[id]?.unreachableSince = currentTime.getTimeInMillis()
|
|
|
|
|
|
|
|
it.sendEvent(name: "DeviceWatch-DeviceStatus", value: "offline", displayed: false, isStateChange: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (d.currentStatus == "Offline") {
|
|
|
|
|
|
|
|
log.debug "$d is back Online"
|
|
|
|
|
|
|
|
d.sendEvent(name: "DeviceWatch-DeviceStatus", value: "online", displayed: false, isStateChange: true)
|
|
|
|
d.sendEvent(name: "status", value: "Online")//setOnline(false)
|
|
|
|
d.sendEvent(name: "status", value: "Online")//setOnline(false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -943,13 +956,10 @@ private handleCommandResponse(body) {
|
|
|
|
updates.each { childDeviceNetworkId, params ->
|
|
|
|
updates.each { childDeviceNetworkId, params ->
|
|
|
|
def device = getChildDevice(childDeviceNetworkId)
|
|
|
|
def device = getChildDevice(childDeviceNetworkId)
|
|
|
|
def id = getId(device)
|
|
|
|
def id = getId(device)
|
|
|
|
// If device is offline, then don't send events which will update device watch
|
|
|
|
|
|
|
|
if (isOnline(id)) {
|
|
|
|
|
|
|
|
sendBasicEvents(device, "on", params.on)
|
|
|
|
sendBasicEvents(device, "on", params.on)
|
|
|
|
sendBasicEvents(device, "bri", params.bri)
|
|
|
|
sendBasicEvents(device, "bri", params.bri)
|
|
|
|
sendColorEvents(device, params.xy, params.hue, params.sat, params.ct)
|
|
|
|
sendColorEvents(device, params.xy, params.hue, params.sat, params.ct)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -984,36 +994,35 @@ private handlePoll(body) {
|
|
|
|
def device = bulbs.find { it.deviceNetworkId == "${app.id}/${bulb.key}" }
|
|
|
|
def device = bulbs.find { it.deviceNetworkId == "${app.id}/${bulb.key}" }
|
|
|
|
if (device) {
|
|
|
|
if (device) {
|
|
|
|
if (bulb.value.state?.reachable) {
|
|
|
|
if (bulb.value.state?.reachable) {
|
|
|
|
if (state.bulbs[bulb.key]?.online == false) {
|
|
|
|
if (state.bulbs[bulb.key]?.online == false || state.bulbs[bulb.key]?.online == null) {
|
|
|
|
// light just came back online, notify device watch
|
|
|
|
// light just came back online, notify device watch
|
|
|
|
def lastActivity = now()
|
|
|
|
device.sendEvent(name: "DeviceWatch-DeviceStatus", value: "online", displayed: false, isStateChange: true)
|
|
|
|
device.sendEvent(name: "deviceWatch-status", value: "ONLINE", description: "Last Activity is on ${new Date((long) lastActivity)}", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
log.debug "$device is Online"
|
|
|
|
log.debug "$device is Online"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Mark light as "online"
|
|
|
|
// Mark light as "online"
|
|
|
|
state.bulbs[bulb.key]?.unreachableSince = null
|
|
|
|
state.bulbs[bulb.key]?.unreachableSince = null
|
|
|
|
state.bulbs[bulb.key]?.online = true
|
|
|
|
state.bulbs[bulb.key]?.online = true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (state.bulbs[bulb.key]?.unreachableSince == null) {
|
|
|
|
|
|
|
|
// Store the first time where device was reported as "unreachable"
|
|
|
|
|
|
|
|
state.bulbs[bulb.key]?.unreachableSince = currentTime.getTimeInMillis()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.bulbs[bulb.key]?.online || state.bulbs[bulb.key]?.online == null) {
|
|
|
|
|
|
|
|
// Check if device was "unreachable" for more than 11 minutes and mark "offline" if necessary
|
|
|
|
|
|
|
|
if (state.bulbs[bulb.key]?.unreachableSince < time11.getTimeInMillis() || state.bulbs[bulb.key]?.online == null) {
|
|
|
|
|
|
|
|
log.warn "$device went Offline"
|
|
|
|
|
|
|
|
state.bulbs[bulb.key]?.online = false
|
|
|
|
|
|
|
|
device.sendEvent(name: "DeviceWatch-DeviceStatus", value: "offline", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.warn "$device may not reachable by Hue bridge"
|
|
|
|
|
|
|
|
}
|
|
|
|
// If user just executed commands, then do not send events to avoid confusing the turning on/off state
|
|
|
|
// If user just executed commands, then do not send events to avoid confusing the turning on/off state
|
|
|
|
if (!state.updating) {
|
|
|
|
if (!state.updating) {
|
|
|
|
sendBasicEvents(device, "on", bulb.value?.state?.on)
|
|
|
|
sendBasicEvents(device, "on", bulb.value?.state?.on)
|
|
|
|
sendBasicEvents(device, "bri", bulb.value?.state?.bri)
|
|
|
|
sendBasicEvents(device, "bri", bulb.value?.state?.bri)
|
|
|
|
sendColorEvents(device, bulb.value?.state?.xy, bulb.value?.state?.hue, bulb.value?.state?.sat, bulb.value?.state?.ct, bulb.value?.state?.colormode)
|
|
|
|
sendColorEvents(device, bulb.value?.state?.xy, bulb.value?.state?.hue, bulb.value?.state?.sat, bulb.value?.state?.ct, bulb.value?.state?.colormode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (state.bulbs[bulb.key]?.unreachableSince == null) {
|
|
|
|
|
|
|
|
// Store the first time where device was reported as "unreachable"
|
|
|
|
|
|
|
|
state.bulbs[bulb.key]?.unreachableSince = currentTime.getTimeInMillis()
|
|
|
|
|
|
|
|
} else if (state.bulbs[bulb.key]?.online) {
|
|
|
|
|
|
|
|
// Check if device was "unreachable" for more than 11 minutes and mark "offline" if necessary
|
|
|
|
|
|
|
|
if (state.bulbs[bulb.key]?.unreachableSince < time11.getTimeInMillis()) {
|
|
|
|
|
|
|
|
log.warn "$device went Offline"
|
|
|
|
|
|
|
|
state.bulbs[bulb.key]?.online = false
|
|
|
|
|
|
|
|
device.sendEvent(name: "DeviceWatch-DeviceOffline", value: "offline", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.warn "$device may not reachable by Hue bridge"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return []
|
|
|
|
return []
|
|
|
|
@@ -1180,22 +1189,6 @@ def setColor(childDevice, huesettings) {
|
|
|
|
return "Setting color to $value"
|
|
|
|
return "Setting color to $value"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def ping(childDevice) {
|
|
|
|
|
|
|
|
if (childDevice.device?.deviceNetworkId?.equalsIgnoreCase(selectedHue)) {
|
|
|
|
|
|
|
|
if (childDevice.device?.currentValue("status")?.equalsIgnoreCase("Online")) {
|
|
|
|
|
|
|
|
childDevice.sendEvent(name: "deviceWatch-ping", value: "ONLINE", description: "Hue Bridge is reachable", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
return "Bridge is Online"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "Bridge is Offline"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (isOnline(getId(childDevice))) {
|
|
|
|
|
|
|
|
childDevice.sendEvent(name: "deviceWatch-ping", value: "ONLINE", description: "Hue Light is reachable", displayed: false, isStateChange: true)
|
|
|
|
|
|
|
|
return "Device is Online"
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return "Device is Offline"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private getId(childDevice) {
|
|
|
|
private getId(childDevice) {
|
|
|
|
if (childDevice.device?.deviceNetworkId?.startsWith("HUE")) {
|
|
|
|
if (childDevice.device?.deviceNetworkId?.startsWith("HUE")) {
|
|
|
|
return childDevice.device?.deviceNetworkId[3..-1]
|
|
|
|
return childDevice.device?.deviceNetworkId[3..-1]
|
|
|
|
@@ -1785,3 +1778,4 @@ def hsvToHex(hue, sat, value = 100){
|
|
|
|
|
|
|
|
|
|
|
|
return "#$r1$g1$b1"
|
|
|
|
return "#$r1$g1$b1"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|