Has anyone used AI to write a device driver for Hubitat?
If so, does anyone have any opinions on which AI to use?
I thought about using Anthropic's Claude, but I'm not sure I want my Hubitat launching a nuke at my neighbors. I'm not saying that's a deal breaker but maybe there is a less WW3 approach.
I opened DuckAI and asked it to write me a Hubitat device driver to give me Civil Twilight, and it did come back with something but I haven't tried it yet.
I have seen several posts releasing drivers made with AI here in the community. I have played around with it to write drivers and help with Groovy coding.
It makes a lot of mistakes. Install the code it gives you and test it. Have AI add debug statements, then you can feed the errors back to AI to have them fixed.
It usually requires a few iterations to get it working, and sometimes it changes more things than it needs to when you ask it to fix something, so keep a copy of in-between versions in case AI goes astray on the fixes.
It helps to tell it first to take on the role of a Hubitat Groovy Driver Developer.
I used Deepseek, but there are many LLMs to choose from. I'm boycotting ChatGPT due to the government stuff though.
I’ve managed to do 3 now using ChatGPT. It’s time consuming and can get quite frustrating. As others have said you need to test and revise continuously. On numerous occasions I’ve found that when telling the AI about some tiny change needed; rather than just make that change it altered other parts of the code causing further bugs. So after each change if I’ve had to repeat testing.
I’m just using the free ChatGPT and learned a couple if things that helped massively with speed/performance. One was to start with a bulleted list of clear instructions such as - all answers must be less than x words, always answer before providing explanations etc (I pasted some instructions from a web search). Secondly at the end of a session or when things are slowing down, ask the AI to provide a project summary with all key steps. That allows me to start a new chat with the instructions, the project summary and the previous code.
I have used Claude recently and was pretty impressed. Of course, one pretty much has to already have some familiarity with writing code, in order to fix the mistakes made by AI. You can feed back to the AI the output from the logs showing errors, and it will often fix its own mistakes.
I used Claude to write a driver for the Visonic Zigbee long-range contact sensor as I wanted to be able to invert the open/closed states. I let it write it from scratch and it did a fairly decent job of it. I have also used it to look at some of my existing HE drivers and asked it to identify any bugs or opportunities for efficiency improvements. It definitely helped find a few things that I would have missed, as they were issues that the code would probably never have experienced. Still nice to tidy things up a bit.
Yeah Anthropic is actually the company that told the US Government that they were not interested in their AI being used for war. So, in my book, they moved up a few rungs on the ladder of non-evilness.
I don't think one has to be a coder to effectively use the tools. One does need ability to both write good specifications and to be able to read some code. One needs enough skill to sense any BS that the AIs come up with.
Use the programming modules, not general chatbots. I've used Claude Code, Codex, and a bit of Grok. They all know Hubitat's Groovy environment pretty well these days
Set up whatever .md files that are recommended for whatever tools one uses
Use planning mode. Cover as many edge cases as you can think of up front.
Get the tools to write out summaries of progress
If one is writing a driver find a working one from another environment like Home Assistant or Homebridge. Give it to the AI
Give the AI examples of well structured Hubitat code for drivers or apps.
We've been using spec-kit with Claude and vs code/copilot/Claude agents. If you are working on larger projects the spec-kit helps a lot because you can polish the requirements and just regenerate all of the code. Then iterate on removing the defects.
I've been using OpenAI's Codex to implement improvements to many of my apps including my HousePanel dashboard. I recently used it to write an AI feature within the dashboard app itself. I'm pretty impressed with it's abilities. I uploaded an entire function and asked it to review it, and it found several errors and fixed them all with the touch of a button. Amazing stuff.