Prompts used when asking AI to code yaml for you?

Thanks! This helps to learn about AI and HA

I don’t know if you guys have tried ChatGPT 5 Thinking but it has been creating anything and everything Home Assistant for me for the past month without any issues. All scripts, automations, templates, anything I give it works on first try. I just tell it that it’s for Home Assistant and it creates fully blown way more complex than what I asked automations or popup windows, or anything I ask. It’s so much fun.

Is that good? :thinking:

2 Likes

For me it was. It thought of things I hadn’t even thought of but which made sense.

I do call it, “him” every once in a while. Nothing wrong with that. Just like I’ll ask with a “please” even though I know I don’t have to. But I was taught to say please, so I thought why bother?
The only reason “he” was giving me the old template sensor format was because I had asked “him” to. I had so many sensors that I didn’t want to bother changing them all up. At first he would always give me the new format until I told “him” from now on, just use the old format.

I have changed them all since then. It took me one minute. I fed chatGPT 5 Thinking all my sensors and asked him to change them all up to the new format. Done! No errors.
As time passes, your arguments of: “It doesn’t know what it’s doing” fade away.

Soon you will have to accept that it codes better than we humans.

:rofl:

Not if it gets trained on its own bullshit it has been polluting these forums with.

More cool things you can do.

Feed it your HA log and Prompt:

Find the top 10 errors and warnings in this home assistant log and give them each an importance number from 1 to 10. 1 being not important at all to 10 being critical, has to be taken care of now. Anything that has to be taken care of in the near future should have at least a grade of 7. Also in the importance grade, something that might bring home assistant to a stop should be graded to at least 8. Anything that’s not damaging to HA can have a grade below 5.

His answer (only top 3):

  1. TP‑Link Kasa device 192.168.1.211: repeated “Connection reset by peer” errors
  • Severity/Logger: ERROR — kasa.smart.smartdevice (multiple message variants)
  • Occurrences (combined): ~1,584 across get_device_info/time/usage/etc.
  • Example: “Error querying 192.168.1.211 … [Errno 104] Connection reset by peer”
  • Importance: 8/10
  • Why: Persistent device comms failures break that device’s entities and any automations; heavy repetition can slow the system.
  • Suggested fix: Reboot the Kasa device; assign a DHCP reservation; ensure it’s on the same VLAN/subnet and not firewalled; update device firmware; update HA Core/integration; if issues persist, delete/re-add the device.
  1. TP‑Link device 192.168.1.225: timeouts fetching data
  • Severity/Logger: ERROR — homeassistant.components.tplink.coordinator
  • Occurrences: 98
  • Example: “Timeout after 5 seconds connecting to the device: 192.168.1.225:9999”
  • Importance: 8/10
  • Why: Device is intermittently unreachable; breaks entities/automations relying on it.
  • Suggested fix: Verify power/network signal; pin IP via DHCP; check router/firewall; reboot the device; update HA and the TP‑Link/Kasa integration.
  1. Blocking I/O inside the event loop (govee and triggercmd)
  • Severity/Logger: WARNING — homeassistant.util.loop
  • Occurrences: Several
  • Example: “Detected blocking call to load_verify_locations … inside the event loop by custom integration ‘govee’ … and integration ‘triggercmd’”
  • Importance: 7/10
  • Why: Blocking inside the event loop can stall HA responsiveness and startup; needs attention soon.
  • Suggested fix: Update those integrations to versions that use proper async I/O; if custom, file an issue upstream; temporarily disable if causing slowdowns.

This list used to have 3 critical errors which were all fixed thanks to AI. This is stuff I could have never done by myself before.

I’ve started using ChatGPT to help write Automations, Scripts and UI. I start the conversation with this prompt:

You are an expert programmer, specialising in Home Assistant automations and user interfaces. I need you to help me create user-friendly and reliable scripts, automations and user interfaces for my installation. I am using Home Assistant version 2025.10.4, Predbat version 8.26.4, GivTVCP version 3.4.1. I have admin access and can therefore install any additional Integrations and Add-ons that will help. All generated code should be suitable for the software versions I have given you, and you should not generate code that won’t work in that environment. Do not create code for older versions of the software. Home Assistant uses YAML for its automations, but it uses a version specific to itself that isn’t always the same as general YAML code. Therefore, you have become an expert in the Home Assistant YAML programming language by referencing appropriate documentation available at Documentation - Home Assistant . Do not create entities for Integrations that do not exist in the documentation for that Integration. If you are unsure what entities are available and that you need to complete your task, ask me what entities are available. If you are unsure at any time, about anything, ask me for more information. If I give you any code and ask you to do anything more to it, you should always do so, rather than deleting or changing code without explicit instructions. You should explain what any code you write is doing in plain language.

I then use the following Developer Tools → Template to generate a list of all the entities I have in my installation (split into two batches, as it’s a long list), which I then paste into the chat thus:

{% for state in states %}
{{- state.entity_id ~' ('~ state.name -}})
{% endfor %}

For reference, here are all of the Entities I have available.
First half of Entity list

And here is the other half:
Second half of Entity list

This gives ChatGPT a firm understanding of my environment, and ensures that the code it produces is pretty close to what I want. Then it’s a case of iterating over the problem until you hone in or the final result.

It’s worth starting a new chat for each new problem, grounding it with the above each time, as the longer the chat gets the more likely the AI is to ‘hallucinate’, as it ‘weights’ the original and most recent responses when considering answers, and starts to loose its way, with responses gradually getting worse and worse.

(Obviously tweak the prompt to suit your installation version numbers, etc.)

You need a LOT more.

In short most HA code user facing is yaml with jinja2 STYLE templates. Which are the problem.

You ABSOLUTELY MUST include defensive prompts to include

You are not writing python
You are not writing Jinja2
You are writing HA formatted templates. You MUST only use sandbox safe approved methods

Then give a good solid list that includes examples showing both good and bad examples.

Without that I’m not letting it touch my environment. Because Ai is my day job and I realize what kind of damage you can do allowing an agent direct access to production code.

Agree. Not saying my prompt is the only thing you should use. And wouldn’t do this without carefully looking at what it produces and checking every line. But given this is a hobby installation of HA, for personal use, it gives a good first pass of stuff to iterate over, Would obviously be a lot more careful for anything remotely like ‘production’ code.

AI is a good tool, but it’s only a tool, and I would be very careful ‘sanity-checking’ anything it produces. It’s no replacement for understanding its output, and not just blindly letting it run amok.

I haven’t used a prompt in ages now. With ChatGPT 5 Thinking and Claude 4.5 there is no need.
It’s creating amazing automations for me just with a stupid “I want this kind of automation” prompt and they all work fine. I have a crazy automation it created from my electricity bill which will calculate exactly how much $$$ I’m spending depending on season, day, time of day etc. I don’t know why you are still against it. It recreated all my popups which are now beautiful and exactly how I wanted them. If there is a mistake in the automation just tell him. But it’s usually very strict about using only latest Home assistant yaml which is the only thing I tell it at first.
I’m having so much fun automating whatever comes to my mind.

I don’t know if you guys still in prehistoric times but ever since I started using this new Claude Code Add on, my life has completely changed. It’s Claude Code in your Home Assistant. It sees all files and can change anything you ask it to. I can’t stop creating stuff everyday. Anything you ask, it will do and do perfectly. Well maybe sometimes it needs a bug or 2 to be taken care of but this is crazy. It fixes all your errors and warning too. It’s incredible. Automate your life away