Silly question about writing drivers

Hi

I hope somebody here can give me a bit of advice here.

I've got some of the Aqara E1 roller shade motors and they are great, but I have a few issues with the driver. It works in that it will instruct the thing to open, close and set position, but in the log there are a few error messages.

This is the driver I've been using.

I'd love to be able to write my own driver, but I look at that and there's literally hundreds of lines of code (albeit a few are commented out). My question is why?

I've followed the basic instructions to do a standard driver for a simple switch, but is there a reason this has to be so complicated?

I had naturally assumed that once you knew the clusters, you just had to send the right command and hopefully interpret what you are sent back (e.g. position, battery level which is all I might ever need!)

Could it ever be that simple, or would I need to really study the programming to ever make progress?

I am keen to write my own partly as an educational thing and partly because I'm fed up of finding that one driver for a device will do XY but not Z and another will do YZ but not X...

Thanks
Chris

My opinion is: It depends. (Bet you never saw THAT coming). :laughing:

You can make a driver pretty simple. There are some foundational sections needed for Hubitat like the metadata, functions for uninstall, etc... Beyond that, it really boils down to what you want the driver to DO. Does it support a device with a bunch of options and data? Does it NEED to allow all those to be changed? How easy do you want it to be for other people to look at your code and understand it? Do you just want to ask AI to do it?

I did not know ANY Groovy before starting to work with drivers on Hubitat. I did have Arduino knowledge, and OLD programming skills, but these were the first like this. I just looked at what some other people had done, looked at the documentation (and samples) Hubitat does, and looked a lot up on Google as I was going.

Some of my oldest drivers are for Zigbee based devices... and I recently wrote a new one (not published yet because I am waiting for an OK from the company, although they seem to have forgotten about me). Looking back on that old code there were a bunch of things I have changed, and some stuff that is still my "standard". I also build in a lot of stuff for future possibilities. For example, my Zigbee driver has a large section of Zigbee clusters... because I did not want to have to keep looking them up. So I just added them all in (at the time) and only use the ones the device actual makes use of.

There are also a lot of people here on the forum that will be happy to answer questions and provide feedback to a project thread if you post one. Just asking is a good first step!

In this day and age, no. i’ve gotten a lot of inspiration from members of this community, Who use AI to create new projects or add features to pre-existing projects.

should you choose to use AI, just understand that you will need to test the code and don’t assume there won’t be any errors or that it’ll just work perfectly. My personal fav is claude, but we all vibe a little different.

Thanks for this - I'm keen to avoid AI as much as possible - partly because it feels like I'm being lazy, partly because I don't really trust it (I'm a luddite, I know) and partly because it feels like I'll learn less. I do accept I may need to go there at some point though!

Thanks for this very helpful.

Realistically, I want a sort of bare-bones driver.

Open and close, set position should be plenty for me, although stop position change might come in handy.

It would also be nice to get battery level back and maybe the some feedback that it is open, closed or the position.

I have some programming experience, but not in Groovy and I'm by no means an expert - mostly PHP and a bit of Javascript so I'm fairly comfortable with the idea of functions, methods and objects.

I'll take your advice and start up a project thread and see if I can get somewhere with it.

I think my issue at the moment is finding middle-level documentation on clusters!

Thanks
Chris

As someone who started writing my own apps and drivers for automations a few years ago, with much satisfaction learning how to do it, at this point I use AI for anything generic, like a driver. I still code my automations into apps and drivers manually, but for actual device drivers, just let AI do it. It will find the endpoints and clusters for you and just write it. As coding goes, drivers are a bit boring to write for me anyway.

You will spend some time going back and forth with AI to get it working correctly. Write a good initial prompt, then feedback errors until it gets it right. It could still take some time, or not.

Not to say you cannot learn from AI while it is doing it. It will tell you what it is doing. You can even ask it to go through the code and explain it, if you want to learn the basics that way.