I'm writing a custom driver for a mimolite connected to one of my automatic transfer switches to show the current connected source. It seems the PowerSource capability is perfect for this applications -except- there is no "generator" value built in for the powersource attribute.
My question I'm hoping someone can help me with - can I sendEvent a custom value to a stock/built-in capability? If so, are there any negative repercussions?
I'm on vacation far from home, so even after writing the code, I can't test it without remotely starting my generator and initiating a transfer - which I don't feel comfortable doing this far from home.
For the HE folks - what are the odds that we could get "generator" added as one of the possible attribute values?
"capability" is (for the purposes of this discussion) just prepackaged that combines a onscreen button (Command) tied to an Attribute.
When writing a driver, you can create all the Attributes you want. You can use sendEvent to put values into those attributes, any attribute. You decide if a custom attribute has it's own command or not. But when you use Capability, usually there's a command and of course commands must be coded and that's where the sendEvent is placed. But you can also have a list of sendEvents within a single command.
If you try to set an attribute that is not part of the list of device capabilities, or the list of attributes for the device, then the sendEvent won't work...
There's a couple of others, but hopefully that's enough.
I think that’s the answer I was looking for. I would rather use a HE capability rather than a custom attribute - just because PowerSource is exactly what an ATS is.
So, it seems I’m stuck with a custom attribute unless the developers decide to add “generator” as one of the attribute values for the stock powersource capability?
In other words, if I am trying to set an attribute that is part of the list of that capability, but set it to a value that is not part of that attributes listed values (mains, battery, dc, unknown), it won’t work?
The question I’m asking has nothing to do with commands. I am asking the below:
PowerSource is a “built in” device capability.
It’s only listed attribute is PowerSource.
This attribute’s only listed values are “mains”, “battery”, “DC”, and “Unknown”.
I am asking can I set that attribute to an unlisted value “generator” and will it work with no negative repercussions?
Similar to a contact sensor which also has no commands, I want to set the attribute value through a sendEvent, but unlike a contact sensor, I am trying to set it to an unlisted value.
One of the reasons I’d like to do this is because webcore (and I’m guessing other things) can’t set attributes that aren’t part of a built in capability. As far as I can tell, you can certainly “read” custom attribute values, but you cannot set them from webcore. And moreover, it would be much cleaner to use PowerSource for this application since again, an ATS literally has one status data point - power source - Normal (utility/mains) or Emergency (generator or second utility service).
This isn't the case. Webcore (and Rule Machine) can run any command. You'd just need a custom command to set the attribute.
So in this sense it does. And @csteele provided a typical solution for this problem.
Going back to this point, you can do this in that nothing will stop you. But this kind of thing is normally a bad idea. Apps may not work well with unexpected values (though this is kind of a niche capability that I'm not sure any app I can think of really depends on...).
Thank you both - you answered my questions. And, I do realize I can create a custom command to set a custom attribute and then call that command through webcore, but I’m trying to avoid that… no need to create a new command if I don’t have to - I’m anal and I don’t like cluttering my device page with additional “buttons” if I can avoid it. And I’m also just realizing that even if I set that attribute to a custom value with a sendEvent, I don’t think I could set that same custom value through webcore - not that I’d really need to do that. Seems like a custom attribute is the way to go, and just figure there is no real use case for setting it externally through webcore or anything else.
Generally though, does it seem practical to feature request another stock value here? It just seems so fitting that power source would be used for this application, and I have to figure more than just a few us have whole house generators.
How are you going to set the value of any attribute (custom or not) from an app without a command?
Maybe, maybe not (I've only seen it used for certain devices likes some Z-Wave sensors or thermostats that can be either plugged in or run on battery). But it's so rarely used I can't imagine many apps depending on this value--or a custom attribute being that much more difficult to work with for the same reasons. (A supportedPowerSources attribute as part of the capability -- with the meaning being what one would assume from its name -- might also make sense. )
You can set a custom attribute through sendEvent, correct? I do it in all my other drivers. But in those cases, I cannot set a custom attribute externally through webcore.
And, as far as the use cases of power source, I am using the community driver for NUT and it uses this. A transfer switch isn’t much different than a UPS in this way. TBH, I think Battery and Generator may make more sense than Battery and DC as value options. My day job is electrical construction - managing/building data centers and I can’t think of a situation where DC and Battery would be different, but there may be some discrete purposes in the small electronics world that I’m not thinking of here.
From an app or driver you are writing, yes. From an arbitrary app, including webCoRE pistons, no. You need a command, whether stock or custom (though again no stock command exists for this attribute; it's normally read-only outside of virtual devices, where a custom command to set is typcially provided).
Yes, so it seems either I can try to feature request this addition or I’m stuck with a custom attribute. The anally tidy part of me (thanks Mom) would really like to see this value officially added because it just makes so much sense to me, but in reality with a transfer switch there should never be a reason to set this attribute externally.