logo elektroda
logo elektroda
X
logo elektroda

Simple HTTP server/file hosting for Home Assistant (useful for OTA)

p.kaczmarek2 7851 17
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Home Assistant logo with WWW text on a blue background.
    Home Assistant offers a built-in, very simple way to host files on its own HTTP server. This can be very useful when we want to perform OTA (remote firmware update) on some device that expects to give it a URL with a file and only supports HTTP. An example of such a situation may be Tasmota (when we want to upload our own build) or Sonoff NSPanel (the FlashNextion command to change the display firmware also requires the file URL).
    The situation is complicated by the fact that often newer hosting solutions available on the web force HTTPS, which makes it impossible, for example, to download this Nextion via ordinary HTTP. For the same reason, for example, it is not possible to download binaries directly from Github.
    You can easily set up an HTTP server at your place, for example using Visual Code, or Node.JS, or other Python tools, but why? Just use HA...
    Here I will briefly show how this can be done.

    HTTP hosting in HA
    I wrote quite a lot about HA itself in this topic:
    Tutorial Home Assistant - configuration, WiFi, MQTT, Zigbee, Tasmota
    Some convenient access to it will be useful, I mapped the config folder via SMB:
    Window for adding network location in Windows
    Network location addition dialog with Home Assistant configuration.
    This allows you to conveniently operate on the Assistant's files:
    View of the Home Assistant configuration folder with its contents.
    We upload the files we want to host to config/www :
    Screenshot of a Windows folder with TFT files.
    For me, there are ripples for the Sonoff panel, which I will describe soon.
    You can get to them from a web address like:
    
    http://192.168.0.113:8123/local/ns-panel.tft
    

    The subdirectory is very important local We can't get to them without him!
    Just opening this URL will download the file - without logging in:
    Screenshot of Microsoft Edge browser with the Downloads pane open, showing the file ns-panel (10).tft.
    And it is this URL that can be given to devices that need to download our update via HTTP GET...

    Summary
    I have the impression that few people know about this option, and it is most useful. It is worth knowing about it, the more that no one will guess that these files are available in the subdirectory local and as we know, users often skip reading the documentation...
    It turns out that hosting files on HA itself is very simple - just right for OTA.
    PS: Of course, remember that if our HA is only in the local network, these files will only be visible in the local network. But we rather know that, don't we? Same as other servers.

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 11800 posts with rating 9921, helped 563 times. Been with us since 2014 year.
  • ADVERTISEMENT
  • #2 21047938
    morgan_flint
    Level 14  
    Hello, @p.kaczmarek2

    I'm trying to do this without success...

    I have Home Assistant installed via Docker in a local server with Ubuntu Server as OS.

    Could this be the cause?

    Thanks!
  • #3 21047996
    p.kaczmarek2
    Moderator Smart Home
    I've been testing the HASS HTTP server on my dedicated HASS VM, made with official (?) image downloaded from web. I am not sure about Docker, but maybe first you should try whether the HTTP port is open and available?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #5 21048390
    p.kaczmarek2
    Moderator Smart Home
    It depends, some people may have blocked incoming connections to their machine for security purposes.

    Still, the Python http server is very useful, I am also sometimes using it as a base for my custom servers (it's easily extendable and scriptable, you can inherit the http server class and add filters, etc)
    Helpful post? Buy me a coffee.
  • #6 21048704
    morgan_flint
    Level 14  
    p.kaczmarek2 wrote:
    I've been testing the HASS HTTP server on my dedicated HASS VM, made with official (?) image downloaded from web. I am not sure about Docker, but maybe first you should try whether the HTTP port is open and available?

    Progress so far, after reading this:
    - Added "http:" to configuration.yaml file in HA /config directory
    - Created "www" under /config
    - Files stored in "www" are accessible via http://192.168.1.249:8123/local/filename.ext in a web browser

    I understand this should be enough to host on "www" the OpenBecken Webapp or OTA FW files.

    What I haven't been able to do is connect to that folder from my Windows 11 PC. I've enabled SMB1 but I don't know if that's enough
    Windows features window with SMB 1.0/CIFS client enabled.
  • #7 21048841
    p.kaczmarek2
    Moderator Smart Home
    I do not remember well but I check this and it seems that you need to first install SMB Samba Share addon for HA. I think I did that, but it was a year ago or so...
    Screenshot of the Add-on Store tab in Home Assistant with the Samba Share add-on selected. Samba Share add-on configuration panel in Hass.io.
    Please try and let me know how it works.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #8 21049230
    morgan_flint
    Level 14  
    I'm afraid I can't access the add-on store because of my docker-compose install of HA... I remember I read some (most) of the add-ons also have a docker version, but I still haven't found this one.

    What seems to work for me is this tutorial. Setting "path = /home/morgan/domotica/ha/config" (which is the config directory defined for HA in the docker-compose.yml) in /etc/samba/smb.conf lets me access its contents from Windows:
    Screenshot of Windows File Explorer with the sambashare folder open on the network address 192.168.1.249.
  • #9 21049730
    p.kaczmarek2
    Moderator Smart Home
    Good job! So, everything is working now?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #11 21170020
    morgan_flint
    Level 14  
    I tried again after re-reading this thread and related ones but with no luck...

    This is the error I get:
    Screenshot of browser console showing a resource loading error with a status 403 (Forbidden).

    Maybe I have to configure something else on the home assistant side?
  • #12 21170023
    p.kaczmarek2
    Moderator Smart Home
    So currently you're not able to host any files on HA? Any web page, not just OBK Web App
    Helpful post? Buy me a coffee.
  • #13 21170293
    morgan_flint
    Level 14  
    >>21170023 I've tried with a simple txt and can read it from the browser. Also, if I put 192.168.1.249:8123/local/startup.js in the browser it lists the script there so yes, files are hosted there, but the webapp doesn't work
    Screenshot of a web browser displaying JavaScript code in the startup.js file.
  • #14 21170616
    p.kaczmarek2
    Moderator Smart Home
    This is not the correct way to run web app. Do you change Web App URL In the OBK device setting to point to your self-hosted app?
    Helpful post? Buy me a coffee.
  • #15 21170646
    morgan_flint
    Level 14  
    That was just a test to check that the files are accessible but, as I said here, I also changed the app's URL to http://192.168.1.249:8123/local/ in OBK's configuration.

    EDIT: Another test, devicesList.html (also in the downloaded webapp-gh-pages) seems to work OK when accessed from the HA host:
    Screenshot of the OpenBeken IoT database page.

    Added after 10 [hours] 56 [minutes]:

    EDIT2: I may be getting closer to the problem...

    If I put 192.168.1.249:8123/local/startup.js/ (ended with "/") in webapp config:
    Screenshot of OpenBK7231N interface with a web app URL field.

    I get this error:
    Browser console showing a 403 error when trying to load startup.js from a URL.

    The path to startup.js includes two bars, and if I open that in another tab it effectively gives the 404 error:
    Browser URL shows a double slash and 403 Forbidden error.

    If I delete one of the bars, the error disappears and the script is listed:
    Screenshot of a browser showing JavaScript code from the URL http://192.168.1.249:8123/local/startup.js.

    This is the code I can see with F12 in the browser:
    Screenshot showing the DevTools console highlighting an error in the JavaScript file path.

    So, although the examples I've seen indicate that it should be included, I tried removing the last "/" of the path in webapp config:
    Screenshot of the OpenBK7231N device configuration panel with a field for entering the web app URL.

    With this configuration, other errors appear. The link to startup.js is now correct:
    Screenshot of a web browser displaying resource loading errors.

    And if I hit "open in a new tab" in the contextual menu, it opens correctly. But the path to other needed files is now incorrect:
    Browser console with errors related to script resources in an application.

    And hitting "open in a new tab" gives a 404 error:
    404 error page showing URL 192.168.1.249:8123/locallib/httpVueLoader.js

    Maybe I can correct the double "/" problems in one of the .HTML files... Which one is called from OBK, when clicking "Launch web application"?

    EDIT3: I think the problem is due to having "/local/" in the address... I've opened the same www folder in sambashare via visual studio code and opened it with file server and everything goes well with "http://127.0.0.1:5500/" as webapp address

    EDIT 4: I made a slight mod in OBK's source code to avoid that double slash. The web app continues to work OK with the default https://openbekeniot.github.io/webapp/ and also with a local server with "short" URL (e.g. http://192.168.1.249:7231/).

    With Home Assistant's local server (in my case http://192.168.1.249:8123/local/) the former error has disappeared and http://192.168.1.249:8123/local/startup.js is run without the previous 404 error but, unfortunately, a new error has appeared:
    Screenshot of browser console with CORS error.

    I've been searching about "'http://192.168.1.132' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource", but the answers are way beyond my capabilities 🤦‍♂️. Hopefully, somebody here can explain this error and why it doesn't appear with default webapp's URL or the simpler local one.
  • Helpful post
    #16 21197391
    morgan_flint
    Level 14  
    Problem solved!

    With a "little help" from ChatGPT.

    I just had to add the following to configuration.yaml in Home Assistant:
    Code: YAML
    Log in, to see the code


    Screenshot showing device configuration with details like uptime, IP, and WEBAPP URL.
  • #17 21209936
    donaldwaters434
    Level 1  
    It’s great to see Home Assistant being used for file hosting! This built-in HTTP server feature is a lifesaver when devices need to access files via HTTP, like with Tasmota or Sonoff NSPanel. It’s a real hassle when newer hosting solutions enforce HTTPS, which can block downloads from specific sources. Setting up a local HTTP server using tools like Visual Code or Node.JS is an option, but leveraging Home Assistant for this purpose makes things much simpler and more integrated.
  • #18 21209996
    sjjduesndheh
    Level 1  
    If you're looking for a straightforward HTTP server or file hosting, they offer reliable offshore server options that could be perfect for your needs.

Topic summary

Home Assistant provides a built-in HTTP server for file hosting, which is particularly useful for Over-The-Air (OTA) firmware updates on devices like Tasmota and Sonoff NSPanel that require HTTP URLs. Users have reported challenges with Docker installations and accessing files from Windows PCs, often needing to configure Samba for file sharing. Solutions discussed include modifying the configuration.yaml file to allow CORS and ensuring the HTTP port is open. Some users have successfully hosted files by creating a "www" directory in the Home Assistant config and accessing files via local URLs. However, issues persist with hosting web applications, particularly with URL configurations leading to 404 errors. The community emphasizes the simplicity of using Home Assistant for this purpose compared to other hosting solutions.
Summary generated by the language model.
ADVERTISEMENT