yi-hack-Allwinner-v2 icon indicating copy to clipboard operation
yi-hack-Allwinner-v2 copied to clipboard

Access media files from home assistant

Open oat1 opened this issue 3 years ago • 32 comments

Hi is there a way to access these media files from home assistant ?

It would be nice to add this folder to media section and watch them directly from this section.

unnamed

oat1 avatar Mar 02 '22 13:03 oat1

You can upload the file to an FTP server or access them with the web services. Check the wiki: https://github.com/roleoroleo/yi-hack-Allwinner-v2/wiki/Web-services-description

roleoroleo avatar Mar 02 '22 13:03 roleoroleo

Yes, but now finding a file is a pain in the ass.

I'm thinking about something more "user friendly" Accessing camera sd card like a network drive, and put the video catalog to media section in HA The whole main catalog of video files, let's say " Yihack", then subfolder with specific days, hours and inside a list of files to play. Just like frigate does ( screen below) It would be much easier to watch and find a specific video from specific

I do not know whether it is possible or not, It is just a wish to consider :) But I think it would be a great thing.

frigate

oat1 avatar Mar 02 '22 14:03 oat1

Try the new release of the integration.

roleoroleo avatar Mar 06 '22 15:03 roleoroleo

Wow Great 😊👍 thanks . There is now a new folder yihackin media section but when I go inside, error appears. Any solution?

Screenshot_20220306-174520_Home Assistant Screenshot_20220306-174507_Home Assistant

oat1 avatar Mar 06 '22 16:03 oat1

Please, check the registry log and send me the error.

This is what it should appear:

immagine

immagine

immagine

immagine

roleoroleo avatar Mar 09 '22 07:03 roleoroleo

Log below

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/yi_hack/media_source.py:76 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 06:23:53 (3 occurrences) Last logged: 08:39:47

[547642575360] Error handling message: Unknown error [547642851184] Error handling message: Unknown error Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/media_source/init.py", line 152, in websocket_browse_media media = await async_browse_media(hass, msg.get("media_content_id", "")) File "/usr/src/homeassistant/homeassistant/components/media_source/init.py", line 111, in async_browse_media item = await _get_media_item(hass, media_content_id).async_browse() File "/usr/src/homeassistant/homeassistant/components/media_source/models.py", line 85, in async_browse return await self.async_media_source().async_browse_media(self) File "/config/custom_components/yi_hack/media_source.py", line 76, in async_browse_media domain = list(list(device.identifiers)[0])[0] IndexError: list index out of range

oat1 avatar Mar 09 '22 07:03 oat1

Try this file: media_source.py.gz

roleoroleo avatar Mar 09 '22 09:03 roleoroleo

Now Works flawlessly, Thanks! For the feature and for help. You're the best !!!

image

oat1 avatar Mar 09 '22 10:03 oat1

With the next release cam/integration the video will have a thumbnail that will display the first frame, as shown in my previous post.

roleoroleo avatar Mar 09 '22 11:03 roleoroleo

Great 👍😃 Couldn't ask for more. Appreciate the job

oat1 avatar Mar 09 '22 16:03 oat1

Hi, I updated camera to the latest 0.2.1 release, but there is no thumbnail, still just icons yi-hack Home Assistant integration is also updated to 0.3.8

image

oat1 avatar Mar 18 '22 11:03 oat1

Login with ssh and check if crontab file is ok:

root@yi-hack-allwinner:~# cat /var/spool/cron/crontabs/root
* * * * * /home/yi-hack/script/thumb.sh cron
0 * * * * sleep 20; /home/yi-hack/script/clean_records.sh 30

Try to run the process manually and check the output:

root@yi-hack-allwinner:~# . /home/yi-hack/script/env.sh
root@yi-hack-allwinner:~# /home/yi-hack/script/thumb.sh cron

roleoroleo avatar Mar 18 '22 12:03 roleoroleo

I get this

image

oat1 avatar Mar 18 '22 12:03 oat1

I've edited it a little and process started image

oat1 avatar Mar 18 '22 13:03 oat1

Sorry, I got confused with Allwinner. This is for Allwinner-v2

root@yi-hack-allwinner-v2:~# cat /var/spool/cron/crontabs/root
* * * * * /tmp/sd/yi-hack/script/thumb.sh cron
0 * * * * sleep 20; /tmp/sd/yi-hack/script/clean_records.sh 30

Try to run the process manually and check the output:

root@yi-hack-allwinner-v2:~# . /tmp/sd/yi-hack/script/env.sh
root@yi-hack-allwinner-v2:~# /tmp/sd/yi-hack/script/thumb.sh cron

Did you understand why the script didn't start?

roleoroleo avatar Mar 18 '22 13:03 roleoroleo

It is running now, starting thumb.sh cron helped. Thumbnails are being created and I can see them in the media section.

To be honest I have no idea why the script did not run automatically after the update and reboot

You wrote 0 * * * * sleep 20; /tmp/sd/yi-hack/script/clean_records.sh 30

and I have 0 * * * * sleep 20; /tmp/sd/yi-hack/script/clean_records.sh 5

How do I change it ? was it the reason ?

oat1 avatar Mar 18 '22 13:03 oat1

Proces makes thumbnails, but only once. New records do not have them and cron does not start automatically again. How do I change it ?

image

oat1 avatar Mar 18 '22 13:03 oat1

Is crond running?

roleoroleo avatar Mar 18 '22 15:03 roleoroleo

How do I check that?

oat1 avatar Mar 18 '22 16:03 oat1

root@yi-hack-allwinner-v2:~# ps | grep crond

roleoroleo avatar Mar 18 '22 16:03 roleoroleo

image

oat1 avatar Mar 18 '22 16:03 oat1

The process is ok, I don't understand.

and I have 0 * * * * sleep 20; /tmp/sd/yi-hack/script/clean_records.sh 5

This is another process, don't care. Do you have another line with thumb.sh or just this line with clean_records.sh?

roleoroleo avatar Mar 18 '22 17:03 roleoroleo

I have this lines

image

When I paste: root@yi-hack-allwinner-v2:~# /tmp/sd/yi-hack/script/thumb.sh cron

Proces starts just one time, when I paste: root@yi-hack-allwinner-v2:~# . /tmp/sd/yi-hack/script/env.sh

Nothing happens, maybe this is the reason ?

oat1 avatar Mar 18 '22 17:03 oat1

It's ok. env.sh command sets environment variable.

Check if there are empty jpg in the record folder. If the process find a jpg file it doesn't try to create it again. But if the file is zero lenght you can't see the image in the media source.

roleoroleo avatar Mar 18 '22 18:03 roleoroleo

I did not find any empty jpg :(

If it is a cron then how often should the process start? Every 1 hr ?

oat1 avatar Mar 18 '22 19:03 oat1

"* * * * *" means every 1 minute.

roleoroleo avatar Mar 18 '22 20:03 roleoroleo

Found the problem. Check the last commit: https://github.com/roleoroleo/yi-hack-Allwinner-v2/commit/968dd8580b1800c2b0ae0d035a171be490b21781

roleoroleo avatar Mar 20 '22 14:03 roleoroleo

Great 😃👍 can I test it now, upadte via ssh ? How? Or wait till next release?

oat1 avatar Mar 20 '22 16:03 oat1

upadte via ssh ?

Yes.

roleoroleo avatar Mar 20 '22 17:03 roleoroleo

But how ?

oat1 avatar Mar 20 '22 18:03 oat1