If you're interested in figuring out why your driver doesn't work, my guess is that all capability attributes (for capability "Switch"
, this would be just the switch
attribute) were not initialized to a valid value. On the device page, you can tell from whether the "Current States" section shows anything for this attribute. The Google Home integration seems to reject devices that don't have a valid value for some or all attributes that are required by devices of capabilities that it supports.
Something like this works for me as-is, but you could also just manually run "On" or "Off" on your switch from the device page to populate the attribute with a valid value. I'm just setting this one to "off" on installation (by running that command, but sendEvent
directly would also work):
/**
* Basic Virtual Switch Driver
*/
metadata {
definition (name: "Virtual Switch TEST", namespace: "Test", author: "Test") {
capability "Switch"
}
}
void on() {
sendEvent(name: "switch", value: "on")
}
void off() {
sendEvent(name: "switch", value: "off")
}
void installed() {
off()
}
void updated() {
}
But to second @aaiyar, Hubitat already has a built-in Virtual Switch driver that should do everything and more (it has auto-off built in, for example) compared to the above one. Like the above, it would work with Google Home. I don't see any mention of what real-world device you're talking about, but sometimes you can use virtual switches as workarounds for integrating devices that don't integrate directly (via another service like Alexa, GH, or IFTTT), so I assume that's what you're doing. No soldering required for virtual Hubitat devices, but maybe something for the real-world device?
PS - I'm assuming this isn't the problem (and it might not even save as such), but capability "Switch"
also has a lowercase "C" in "capability." It's generally most helpful to share the code you're working with if you are asking for help on it, but I'm guessing the problem is the above and not this.