LongCut logo

BUILD, MAINTAIN, and TROUBLESHOOT Home Assistant with ha-mcp and your favorite AI.

By mostlychris

Summary

Topics Covered

  • AI Can Destroy Your Home Assistant Instance
  • AI Assumes Your Garage Is a Parking Garage
  • LLMs Know How, Not What's Best
  • Tool Search Shrinks Context From 46K to 5K

Full Transcript

Well, AI is here to stay. Whether you

like it or not, your life is already being impacted by some form of AI. You

may not know it, but it's out there. I

use it daily for work and for personal projects, and I've come to include it in my workflow, and the more I use it, the more I get used to it. When it comes to Home Assistant, that AI can be a good

personal assistant for you. And what I'm going to show you today is called HAMCP.

There are so many things you can do with it. There's just no way I can cover them

it. There's just no way I can cover them all, but I'll do my best to go through a few examples to give you some ideas. So,

let's get started. [music]

Okay, so let's talk about what the HMCP is here. They call it the unofficial and

is here. They call it the unofficial and awesome home assistant MP MCP server.

Uh, and there's a whole bunch of information on here about installing it there. It's a standalone uh standalone

there. It's a standalone uh standalone server. You can put it somewhere else or

server. You can put it somewhere else or you can run it in Home Assistant. I'm

going to use the Home Assistant app.

Here's some things they say you can do with it. Uh create an automation that

with it. Uh create an automation that turns on the porch light, add a weather card to my dashboard, check the motion sensor, uh some other stuff like that.

So, a lot of things you can do with it.

It's got search, control, manage monitor, um got system options. There

are 83 tools. I think there's 86 now actually, or at least that's what it showed on something else I was looking at. But these are all of the different

at. But these are all of the different things that you can interact with via the MCP server. There is a home assistant AI skills. It's bundled and

served as MCP resources via the skill um URL here or URI. So any MCP that supports skills can discover them automatically. For Claude, it's already

automatically. For Claude, it's already embedded. I don't have to worry about

embedded. I don't have to worry about it. um for tool only clients. So I'm

it. um for tool only clients. So I'm

talking about Claude, the same skills are reachable through the polymorphic HA get skill guide tool. If you're using Claude on a paid plan or your LLM on a

paid plan or you're using it um the free version that has limited context or limited tokens, you have to be aware of how many tokens you're using when you're building something out. So, just keep in

mind when you're doing uh this work here, the tool you use and the way you implement it could affect your token usage and and how much it actually costs

you to do the stuff you're doing with AI and Home Assistant. All right, so let's get into um installing it. You can

always add the app repository to my HA here by clicking that button. And what

that will do is it'll add the the repo into the app store and install it. So,

the way I'm doing it now, uh, is let me fix my browser for you. Click on install app here. You have to go over here to

app here. You have to go over here to these three dots and you have to click on repositories. And then what you'll do

on repositories. And then what you'll do is you'll add a repository and you'll paste in the repository listed in one of these things here.

So, you want to add this repository. I

know this says hs or hacks, but this is the same thing. So, you click it here and you go into your Home Assistant repository and you add it right here.

Now, I've already got it added. So, I

won't do it again. And if you look over here, once you add it, you should see it show up as Home Assistant MCP server.

And here's the URL for it. Now, once you have it added, uh, what you'll do is you go in here and search for MCP. You'll

have a few options. You have the Home Assistant MCP server, the MCP server dev, and then this Navacasa web hook proxy. You don't want these two. You

proxy. You don't want these two. You

want this one. You'll click on this one and you'll install it. When you go to install it, you'll see it show up here.

Now, it's I've already got it installed.

So, you'll see it look like this when it's done. Once you're done with this,

it's done. Once you're done with this, what you want to do is you want to go over to the log. So, here is the MCP.

Uh, let's pause this. How do I pause it?

Uh, you'll get this section in the log.

And this is what you want to find right here. This URL is your home assistant uh

here. This URL is your home assistant uh URL or IP plus the port number plus the

/private and then this little bit of um set of characters here. And this is going to be the code you're going to need to run in just a minute.

So I have a command here that I'll paste into claude code and it will install the server for me.

So this is all you have to do. claude

mcp add-on add json home assistant and then the URL of your home assistant instance and then that private URL you just used. So I'll run it now

just used. So I'll run it now and we'll see if it actually does what it's supposed to. So now it says allow cloud to run add home assistant mcp

server config and then it'll do this whole thing again. Now I'm going to deny it just because I've already got it installed and I just don't want to break it. But that's what you would do. It

it. But that's what you would do. It

would run it, install it, you would close out of Claude, the client, open the client back up, and then you can do stuff like um so uh

that's the same thing here. It's going

to ask me this or tell me the same thing hopefully. Paste it.

hopefully. Paste it.

And now it should use the MCP server that I have it connected to, which is right. So it's connected successfully.

right. So it's connected successfully.

Your instance is here. want to point something out here. Let me just let me just point out this obvious fact real quick for you.

You are opening your Home Assistant instance to an LLM. So, you saw Claude ask for permission when I ask it to do something. And there's a there's a

something. And there's a there's a number of settings you can set in the MCP server to prevent it from thing doing stuff or asking you need to tell it to ask permission first. So, you can control the security. Um, but you do

need to pay attention to what you're doing. You need to understand what

doing. You need to understand what you're asking AI to do and also understand that it's going to go in there and it's going to make changes on your behalf. The good news with the

your behalf. The good news with the Hammcp server is it keeps an edit um history. You can restore things from a

history. You can restore things from a pre-edit perspective if something goes wrong. But if you don't do things right,

wrong. But if you don't do things right, you could destroy your Home Assistant instance. you're telling your coworker

instance. you're telling your coworker essentially to go do something and you're trusting your coworker knows what they're doing before they do it. So if you don't take control or you

it. So if you don't take control or you don't watch what's happening with the AI stuff, you could blow up your whole home assistant instance. Just remember that.

assistant instance. Just remember that.

So that's what I want to to make sure you're aware of there. Okay. Now, what I want to take you through uh is some things that I've done with this server or with this uh MPC server. And I want to what I'm going to do is show you what

I've already done. This kind of a a history lesson of things that I've done with this. I'll show you what I asked it

with this. I'll show you what I asked it and I'll show you the responses of what it gave me. I'm not going to replay all this stuff again because I've already done it one time. So, let me just go

ahead and start with a few things here.

Um, what I've asked Claude initially was I was having a problem with one of my sensors, right? So, I wanted to debug

sensors, right? So, I wanted to debug it. So, I asked asked Claude to check my

it. So, I asked asked Claude to check my home assistant instance uh to tell me why the garage motion motion sensor is no longer working. Now,

initially it didn't have uh the correct home assistant instance. So, I went through and I actually fixed it. So,

then I asked it to do it again. Let's

try again with a new MPC configured. So,

it's going to search for all of the for FP3 and all the configured instances. And it tells you what tools

instances. And it tells you what tools it actually uses to do this. So, this is using the Home Assistant HA search entities. It found it. Now, it's going

entities. It found it. Now, it's going to pull the full device details. It's

going to get device, get entity. So,

these are all tools that are part of those 83 or 86 tools. Um, it found good data, so it knows what it's looking at.

And then here's a full diagnostic. It

basically told me the device is online, but has a stale state. Um, and so here are the the parameters it came back with. Now, it said the real problem last

with. Now, it said the real problem last updated 24 hours ago. The occupancy

sensor last changed on this date and time has not reported since. For a

present sensor in a garage that likely sees regular activity, this strongly suggests all these things. Now, let me take a moment and tell you about that.

The garage in a residence is not that active. A garage in a multi-story

active. A garage in a multi-story parking garage would be more active and would have more sensor activity. So

remember when I said you need to understand what the AI is telling you because it's not always going to be accurate. So what it's telling me is it

accurate. So what it's telling me is it didn't see any activity for x number of hours. That means it thinks the sensor

hours. That means it thinks the sensor is offline. Not true. The sensor is

is offline. Not true. The sensor is working just well it's not working fine but it's not offline because of that reason. So keep that in mind when you're

reason. So keep that in mind when you're doing work with the AI. So again it said it lost its connection. Um, it routes through the W200 matter bridge, not

directly to HA. It may have lost its connection. Uh, says it's common with

connection. Uh, says it's common with Aquar devices and the sensor is not showing as unavailable because matter sometimes doesn't propagate. So, it's

giving me some ideas of what to do. Then

it tries to tell me what to do. Uh, and

I said, okay, well, that's nice, but I don't think that's what I want to look at. So, then it looks at the automation.

at. So, then it looks at the automation.

I said tell it to to look at the automation that turns the garage lights on when it shows detection. There was

activity yesterday but the lights never came on. Then it goes through and does

came on. Then it goes through and does all this stuff too. Now it starts to look at automation.

So it has a deep search and a search entities and then it also uses get automation traces and it tells me what it saw at what

time. Uh and then it goes through some

time. Uh and then it goes through some more things. Right? So what happened is

more things. Right? So what happened is the lights the FP300 triggered the automation. the lights to turn on and

automation. the lights to turn on and then and etc., etc. Um, and it goes through and gives me a little event history. Uh, it's 654. The door sensor

history. Uh, it's 654. The door sensor triggers. It cancelled the FP300 run.

triggers. It cancelled the FP300 run.

And, you know, I don't want to get into all the details of this actual stuff here, but it says root cause mode restart door sensor triggering rapidly.

So, I do have a door sensor that turns the lights on when you go into the garage. And I also have this other

garage. And I also have this other motion sensor that if you walk in from the outside into the garage or you're walking around in the garage, it turns the lights on in there, keeps them on.

So that's what I'm troubleshooting.

So, let me stop there because I have a lot to cover here and I don't want to make this video super long, but I will say that you can use it to debug things if you want to. Um, and one of the

things I ended up doing was creating an automation that told me, look, I want to know if the sensor goes offline. So, I'm

going to go down here and find that piece for you. Um,

and before I do that, I just see if there's anything else interesting in here. I said, um, look at the logs in

here. I said, um, look at the logs in HA. So, it goes through a bunch of logs.

HA. So, it goes through a bunch of logs.

It shows the matter server is running.

Okay. Um, the FP300's communicating. So,

it's more troubleshooting. It goes

through. I wanted it to compare the past 24 hours and look at the automation based on what the sensor is doing and make sure it's right. and it created me a FP300 detection log. Uh, and then

automation traces. It only keeps five

automation traces. It only keeps five traces. So, one of the issues I have

traces. So, one of the issues I have with home assistant traces is the fact that by default it only keeps a certain number of traces just to save uh on resources, memory, processing power,

everything else. So, one of the things I

everything else. So, one of the things I wanted to do was to have more traces so I can do for f uh future troubleshooting. So, that was easy

troubleshooting. So, that was easy enough to do to say, "Look, increase the trace history by 15 for the automation."

And it used a couple tools to do that, and it it did. Um, and I talked about some more stuff here, and asked if if it was possible to tell if the 300 goes

offline or disconnects. So, it went through and looked for some uh available heartbeats or something else. And it

found that the temperature updates every about 1 hour. So, temperature and humidity both. then it's going to use

humidity both. then it's going to use that as a a heartbeat. And that

basically means that if I don't see an update within an hour and a half or so that it likely is the sensor has gone offline. So I asked it to create an

offline. So I asked it to create an automation for that. Um or it told me yes, you can detect it. So then I said what's the average temperature sensor

update interval? And it gave me all this

update interval? And it gave me all this information here. And then um

information here. And then um I said okay create an automation that creates a persistent notification which will show on the in the dashboard and it also notify me on my phone and it went

through and created that automation to do all these things. So I did two things here. I troubleshoot the sensor and I

here. I troubleshoot the sensor and I created an automation that actually will let me know if that sensor goes offline.

And I did that all pretty quickly in AI.

Now, one of the next things I want to talk about here is I want to show you what you can do to check your Home Assistant instance basically. So, I said check my instance and report any serious

issues that I should correct. And it got a full diagnostic using all these tools right here. And it found a bunch of

right here. And it found a bunch of things. It found critical items. Uh,

things. It found critical items. Uh, Frigot's not really down. That's um

because I'm not really running Frigot on that. It just seems to have seen it. Uh,

that. It just seems to have seen it. Uh,

SQLite database is 1.7 gig. So they I should shrink that or figure out how to deal with that. And then Z-Wave has some broken nodes. Those are critical under

broken nodes. Those are critical under Sirius. It uh has got some configuration

Sirius. It uh has got some configuration package issues. Um some other stuff

package issues. Um some other stuff here. This home assistant turn on has no

here. This home assistant turn on has no target. I have a couple of instances

target. I have a couple of instances where the home assistant turnon cannot be called without a target. So it fails.

And all this other stuff. Then we go into ongoing connectivity. It goes

through and tells me here all of these um alerts or integrations what the issue is and how many times they happened. And

this is interesting too because I know this Emporia view times out a lot. I see

it on my dashboard things go away. Xbox

I need to remove that because I don't need it and it's causing 60 plus error counts and whatever time frame this thing looked at and and a few other things. So that's nice to see that

things. So that's nice to see that there. Then we've got some template

there. Then we've got some template errors. Let me tell you, template errors

errors. Let me tell you, template errors are probably the hardest thing for me to fix. If I build a template with a bunch

fix. If I build a template with a bunch of YAML code and it's wrong or Home Assistant changes something, which they do from time to time, deprecating some

way I'm doing something with the uh with the templates, then I have to go through and fix them. And I spent two or three hours one day going through and fixing a whole bunch of things that occurred because they deprecated something in the

way I had my template set up. So

template sensors, template errors are if it finds something and I say go fix the template errors, then go do it. I don't have to worry about fixing this and dealing with all

this stuff because these are hard for me. Then you've got some minor issues.

me. Then you've got some minor issues.

You got some duplicate entity IT entity IDs. You've got a protocol migration for

IDs. You've got a protocol migration for MQTT that needs to be done. And then um this right here has been bugging me for a long time. uh on my dashboard or

repairs. It tells me that Uptime Kuma

repairs. It tells me that Uptime Kuma has a updates available, but you have to do some weird upgrade path to get from one version one to version two. I've

never really figured out what that problem how to do that and it's just been bugging me. So, I can go tell it to fix that. It also says I'm on the beta

fix that. It also says I'm on the beta channel. Uh but and that's on purpose.

channel. Uh but and that's on purpose.

So, if you're on a beta channel and you didn't know that, that's good to know.

And it asked me if it wants to start working through all this. So, there you go. um something to help you

go. um something to help you troubleshoot your Home Assistant instance as well and fix all these issues. You can actually then go to say

issues. You can actually then go to say go fix these issues or go fix the serious ones, something like that to get it going. Next up, and I'm going fast

it going. Next up, and I'm going fast here cuz it's a long video already. Um I

wanted to build me a little dashboard and I asked it something very simple.

This is not how I would build a dashboard, but I just wanted to see what it would do. I said, prototype a dashboard of all the lights and switches that have regular usage. Don't include

any devices. They haven't been active in the last 7 days. Uh, make sure you're actually looking at devices and they are switches or lights cuz I have things in the wrong domain sometimes that I don't want to show up there. So, it goes

through and gathers all the lights and switches. It found 328

switches. It found 328 switches. Yep, that's probably because I

switches. Yep, that's probably because I have more than I should. And then it checks to see which ones are really possibly going to be light switches. And

it checks a 7-day history. And then it gets all the data. And then here's an interesting thing here. It ran a skill called home assistant best practices.

It says it wants to build a dashboard on the best practices. And that's what I was talking about earlier. You want to have that best practices skill in order

for the um your AI or LLM to know how to build something. It knows how to do

build something. It knows how to do things, but it doesn't know the best way to do things from a home assistant perspective. So you want to make sure

perspective. So you want to make sure that this thing is actually using the um the home assistant back best practice this skill. So however you run your LLM,

this skill. So however you run your LLM, whichever one you use, make sure it's including that so that you can get the proper way to do things, not just the how to do things. And that's very

important. Um so after I did all that,

important. Um so after I did all that, it had the areas and it's it built the dashboard. It didn't take long at all.

dashboard. It didn't take long at all.

So, if I go look at the dashboard now, it's in my sidebar over here.

And I'm going to find it. It's called

lights and switches. And like I said, it is a very, very generic dashboard. Initially, it had some things

dashboard. Initially, it had some things in the wrong area. So, I went back and told it to fix it. In fact, I'll just show you what I told it here. Um, it

well, first of all, it told me here's what it found. 25 entities across nine rooms and sections, all confirmed active in the last seven days. What it didn't add were any frig switches, DND toggles,

theation controllers, Z-Wave config switches, all that stuff. It also didn't include fan control 7 and 8, even though I wanted it to because it thinks nothing, nobody's touched those, which is likely. They don't really we don't

is likely. They don't really we don't really touch those. They're all

automation.

Um, and then add these power strip outlets. So what I said was you can go

outlets. So what I said was you can go ahead and add the fan seven and 8 and you also need to check the areas assigned the devices to some appear in the wrong place. So it went through and

said okay um these two are both in the master bedroom not in the kids. Let me

now check the areas for the rest and then so it fixed all these. It changed

these put them in the right places. Uh

these two are the same Z-Wave node. So

it uh kept them in the game room and dropped the duplicates. Uh these were moved to the studio. So, it did a lot of stuff on the second pass just to make it work better. And here's all the fixes.

work better. And here's all the fixes.

Over here, you have the web UI. And

there's a whole bunch of stuff here. So,

this page right here, the tools page, this allows you to go through and um enable or disable all of these different skills. You can also pin these

different skills. You can also pin these skills. Now, this up here says pin

skills. Now, this up here says pin toggles only take effect when the tool search is enabled. Either in the service setting tab or for add-on users, the

add-on configuration page. So, if I look at the server settings, is search enabled? It is not, and I will tell you

enabled? It is not, and I will tell you why here in a minute. So, the pin toggle doesn't actually do anything here, but security gated might as well.

um because security gain we'll talk about in a second. So you can on a part per per per tool basis you can actually uh enable these or disable them and then

it should not show up and here's all the different tools that they have within this ha uh hammcp server.

Now if we go to server settings enable tool search. Now, this right here is the

tool search. Now, this right here is the reason why I say um it's not enabled.

And we talked about this before. It

replaces the full tool catalog with searchbased discovery. It reduces the

searchbased discovery. It reduces the idle context from about 46,000 tokens to 5,000 tokens. Says do not enable this if Claude if you use Claude

in Sonnet Opus. And that's because they have their own built-in tool search defer tools which conflicts with theirs.

So, if you want to use that in Claude, disable Claude's built-in tool search first, otherwise leave this off. Use

this only with LLMs that lack native deferred tools. So, non-Cloud, Sonnet,

deferred tools. So, non-Cloud, Sonnet, and Opus do not have it. Um, also local OpenAI compatible models are smaller

context windows.

So, I do not need to have this enabled.

So, I don't So, the pinning doesn't do any good. Also in this page tool search

any good. Also in this page tool search max results enable YAML config editing.

The tool security poly policies is enabled. So it it gates high stakes MCP

enabled. So it it gates high stakes MCP tool calls behind user approval. When

enabled tools that match a rule in the tool security policies tab require you to click approve in the web UI before they run. It's off by default. So I'll

they run. It's off by default. So I'll

show you that tool security in a second.

Backups are interesting because what backups allow you to do is allow you to restore view diff restore or or even delete this. But this is a kind of a

delete this. But this is a kind of a running history of what changes were made. So when I created the dashboard,

made. So when I created the dashboard, this created a uh a file of changes that you can put back in place prior to the change, I believe. Same thing with this

believe. Same thing with this automation. when I created this

automation. when I created this automation, um, it created a kind of a checkpoint for me to replace or repair it or view it or whatever. So, if I change this

automation through AI, it should show another one here or update this one with a diff. And there's no diff here

a diff. And there's no diff here actually. Um,

actually. Um, yes, it did. It changed this to 15 traces. So, this is the different

traces. So, this is the different difference in the automation. That's why

I created this because it did a differential or it did a change. And

here the same thing it moves some of these to different rooms like I mentioned. So the dashboard was changed.

mentioned. So the dashboard was changed.

So anytime you make a change of something that was done by the AI, it will create a backup here that you can do something with. And then you can do auto backup edits, you can set the

throttle and you can retain how many per entity. Now finally tool security

entity. Now finally tool security policies. Um you can enable these

policies. Um you can enable these policies. It's the same thing as in the

policies. It's the same thing as in the server settings. off by default. It

server settings. off by default. It

says, and when they say you have to approve certain things, if you have uh it set up to do something like um

security gated here, if I do any get add-ons, then it should actually uh force me to do a approval. And the approvals will

sit in here until, and here it is right now. Hi add-on. shows you right here.

now. Hi add-on. shows you right here.

Gated tools require approval when all of these conditions match. So no condition rule matches every caller of this tool.

So you can add a condition. Um

so you can get pretty granular with it.

Cancel. Uh so remember approval for X minutes single shot. So if I if someone were to come in here, if I were in here and say get an add-on, I it would show up in this window and I I would have to approve it before it would actually get

done. So that's what you do with tool

done. So that's what you do with tool security product uh policies.

Okay.

Um I went really fast. That was a lot of stuff. Remember AI is everywhere and it

stuff. Remember AI is everywhere and it does a lot of things and it's not surprising that there's a lot of stuff you can do here with Home Assistant.

What I showed you was just the very very tip of the iceberg of things you can do.

You can use your imagination to do all kinds of stuff with the HMCP server. So,

the point was to take you through this, which I hope I did, at least it to give you an idea that it exists and you can go around and play with it. Now, it is not one of your more uh offtheshelf

plugandplay kind of things. You do have to figure out how to configure whatever you're using with. Let me know if you have any questions. I'll do my best to answer them. I'm not an expert in AI or

answer them. I'm not an expert in AI or Claude or anything else, but I can break things really well. So, just let me know. uh comments down below and also on

know. uh comments down below and also on Discord is where you can reach me. Thank

you so much for watching. Thank you for supporting me in what I do on this channel.

Loading...

Loading video analysis...