{"id":2963,"date":"2024-12-28T23:08:14","date_gmt":"2024-12-28T23:08:14","guid":{"rendered":"https:\/\/liljenfeldt.ch\/?p=2963"},"modified":"2024-12-28T23:10:40","modified_gmt":"2024-12-28T23:10:40","slug":"locally-and-externally-available-home-assistant","status":"publish","type":"post","link":"https:\/\/webbservern.se\/~jonas\/wordpress\/?p=2963","title":{"rendered":"Locally and externally available Home Assistant"},"content":{"rendered":"\n<p>Warning issued; Another tech related niche post&#8230;<\/p>\n\n\n\n<p>So you have set up Home Assistant and went with Duck DNS and Let&#8217;s Encrypt which is the standard solution but is only 95 % happy since it is not great when you are accessing your instance locally. What to do, aim for 100 % and spend the time to find a better solution or move on with your life. Since you have read this far, you are obviously going the extra mile&#8230;<\/p>\n\n\n\n<p>You are not alone my friend, I walk with you. (Ok, I stop the cheesey writing style now and switch to dry technical writing&#8230;). So, we do not want to rely on the Duck DNS entry and take control of things and use our own hosted domain name (ha.webbservern.se in my case) for the Home Assistant instance. At least for me, I did sometimes notice weird connection issues and finally got tired of it and decided to set up my own DNS entry (also using Let&#8217;s Encrypt btw, Let&#8217;s Encrypt is fantastic) and this Apache configuration (without fiddling with the currently almost working Duck DNS\/Let&#8217;s Encryt setup) which I think is the actual meat of this blog post:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:443&gt;\nServerAlias ha.webbservern.se\nServerName ha.webbservern.se\nSSLEngine on\n\tInclude \/etc\/letsencrypt\/options-ssl-apache.conf\n\nSSLProxyEngine on\nSSLProxyVerify none \nSSLProxyCheckPeerCN off\nSSLProxyCheckPeerName off\nSSLProxyCheckPeerExpire off\nProxyPreserveHost On\n\nProxyPass \/api\/websocket wss:\/\/homeassistant:8123\/api\/websocket\nProxyPassReverse \/api\/websocket wss:\/\/homeassistant:8123\/api\/websocket\nProxyPass \/  https:\/\/homeassistant:8123\/\nProxyPassReverse \/  https:\/\/homeassistant:8123\/\nCustomLog ${APACHE_LOG_DIR}\/vhosts\/ha.log combined\n\nRewriteEngine on\nRewriteCond %{HTTP:Upgrade} =websocket &#91;NC]\nRewriteRule \/(.*) wss:\/\/homeassistant:8123\/$1 &#91;P,L]\nRewriteCond %{HTTP:Upgrade} !=websocket &#91;NC]\nRewriteRule \/(.*)  https:\/\/homeassistant:8123\/$1 &#91;P,L]\nSSLCertificateFile \/etc\/letsencrypt\/live\/yourdomain\/fullchain.pem\nSSLCertificateKeyFile \/etc\/letsencrypt\/live\/yourdomain\/privkey.pem\n&lt;\/VirtualHost&gt;\n<\/code><\/pre>\n\n\n\n<p>I won&#8217;t say each and every line is correct or needed, but yes, it works great, also with the Android Companion app. It is indeed the result of a fair bit of trial and error but I do think it could help others, if search engines will help to index this, since I did see that people have similar issues in various forums when trying to set up a virtual host proxying a https exposed backend with a certificate valid for the default Duck DNS\/Let&#8217;s Encrypt setup. Nota bene, it might be needed to enable the Apache module wstunnel: sudo a2enmod proxy_wstunnel<\/p>\n\n\n\n<p>Some people might be scared by the SSLProxy relaxations above but in this kind of set up this is not a concern for me, we are talking about connections within the LAN and the attack vector is not significantly increased&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Warning issued; Another tech related niche post&#8230; So you have set up Home Assistant and went with Duck DNS and Let&#8217;s Encrypt which is the standard solution but is only 95 % happy since it is not great when you &hellip; <a href=\"https:\/\/webbservern.se\/~jonas\/wordpress\/?p=2963\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,36],"tags":[808],"class_list":["post-2963","post","type-post","status-publish","format-standard","hentry","category-datorer","category-webbservern","tag-home-assistant"],"_links":{"self":[{"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2963"}],"version-history":[{"count":3,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963\/revisions"}],"predecessor-version":[{"id":2966,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/2963\/revisions\/2966"}],"wp:attachment":[{"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2963"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webbservern.se\/~jonas\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}