Logs showing problem:
Code of application "Night Light":
/*
* Night Light switch controller
*
* This controls a Kasa TP-Link smart color bulb to act as a nightlight during the night
* The switch is expected to be an on-off pushbutton that controls the on/off state of the bulb
* Night time variable is a Hub Variable that is set true at night, and false during the day.
* Use a couple of rules in Rule Machine to switch it at sunrise and sunset.
* The bulb is the light bulb to control. As written, this works with Kasa TP-Link bulbs,
* connected via the Kasa Integration package. You may well need to change controlBulb()
* at the bottom to work with other bulbs. It should be obvious what goes where.
* Nightlight colors are the HSL for the nightlight setting. This is very Kasa specific and
* might well need changing for other bulbs. In particular a white only LED bulb might only
* have a level setting. You'll need to adjust as needed for your setup.
*/
import groovy.transform.Field
@Field final int ON_BUTTON = 1
@Field final int OFF_BUTTON = 2
definition(
name: "Night Light",
namespace: "dgnuff",
author: "David Goodenough",
description: "Smart LED nightlight controller",
category: "Utility",
iconUrl: "",
iconX2Url: ""
)
preferences
{
section("Switch to read:")
{
input "theswitch", "capability.pushableButton", required: true, title: "Select"
}
section("Night Time variable:")
{
input "nighttime", "capability.sensor", required: true, title: "Select"
}
section("Night light to control:")
{
input "theNightlight", "capability.colorControl", required: true, title: "Select"
}
section("On/off lights to control:")
{
input "theOnOfflights", "capability.colorControl", required: false, multiple: true, title: "Select"
}
section("Nightlight color:")
{
input "nightLightHue", "int", title: "Hue", required: true, range: "0..100"
input "nightLightSaturation", "int", title: "Saturation", required: true, range: "0..100"
input "nightLightLevel", "int", title: "Level", required: true, range: "0..100"
}
}
def installed()
{
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated()
{
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize()
{
subscribe(theswitch, "pushed", pushHandler)
subscribe(theswitch, "held", pushHandler)
subscribe(nighttime, "variable", nightHandler)
state.isOn = false
}
def pushHandler(evt)
{
log.debug("pushHandler called button $evt.value")
def isOn = state.isOn;
state.isOn = evt.value.toInteger() == ON_BUTTON
def newIsOn = state.isOn
log.debug("pushHandler says isOn changed from $isOn to $newIsOn")
controlBulbs()
}
def nightHandler(evt)
{
log.debug "nightHandler called"
runIn(5, "controlBulbs")
}
def controlBulbs()
{
String isNightStr = nighttime.currentValue("variable")
boolean isNight = isNightStr == "true"
theOnOfflights.each{ bulb -> controlBulb(bulb, true, isNight) }
controlBulb(theNightlight, false, isNight)
}
def controlBulb(bulb, isOnOff, isNight)
{
log.debug "controlNightBulb() isOn $state.isOn isNight $isNight"
if (state.isOn)
{
log.debug "controlNightBulb on"
bulb.setColorTemperature(2700, 100, 0)
}
else if (isNight && !isOnOff)
{
log.debug "controlNightBulb night $nightLightHue, $nightLightSaturation, $nightLightLevel"
Map color =
[
hue: nightLightHue.toInteger(),
saturation: nightLightSaturation.toInteger(),
level: nightLightLevel.toInteger()
]
bulb.setColor(color)
}
else
{
log.debug "controlNightBulb off"
bulb.off()
}
}
That should be enough to reproduce the issue, assuming it can be reproduced. You might want to fiddle with the logic in controlBulb()
to make it work with other bulbs, so far the only ones I've tried are TP-Link Kasa KL125's, mostly because that's all I have at the moment.
Also, I find that Hue 45, Saturation 100 and Level 2 are reasonable parameters for nightlight mode, your actual mileage may vary.
"Test Switch" is a Zooz ZEN71 switch, I've got the "Zooz ZEN Switch Advanced" driver by jtp10181 installed, but I'm not sure if that's picking up the switch, I may be using the generic Z-Wave driver instead. It shouldn't make any difference, all I want to do is detect when the paddles on the switch are pressed, nothing fancy at all.
The logs show the problem. As can be seen in the App code, I've subscribed to "pushed" and "held" events for "Test Switch". There are info lines in the log showing "Test Switch" being turned on and off, these correspond to presses on the two paddles. However the log.debug()
call at the top of pushHandler(evt)
is never invoked, meaning my handler isn't getting called.
The weird thing is that if I use a ZEN34 remote switch with Zooz's own "Zooz Remote Switch ZEN34 Advanced" driver, everything works correctly.
So what's the difference between the ZEN34 that works, and the ZEN71 that doesn't? And how can I force the ZEN71 to use jtp10181's driver?