To add to the above, this is the way pretty much any dimmer-type (bulb, etc.) driver on Hubitat works. Levels are generally reported in the range of 1-100 (or 1-99 for many Z-Wave devices--closer to Z-Wave spec). The "Set Level" command may take 0 as a level parameter but is generally equivalent to off()
--as you wrote and as I previously did above:
It should be noted that with some drivers, you may at least get to specify an arbitrary transition time with setLevel(0,...)
, unlike a plain off()
. (Actually, there are some oddities with either Hue or the Bridge API here, so I'm not sure I'd recommend it unless you consistently avoid plain on/off commands for this device in favor of "Set Level" for but on and off sides of things--the issue is with remembering the last level on the bulb side--but for most devices...).
On a related note, it should be also noted that, in the absence of pre-staging being enabled (which itself seems to sort of be deprecated in favor of a special command instead), a "Set Level" command will also turn on a device that is off--no explicit on()
needed.
Again, this may vary by driver, but that's generally what happens. The takeaway pretty much everywhere, though, is that the switch
and level
attributes are not related. If you want to test the on/off state, use switch
.
I still agree with your point, but if anyone wants to know: this is actually also how Hue's v1 API, which Hubitat's built-in integration uses, works. Brightness values can be set from 1-254 (note that 0 is not an option--and they're also in "raw" Zigbee values here that Hubitat scales 1-100, per convention, though that's beside the point). Additionally, the API reports brightness (the bri
attribute in the API, which corresponds to brightness/level, as its name suggests) as the last known value when on, with the on/off state being reported via a separate attribute. Here are some relevant parts of the state for one of my currently-off bulbs now (last dimmed to 10% before turning off):
I think this is generally how Zigbee devices work, too; the Hue v1 API is a thin wrapper around this with minimal abstraction from what I can tell. SmartThings also seems to have originated as mostly a Zigbee-oriented platform (given that they still use Zigbee terminology like "clusters" to describe Z-Wave features like "command classes"), and this might have been why they made that choice.
It's all really beside the point, I guess, since a driver can choose to abstract real-world details into whatever presentation on the hub it wants (and why I still agree with your caution). This is just convention for how Hubitat does it--regardless of underlying protocol, as far as any device/driver I can think of goes (and again, it's not the only platform I'm aware that does it this way). Just have to know what to look for! And for this purpose, it's switch
.