Skip to content

Commit

Permalink
Merge pull request #6 from rafaelborja/v0.2
Browse files Browse the repository at this point in the history
V0.2
  • Loading branch information
rafaelborja authored Aug 18, 2020
2 parents 01bae3a + a9c61d3 commit 7c9dccd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 41 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ To control lights device child, simply use the command "Ok Google, set Fan **Lig


### Validation scenario
#### V.01
This device handler was tested using Samsung Connect Home Pro (Smartthings V2 Hub) with Firmware version 000.027.00010 in a set up with +10 Zigbee devices. I used two King Of Fans, Inc. model HDC52EastwindFan at the same network.
Google assistant commands were validated using Google Home app v 2.19.1.18 running under Android Oreo, Google Nest mini running firmware 191160 and Google Nest Hub running firmware 191160. All commands were tested using US-English language set.

#### V.02
This device handler was tested using SmartThings WiFi, Plume US (Smartthings V3 Hub) with Firmware version 000.029.00009 in a set up with +10 Zigbee devices. I used two King Of Fans, Inc. model HDC52EastwindFan at the same network.
Google assistant commands were validated using Google Home app v 2.26.1.8 running under Android Oreo, Google Nest mini running firmware 191160 and Google Nest Hub running firmware 191160. All commands were tested using US-English language set.


### Known issues
- Random delays to update child device.
- Excess message logging and events generated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ metadata {

def parse(String description) {
log.info "parse($description)"
// TODO description 'on/off: 1' or 'on/off: 0' can represent both light on/of or power on/off on remote control. After this event fan speed and state must be retrieved and updated
def event = zigbee.getEvent(description)


if (event) {
// "Sample 0104 0006 01 01 0000 00 D42D 00 00 0000 01 01 010086"

Expand All @@ -94,13 +97,9 @@ def parse(String description) {
it.device.deviceNetworkId == "${device.deviceNetworkId}-Light"
}
event.displayed = true
event.isStateChange = true
event.isStateChange = childDevice.isStateChange(event)

// TODO find right event
childDevice.createAndSendEvent(event)
// childDevice.createAndSendEvent(description)
childDevice.sendEvent(event)
// TODO not needed? childDevice.parse(description)

//send light events to light child device and update lightBrightness attribute
if(event.value != "on" && event.value != "off" && !useDimmerAsFanControl()) {
Expand Down Expand Up @@ -315,13 +314,6 @@ def off (physicalgraph.device.cache.DeviceDTO child) {
def childDevice = getChildDevices()?.find {
it.device.deviceNetworkId == "${device.deviceNetworkId}-Light"
}
if (childDevice) {
log.debug "Sending event to child $childDevice"
log.debug childDevice
childDevice.createAndSendEvent(name: "switch", value: "off", displayed: true, isStateChange: true) // childDevice.sendEvent(name: "device.switch", value: "off", displayed: true, isStateChange: true) +
// childDevice.sendEvent(name: "switch", value: "off", displayed: true, isStateChange: true) +
// childDevice.createAndSendEvent(name: "switch", value: "off", displayed: true, isStateChange: true)
}

lightOff(getEndpoint(child))
}
Expand All @@ -331,14 +323,6 @@ def on (physicalgraph.device.cache.DeviceDTO child) {

def childDevice = getChildDevices()?.find {
it.device.deviceNetworkId == "${device.deviceNetworkId}-Light"
}
if (childDevice) {
log.debug "Sending event to child $childDevice"
log.debug childDevice

childDevice.createAndSendEvent(name: "switch", value: "on", displayed: true, isStateChange: true) // childDevice.sendEvent(name: "device.switch", value: "on", displayed: true, isStateChange: true) +
//childDevice.sendEvent(name: "switch", value: "on", displayed: true, isStateChange: true) +

}

lightOn(getEndpoint(child))
Expand Down Expand Up @@ -388,7 +372,6 @@ def lightOn(String dni) {
log.debug childDevice
childDevice.sendEvent(name: "device.switch", value: "on", displayed: true, isStateChange: true)
childDevice.sendEvent(name: "switch", value: "on", displayed: true, isStateChange: true)
childDevice.createEvent(childDevice.createAndSendEvent(name: "switch", value: "on", displayed: true, isStateChange: true ))
}

return zigbee.on()
Expand All @@ -408,15 +391,13 @@ def lightOff(String id) {
log.debug childDevice
childDevice.sendEvent(name: "device.switch", value: "off", displayed: true, isStateChange: true)
childDevice.sendEvent(name: "switch", value: "off", displayed: true, isStateChange: true)
childDevice.createEvent(childDevice.createAndSendEvent(name: "switch", value: "off", displayed: true, isStateChange: true ))
}

return zigbee.off()


}


void childOn(String dni) {
log.debug "childOn(String ${dni})"
lightOn(null)
Expand All @@ -441,11 +422,8 @@ def lightLevel(val) {
if (childDevice) {
log.debug "Sending event to child"
log.debug childDevice
//childDevice.sendEvent(name: "device.value", value: val)
// childDevice.sendEvent(name: "device.switch", value: "on", isStatusChange: true)
childDevice.sendEvent(name: "switch", value: isDeviceOn? "on": "off", isStatusChange: true, display: true)
childDevice.sendEvent(name: "value", value: val, isStatusChange: true, display: true)
childDevice.createEvent(childDevice.createAndSendEvent(name: "level", value: value, isStatusChange: true, display: true))
}
}

Expand Down Expand Up @@ -498,19 +476,25 @@ def ping() {
def refresh(physicalgraph.device.cache.DeviceDTO child=null) {
log.info "refresh($child) called "

return zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.readAttribute(0x0202, 0x0000) + zigbee.readAttribute(0x0006, 0x0000) +
zigbee.readAttribute(0x0202, 0x0000) + zigbee.readAttribute(0x0202, 0x0001) + zigbee.readAttribute(0x0006, 0x0001) + zigbee.readAttribute(0x0006, 0x0000) +
zigbee.readAttribute(0x0008, 0x0004) + zigbee.readAttribute(0x0008, 0x0004)
log.trace "That's tthe refresh: ${zigbee.onOffRefresh() + zigbee.levelRefresh() + zigbee.readAttribute(0x0202, 0x0000) + zigbee.readAttribute(0x0006, 0x0000) + zigbee.readAttribute(0x0202, 0x0001) + zigbee.readAttribute(0x0008, 0x0004)}"
return zigbee.onOffRefresh() /* same as zigbee.readAttribute(0x0006, 0x0000) + */ +
zigbee.levelRefresh() +
zigbee.readAttribute(0x0202, 0x0000) +
zigbee.readAttribute(0x0006, 0x0000) +
zigbee.readAttribute(0x0202, 0x0001) +
zigbee.readAttribute(0x0008, 0x0004)
// + zigbee.readAttribute(0x0006, 0x0001) TODO Confirm it was the cause of blinking light

}

/**
* Returns true if dimmer will control fan speed (for Google Assistant, Alexa compatibility)
*/
def useDimmerAsFanControl() {
log.trace("useDimmerAsFanControl(): ${settings.dimmerControl}")
// Check fro dimmerAsFanControl == 1 for legacy reasons. TODO - Remove in future versions
return settings.dimmerControl == "Fan" || dimmerAsFanControl == 1

// Check for dimmerAsFanControl == 1 for legacy reasons. TODO - Remove in future versions
return settings.dimmerControl == "Fan" || dimmerAsFanControl == 1
}

/**
Expand Down Expand Up @@ -539,8 +523,6 @@ def dimmerLevelToSpeed(dimmerLevel) {
}




def raiseFanSpeed() {
setFanSpeed(Math.min((device.currentValue("fanSpeed") as Integer) + 1, 3))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,27 @@ void refresh() {
parent.childRefresh(device.deviceNetworkId)
}


def createAndSendEvent(map) {
log.debug "child[ ${device.deviceNetworkId} ].createAndSendEvent($map)"
results.each { name, value ->
sendEvent(name: name, value: value, displayed: true, isStateChange: true) // check if displayed: true, isStateChange: true is needed
}
return null
/**
* Returns true if event map values differs from devices values.
*/
def isStateChange(event) {
log.trace "[isStateChange](${eventChange})"

def eventChange = true;
switch(event['name']) {
case "switch":
eventChange = (event['value'] != null && event['value'] != device.currentValue("switch"))
break
case "level":
eventChange = (event['value'] != null && event['value'] != device.currentValue("level"))
break
default:
log.debug "[isStateChange] Unknown event: ${event}"
break;
}

log.trace "[isStateChange] ${eventChange}"
return eventChange
}

def parse(description) {
Expand Down

0 comments on commit 7c9dccd

Please sign in to comment.