Python_script to create index.html file in (config/www/"whatever"/) My goal is to use the lovelace IFRAME card to display the contents

Hi I want to use a Python_Script to recursively create an index.html file in (config/www/“whatever”/) the goal is to use the lovelace IFRAME card to display the contents. In my Case its my .mp4’s I recorded using camera.record from one of my camera streams.

I have tried placing the scripts “” at my chosen directory ie… config/www/captures/ and running it but i get access denied. tried as sudo su… issue is im not on a pi. Ubuntu linux generic install. I used cli. I have not tried putty to run the script yet. Im also wandering if i could use this as a service. like is mentioned here.

Thank you for your assistance.

This does not exist.

I’m going to assume that you are using hassio.

/config/www/“whatever”/ would be the output dir for your script, assuming (again) that you are running hassio, and this is executed inside the homeassistant container.
Notice the / _before: config

Yes I am running hassio,

I have two more directories inside of my “captures” folder. “videos” , and “snapshots”.

“Whatever” was a reference to what-ever you folder you may have created inside the www directory.

So Far the only way I’ve successfully managed to run the script was to ssh in via PUTTY to my server, using port 22. Thus far I have not succeed using when using developer ssh login methods ie… port 222 or 2222 to login directly to the hassio cli.

Once I ssh in via PUTTY I can then cd (Change Directory) to “” /usr/share/hassio/homeassistant/www/captures/ “” and then run my commands python

image of results

That is for HassOS only.

I figured that name only was a placeholder.
/usr/share/hassio/homeassistant/www/captures/ would be on the host os, that is not accessable by the HA container, and HA can therefore not execute the script, but maybe that was not your plan?

Yes precisely. To achieve this from the with-in the container all that is necessary is open a terminal and navigate to “” /config/www/captures/ “” folder.

( FYI for any others who happen to read this, to clarify. I created the directory “captures” and two other folders within it. That is where my camera snapshots and mp4’s are being saved to.)

Perhaps you or someone here might so kind as to help me write a simple “script” or “shell command” that could regularly update my index.html file with the updated folder contents ie… new videos and screenshots. I’m quite new to “Linux & Python” and don’t have a full grasp of consents and have not figured out how best to accomplish this task…

If the is located under /config, this should work.

  generate: "python /config/"
1 Like

Thank You so much for your quick reply.

My setup has the ““”” file inside the config/www/captures/ folder. I don’t immediately see why this should make any difference but who knows. I’m still learning.

PS. Thank you again. I’ll give this a try and report back with details.

As long as you understand how the FS are mounted and used inside the container, it should not matter where the script is :slight_smile:

Got it. And I believe I figured out why I wasn’t able to use the cli terminal to run the command. If I’m right I think it had to do with the fact that the ssh addon is not running within the same container as hassio. Because hassio is the container hosting the “homeassistant” folder that is mounted as the /config directory by other containers.

I do have a silly question though. How would one now call the shell command after creating it in the configuration.yaml like so.

# BlaBla
blabla: bla black

# Shell Commands
  generate: "python /config/"

Ohh. Perhaps a system restart is necessary.

When I run the Shell Command from within the hassio user interface (browser gui), My Hassio becomes unresponsive. I am not able to recover it from a browser session. However an ssh client, or even physical display with keyboard & mouse at the machine allows me to restart the containers or simply reboot the host machine.

After either method of restart, the system comes back online and loads as usual. I am then able to see the newly updated index.html files inside the respective directory structures using any method of my choice ie… any ssh client or any add-on like (Configurator / Samba / VScode / cloud 9 IDE)

However properly viewing the new versions of the index.html files in my browser requires me to manually clear the browser cache of any browser I’ve previously used to view that index.html. Opening any previously unused browser like firefox to see the updated html page, works just fine and can render the index.html file inside the iframe card just like you would expect.

I use “Google Chrome’s” "Install home assistant" method to access my hassio instance. Can anyone help to identify the cause of hassio freezing after executing the shell command?

Also, anybody know of a better (more direct / less tedious) way to clear chrome’s cache for only one specific page/site at a time.

Thank you again for your time.

Don’t know if this is relevant, but i had to whitelist directories to have access to them

    - /config/www/"whatever"

But interesting script, is it possible to open the files in your iframe?


Have a look here

Yes,. Well clicking the links drills down threw the directories to the files. Then clicking the files listed opens them in the pop-out player, just like clicking on the live stream withing hassio.

Thank you. For this link. Sorry I’ve been away so long.