Taking a crack at UPB platform development

I’ve been experimenting with HA using Z-Wave (works great–better than anything else I’ve tried). In addition to various Z-Wave devices (switches and lights) I also have UPB switches. I’m a competent Python developer, so I’m planning to take a crack at developing a “platform” module for UPB. Since I’m relatively new to HA, I’m still pretty fuzzy on how to go about doing that.

I’ve been looking at the source on Github and reading the developer documentation, but I still have lots of questions. For example, I think using Z-Wave as a reference makes sense (like Z-Wave, UPB has switches, lights, scenes, etc. and can be controlled as well as generate events, like when a switch is manually turned on/off), but the source contains multiple Z-Wave modules, and it’s not clear which (if any) I should model my UPB modules after. It seems like there are separate modules for Z-Wave “control” and “sensor” functions, or maybe it’s different modules for different types of Z-Wave devices? I can see implementing UPB in “phases” (i.e. switch control, light control, “sense” input, etc.), but I’m not clear if that’s the right approach, in keeping with the HA design methodology.

Can anyone (i.e. with more experience with HA in general, and better yet, someone that has a deeper knowledge of the code) point me in the right direction? I’m looking for help in understanding the structure of “platform” modules and what design considerations I need to take into account. Thanks in advance!

Not sure if this will help, but there are several threads in the development forum requesting it. One of them has links to some coding that may get you started.

I’m not a python coder (although I’m willing to learn), but I do have access to a Leviton UPB system that has light switches, plug-in modules, alarm system and thermostats, so I’m willing to help test things.

Yep, I’ve read through everything that references UPB. The links are useful in that they are examples of other UPB implementations (so they will help answer questions about low-level UPB interfacing and such), but this would need to be a “new effort” for HA. That’s what I’m trying to get a better understanding of–the specific approach of what modules need to be written for HA. Ideally, if someone could tell me “you need to duplicate the functionality of these three Z-Wave modules” for UPB, that would get me started. As-is, my understanding of the HA architecture is very rudimentary, so I’m not sure what modules need to be written.

I can’t say for sure, but my guess would be to use the ZWave platform as a starting point. With 0.46, it now has lighting, fan, and plug controls, which UPB has as well. For alarm and AC control, that may mean looking at individual components and integrating them in. I’d start with the lighting system first, as it’s the easiest to control.

I’ll have full access to a Leviton OmniPro II system, including 433 wireless sensors, alarm, A/C, and HiFi 2 system here in another month or so. I’ll also have a USB PIM from Simply Automated, so I can test anything you need from my Raspberry Pi. I can possibly even mock some of it up in a lab (given enough notice).

Let me add one more thing… all the Leviton UPB guys live on the CocoonTech forums. Here’s a link to a thread on there that has some coding in it that may get us started in the right direction:

Here’s another link to something I had looked at regarding UPB support:

I’m wondering if @balloob or one of the original developers could help point us in the right direction regarding the platform requirements.

I’m slowly starting to understand the implementation details of HA. There’s something I’m not clear on (at the moment, anyway)–do you happen to know? A Z-Wave switch or light can report it’s state when it’s manually turned on or off. HA recognizes this and changes the state internally. I can’t specifically find the code that does this. There are Z-Wave platform libraries under /switch, /light, /sensor, etc. If I’m only concerned with UPB lighting, for example, the “control” function (i.e. the interface that lets HA send commands to the UPB network) would logically be implemented under /light, but is that also where the “stage change report” should be handled, or should that be a separate platform library (maybe under /sensor)?

I don’t know much about this stuff but just from the forums and chat rooms it seems like zwave is kind of a “shit show”. Maybe use one of the other lighting components as a base or example?

I would guess that it would be under the /light area, since you’re talking about the state change of a light. In my house, we only have UPB lights and plugs. The lights are all dimmable, and the plugs are all on/off.

The ZWave sensor section appears to be used for things like motion sensors, etc, not necessarily for “sensing” the status of the light. I could be wrong though, as it may use that component as part of the heal/repair function of ZWave, which UPB doesn’t necessarily use.

@bbrendon: OK, that’s just the main one I use (other than UPB). It actually seems to work fine, but of course that doesn’t mean it’s a good example of “good code”. Any thoughts on what is considered a “good” lighting platform?

@jeremyowens: Yes, I only have UPB lights and plugs, too (I’m not actually aware of anything else in the UPB world). What I haven’t been able to figure out is how manual device state changes are reported back to HA. If it weren’t for that, I’m fairly sure that just a /light module would do the trick. Continuing my research, but if anyone else has any input here, please join in.

Any updates ? Have you written any code you can post?

How can we get this unstuck? I’m dying for UPB!

Take a look at Pytomation. It has UPB support already written in Python for it. While I haven’t had time to see what all would be required to make it work with HASS, this could be a huge jumpstart for this. While it’s free under GNU, I have emailed the original author to confirm that we can use all or part of this code, if needed.

Maybe looking at X10 code would be more helpful? I understand UPB is in-line transmission, similar to X10 with the significant difference in the power line transmission characteristics being more reliable. Isn’t z-wave out-of-band wireless technology? I also understand UPB is stateless.

@kelargo Wow. That’s a great idea. The x10 code isn’t very long. It basically calls a program “heyu” to make changes to the lights. I wonder if I can modify my UPB integration to work like the x10 does.

Either way, it’s an extremely simple framework to start with.

Thanks for the ideas!

I’m not sure, but I don’t think hey can support UPB, only X10. I found this tool below; a command line interface to UPB.
I have not used it, so I’m not sure how mature it is. There maybe other tools…

Thank you for looking into this.

@bbrendon: It’s my understanding (from https://home-assistant.io/developers/add_new_platform) that what’s needed is a “platform” script for UPB. If I only wanted to control UPB devices, I think I could use just about any of these as a starting point: https://github.com/home-assistant/home-assistant/tree/master/homeassistant/components/switch. That actually looks pretty straightforward.

But I not only want to control UPB devices, I also want those devices to provide events to HA when they are physically changed (primarily when someone presses a button on a UPB device). I don’t want to poll for the status (and in fact, UPB doesn’t really allow for that anyway). Z-Wave (which is the other switch type I have on my HA system) does this (I can control the state of a Z-Wave switch from HA, and if the Z-Wave switch is manually changed, HA is immediately updated).

This is what I’m not clear on: It does not appear to me that the “platform” scripts handle this “event” feedback. So does that mean I also need to write a platform script here (https://github.com/home-assistant/home-assistant/tree/master/homeassistant/components/sensor)?

What I don’t want to do is develop a switch platform script for UPB, and then find out that I should have done something completely differently in order to also support the “event” feedback.

Also, X10 may be a good starting point (although only if it provides the “event” feedback to HA). But even so, I can’t find a switch platform script for X10 (it’s not on github that I can see).

@eric24 what did the guys in the developer chat room say?

Sorry, but I’m not familiar with that chat room. I’ll take a look if you can point me in the right direction.

Try here:

#dev room.

@eric24 Any progress?

I wrote a platform that works. It’s a bit hackey because it uses a node application to send and interpret UPB messages. The main reason I did this exploration into the bowels of HASS is because I wanted my UPB lights to appear in HASS as lights which with my other method, they did not. It’s an improvement over what I had working before. Hopefully someone can help improve on this.