Mostly I’m writing this to remind “future me” of what I did to set up my coding environment using VSCode (Actually Cursor AI, but it’s the same), and a Debian Supervised install. I’ve searched high and low, Reddit forums, here, and this isn’t fully documented anywhere. Bits and pieces, but nothing newbies can follow.
Its not straightforward and it’s taken me (admittedly I’m not a pro programmer) weeks to get here. I Initially tried installing ESPHome locally on my HA system. Compiling that way takes forever for some reason. The better way is to use the docker container already running esphome.
HA’s ESPHome Builder is great for beginners. I’m into a 1,500+ line ESPHome application and switching back and forth between VSCode and ESPHome Builder is inefficient, especially since you really don’t have to leave VSCode at all.
Steps on computer you will be editing and writing code on:
1- install VSCode or Cursor AI. I use Cursor AI - it’s a game changer. See my other posts for why
2 - Install the following VSCode extensions if they aren’t already installed.
- ESPHome
- ESPHome Snippets
- Home Assistant Config Helper
- Run In Terminal
- YAML
Here’s a cool video showing you whats possible in VSCode with the HA extensions.
Next, find out what the name of the docker container is that runs ESPHome. I’m not a docker guy so I install Portainer which gives me a nice pretty UI that lets you do everything you can do from the command line.
this command will do the same thing docker ps -a |grep esphome
now that you know what the name of the ESPHome docker container is, go back to VSCode and open a terminal window. Top Menu Bar/Terminal ->New Terminal Window.
Now ssh to your Home Assistant system. I created a user called ‘esphome’ on my Debian system and allowed it to be used with SSH. Google how to do that.
ssh [email protected]
(or whatever the ip address is of your HA server.
once you’re logged in via ssh, type this command:
sudo docker exec -it -w /config/esphome addon_15ef4d2f_esphome bash
you should get this prompt
root@15ef4d2f-esphome:/config/esphome#
then run the command
esphome run your-file-name.yaml
root@15ef4d2f-esphome:/config/esphome# esphome run your-file-name.yaml
and magically it compiles, uploads and starts the log, just like if you were in ESPHome Builder.
There are tons of things you can do using the command line:
To automate even further, add these lines to the end of your .bashrc file in the home directory of your SSH user (mine is esphome)
export PS1='\[\e[0;36m\]\u\[\e[0m\]@\[\e[0;33m\]\h\[\e[0m\]:\[\e[0;35m\]\w\[\e[0m>
sudo docker exec -it -w /config/esphome addon_15ef4d2f_esphome bash
those 2 lines give you a nice prompt, and automatically get you to the right place so you can execute the esphome
command.
Now you don’t have to ever leave VSCode as you’re creating new firmware for your projects. I hope this helps someone else.
I know it’s gonna help future me…