Howto run ESPHome on HA Core

I have HA Core 0.110.3 on Raspbian.
I also use ESPHome and the folder with the configurations placed in
/home/homeassistant/.homeassistant/esphome
when i want to run it I do
cd /home/homeassistant/.homeassistant/esphome
and
esphome config/ dashboard

Can this be activated by a service. so it run’s al the time

For sure. Depends on your operating system. I don’t know which version of raspbian you are using but if it is a recent one systemd should make it for you

I run via docker and simply set it to always run.

I’d suggest to run this as a separate user (or at least) in a separate venv. It can be run as a service just as Home Assistant with a custom systemd config.

See here to get a rough idea. Installing AppDaemon on Ubuntu with virtualenv

Thanks for the suggestions.

I made a second venv. Because it is homeassistant related I used the same user.

cd /srv
sudo mkdir esphome
sudo chown homeassistant:homeassistant esphome
sudo -u homeassistant -H -s
cd /srv/esphome
python3 -m venv .
source bin/activate
python3 -m pip install wheel
pip3 install esphome
pip3 install tornado esptool

In /etc/systemd/system/ i made a service
I made a service [email protected]
with the following content

[Unit]
Description=ESPHome
[email protected]
[email protected]

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant/esphome
ExecStart=/srv/esphome/bin/esphome -c "esphome config/ dashboard"

[Install]
WantedBy=multi-user.target

I started the service and journalctl gives:

May 27 19:24:56 HomePiOne systemd[1]: Started ESPHome.
May 27 19:24:57 HomePiOne esphome[7307]: usage: esphome [-h] [-v] [-q]
May 27 19:24:57 HomePiOne esphome[7307]:                [configuration [configuration ...]]
May 27 19:24:57 HomePiOne esphome[7307]:                {config,compile,upload,logs,run,clean-mqtt,wizard,mqtt-fingerprint,version,clean,dashboard,vscode,update-all}
May 27 19:24:57 HomePiOne esphome[7307]:                ...
May 27 19:24:57 HomePiOne esphome[7307]: esphome: error: argument command: invalid choice: 'esphome config/ dashboard' (choose from 'config', 'compile', 'upload', 'logs', 'run', 'clean-mqtt', 'wizard', 'mqtt-fingerprint', 'version', 'cle
May 27 19:24:57 HomePiOne systemd[1]: [email protected]: Main process exited, code=exited, status=2/INVALIDARGUMENT
May 27 19:24:57 HomePiOne systemd[1]: [email protected]: Failed with result 'exit-code'.

Something is wrong with the line

ExecStart=/home/homeassistant/.homeassistant/esphome -c "esphome config/ dashboard"

Any idea’s?

Hi,
I also have HA in core version on RasperryPI OS.
Interested in ESP HOME, I don’t know how to do the installation.
@Thuurke, did you find the solution for starting the service?
Thank you in advance.

This unit file worked for me. Changed the config path in ExecStart, and added Environment directive containing path to esphome binary.

[Unit]
Description=Esphome Dashboard
After=network-online.target
[Service]
Environment="PATH=/srv/esphome/bin:/home/homeassistant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant/esphome
ExecStart=/srv/esphome/bin/esphome /home/%i/.homeassistant/esphome/ dashboard

[Install]
WantedBy=multi-user.target
2 Likes

Thanks to everyone above for helping me get this going! Here in Dec 2021 there have been a couple slight changes in how this needs to be setup, so I’ve recorded what worked for me today with the hope that it helps the next girl to come around and try this:

sudo mkdir /home/homeassistant/.homeassistant/esphome
sudo chown homeassistant:homeassistant /home/homeassistant/.homeassistant/esphome
cd /srv
sudo mkdir esphome
sudo chown homeassistant:homeassistant esphome
sudo -u homeassistant -H -s
cd /srv/esphome
python3 -m venv .
source bin/activate
python3 -m pip install wheel
pip3 install esphome
pip3 install tornado esptool
exit
sudo tee /etc/systemd/system/[email protected]<<EOF
[Unit]
Description=ESPHome Dashboard
[email protected]
[email protected]
[Service]
Environment="PATH=/srv/esphome/bin:/home/homeassistant/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant/esphome
ExecStart=/srv/esphome/bin/esphome dashboard /home/%i/.homeassistant/esphome/ 
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl start esphome@homeassistant
sudo journalctl -f -u esphome@homeassistant
10 Likes

I followed these instructions and I can access the ESPHome UI but it wont compile a firmware. It also gives me no information about what failed. Any ideas?

What is the output when you try to compile?

I found my issue was due to websockets not working because I was using a reverse proxy to enable HTTPS. The instructions above actually work perfectly when using HTTP only. Here is the apache config that I ended up using to get it to work. Thank you!

<VirtualHost *:6053>
    ServerName some.host.com

    SSLEngine on
    SSLProxyEngine On
    SSLCertificateFile    /etc/letsencrypt/live/some.host.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/some.host.com/privkey.pem

    RewriteEngine on

    RewriteCond %{QUERY_STRING} transport=polling       [NC]
    RewriteRule /(.*)           http://localhost:6052/$1 [P]

    RewriteCond %{HTTP:Upgrade} websocket               [NC]
    RewriteRule /(.*)           ws://localhost:6052/$1  [P]

    ProxyRequests Off
    ProxyPass / http://localhost:6052/
    ProxyPassReverse / http://localhost:6052/

    Header set Origin "http://localhost:6052"
    RequestHeader set Origin "http://localhost:6052"


</VirtualHost>