snjoetw / py-synology

Python API for Synology Surveillance Station
MIT License
30 stars 15 forks source link

Home Mode Switch #5

Closed raccettura closed 5 years ago

raccettura commented 6 years ago

Looks like it might be possible to implement a switch for "home mode" in surveillance station. This would facilitate more complex operations to turn on/off the camera system based on home assistants automation. See: https://community.home-assistant.io/t/synology-surveillance-station-ip-camera/3552/98

modeclerck commented 5 years ago

Hi @snjoetw When is the new release scheduled?

raccettura commented 5 years ago

+1 to @GaryWes can a new release be tagged?

pergolafabio commented 5 years ago

ok, can we already now use the home mode from this project?

snjoetw commented 5 years ago

sorry for the delay! I'm going to make a new release today

pergolafabio commented 5 years ago

no sorry at all :) btw, did you have a look at the other issue with the new streampath? this py-snology is not working anymore with 8.2.3 or newer, they are going to drop the old method

snjoetw commented 5 years ago

Just did the release, thank you all!

https://github.com/snjoetw/py-synology/releases/tag/0.3.0

snjoetw commented 5 years ago

@pergolafabio yep, let's discuss in that issue i instead

snjoetw commented 5 years ago

Closing this one

pergolafabio commented 5 years ago

Will this be merged now in home assistent?

pergolafabio commented 5 years ago

And also, how to use it in home assistant? :)

Thnx in advance

alekslyse commented 5 years ago

Will this be merged now in home assistent?

Im not sure if Home Assistant got a camera service for home mode - maybe an alarm component need to be created for the synology if you want to be able to use arm home / away on the cameras.

I pushed a new release with the on/off changes though so for now the supported functions in HA is on, off and motion enable/disable

pergolafabio commented 5 years ago

ah ok, well, but i think indeed its enought if it will be exposed like a switch or something? so when this merged, we will see 2 switches? or am i wrrng?

but its not merged yet?

alekslyse commented 5 years ago

ah ok, well, but i think indeed its enought if it will be exposed like a switch or something? so when this merged, we will see 2 switches? or am i wrrng?

but its not merged yet?

Are you thinking about the home switch now? Im unsure about the compliance of HA of putting doing that, but maybe a binary switch could work.

The on / off is not merged yet, but its under review. I can check the binary switch option for home mode. Im not the one that is maintaining the synology component so dont want to step on any toes when it comes to how the component is working.

pergolafabio commented 5 years ago

ah ok :)

np, binary switch offcourse also ok :)

thnx in advance already

alekslyse commented 5 years ago

ah ok :)

np, binary switch offcourse also ok :)

thnx in advance already

I added enable / disable home mode to the component. Im not sure if the solution is going to be approved as you get two new services in Home Assistant, but you could download the files from the pull request and add them to custom_components. After reboot you should have the services available in your Home Assistant for use in automations etc.

https://github.com/home-assistant/home-assistant/pull/21261

pergolafabio commented 5 years ago

ah cool :, yes; i was following that PR , saw your progress how long does it normally takes to get approved?

also, i only need this one as a custom? right

camera/synology.py

alekslyse commented 5 years ago

Yeah just copy synology.py to config_folder/custom_components/camera/synology.py then it will override the builtin component.

I have no idea how long it would take to approve, but Im just using the custom component while waiting.

pergolafabio commented 5 years ago

this one right? thats the modified one

https://github.com/home-assistant/home-assistant/blob/16cd93b3a632fb5eec75faec97ceb14c422d0e54/homeassistant/components/camera/synology.py

are you running 0.88 releasse? because i think now you need to rename the custom components i should be now custom_components/synology/camera.py

pergolafabio commented 5 years ago

ok, tested the custom one, seems to work i can now enable /disable home mode by this service : camera.enable_home_mode .... but is there also now a sensor visible? to see the actual state of home mode? the status?

alekslyse commented 5 years ago

ok, tested the custom one, seems to work i can now enable /disable home mode by this service : camera.enable_home_mode .... but is there also now a sensor visible? to see the actual state of home mode? the status?

Yes the 0.88 it should work fine with the "old" format, but you could change the path format if you want, should not affect the component.

I pushed a new version that exposes if home mode is enabled or not (on each camera) - in the attributes you will now see a field with "home_mode" that is true or false

pergolafabio commented 5 years ago

yes i see it for each camera now but there is something wrong i see the state as recording now for each camera, while its not the case, something wrong now

pergolafabio commented 5 years ago

also, you see indeed the home mode attribute for each camera, but actually, its just a global setting, not?

alekslyse commented 5 years ago

yes i see it for each camera now but there is something wrong i see the state as recording now for each camera, while its not the case, something wrong now

Could you check if you get the same issues with the original file? I know synology made some API changes lately, but im not personally using home/away mode and did not change any recording code. If its not the same issue on the old code I will check it tomorrow.

And yes it should be a global setting, this was just a quick fix since cameras could belong to different servers and it could be handy to see if that specific camera is covered by a home mode. I could make a global camera.synology state with global attributes pr server

pergolafabio commented 5 years ago

no, the issue is with your last commit since you added the home_mode true/false if i load the previous one from 1 hour ago, where you just added the home mode service, its fine, then i see the cameras as streaming

pergolafabio commented 5 years ago

ok, did test again, when i load your last version i see state as recording, not with the previous version without the attribute true/false

pergolafabio commented 5 years ago

its only the state for each camera that is in recording state in HA but the cameras are not actually recording

alekslyse commented 5 years ago

its only the state for each camera that is in recording state in HA but the cameras are not actually recording

Try now with the latest release. Moved the home mode status to its own entity "camera.synology_home_mode" - hopefully it wont interfere with the recording status now

pergolafabio commented 5 years ago

see it as seperate home mode now, but still recording state

alekslyse commented 5 years ago

see it as seperate home mode now, but still recording state

Could it be that you just updated the surveilance station as they removed the live stream API in the lastest release (https://www.home-assistant.io/components/camera.synology/) - I have tried with my old version and recording is not really coming from my code, but the API.

pergolafabio commented 5 years ago

yes, i am running 8.2.3 , indeed the latest one with the changed api but this was like a week ago i only see now the recording state since you added the state of the home .... when you added only the service to set the home mode to on/off, then it was still fine

alekslyse commented 5 years ago

Okay will do some investigation. If it’s a problem for you, just delete the custom file and it should downgrade to stock so I guess no harm done

pergolafabio commented 5 years ago

no problem at all for me, its just the state thats wrong :) , they dont record ... strange though, there is no much difference in your code when you added that state attribute , cant figure it out also ...

i think the other issue about the streaming method for live view is more important :) this is a bigger impact on HA community

pergolafabio commented 5 years ago

i did also created a thread on forum synology about new api for videostream, also an employee from synology responded, that the SID is not used anymore, but now uses cookie instead but he also said, thats best to use the new stream api, since the cookie one will also be gone in future releases

https://community.synology.com/forum/3/post/123094?page=1

pitoganzado commented 5 years ago

@pergolafabio how are you? how do you manage to use this to enable and disable home mode? regards!

pergolafabio commented 5 years ago

Hi, you need to load this for now as a custom component, still be small glitch though, you will see all your camera in recording state, while they are not actually recording

pergolafabio commented 5 years ago

hy @alekslyse @snjoetw , any update on this? i think the "recording" state is the only issues left before it can be merged with HA?

also the videotream issus is still present , needs to be changed to the new API method

alekslyse commented 5 years ago

@pergolafabio Could you please try the latest version.

Remember to set your synology scheduler correctly as I tested several times now and this version does work with my cameras.

alekslyse commented 5 years ago

Also remember to wait 10-15 seconds before sending the service as HA would not update right away. It would update the recording status on the next check as is some seconds

alekslyse commented 5 years ago

Btw created a new pull request as the old one was a mess: https://github.com/home-assistant/home-assistant/pull/21757

pergolafabio commented 5 years ago

yes, tested it, thats indeed better now they are back on streaming state, except one camera, but that was actually recording :)

so its indeed fixed :)

nice job

now just the videostream issue?

pergolafabio commented 5 years ago

BTW, the videostream is only an issue on 8.2.3 , not on earlier versions

alekslyse commented 5 years ago

Yeah the videostream is another issue, but I dont think thats related to this pull request. I guess the API changed and need to be fixed in this repo, not HA?

pergolafabio commented 5 years ago

Yes , indeed, its not a HA issue.. Synology changed API, and they gonna drop videostream, you need to use the new method....

The cameras from this repo, that we push to HA lack the ability now to open videostream :(

alekslyse commented 5 years ago

@pergolafabio

Now im not the one who is doing maintainance on this repo, but im thinking two things: 1, Fix the mpeg preprocessed stream for versions higher than when they changed the API

  1. Add an option to use the rtsp stream and ffmpeg in home assistant - that way you could stream real video directly in ha instead of a series of images. That would be more CPU intensive so would be best for people who run hass on anything else than a rpi (even if rpi should be able to process some video)

For me who use a Intel NUC to run hass I would prefer to use the rtsp stream and be able to have real streaming video in hass

pergolafabio commented 5 years ago

Ah, yes, rtsp is indeed better, but I thought the rtsp component was not ready yet in HA todo fluent streaming

pergolafabio commented 5 years ago

I also think the mpeg stream should be fixed anyway, don't think it's a huge change in code anyway

alekslyse commented 5 years ago

I have not tried the ffmpeg component in ha, but since its using the binary of the ffmpeg I would guess its not ha that decide that. Alternative would be to use an iframe with a stream or something if you really want to bypass any ha limitations. But its always possible to try the rtsp stream and see - im sure it would be better than the few frames we get from the mjpeg component.

pergolafabio commented 5 years ago

I tried the rtsp before, I used the stream path from Synology... If I remember correctly it was also limited to frames only... Not 100% sure anymore... But it wasnt fluent, that I remember

Or it was frames or it was nothing at all