SecKatie / ha-wyzeapi

Home Assistant Integration for Wyze devices.
723 stars 112 forks source link

[Feature Request] Support Wyze Cam(RTSP) #48

Closed jfarmer08 closed 3 years ago

jfarmer08 commented 4 years ago

I just want to see what the response of those people following this repo on adding the Wyze Cam as switch. So my thought is from the app you can turn the camera on and off, way not add this function to HA, but before I go any further is it worth it.

I see this as being good, When i am home I can create or automation and have HA turn the cameras off and when i leave turn them back on.

image

I cannot change this to label:question

kdoh82 commented 4 years ago

You can do this currently with the integration as it is. When the lights get added to HA as an entity you can simply call the service "light.turn_on" or "light.turn_off" as part of your automations. Is there something I'm missing here that you're trying to do?

On Thu, May 14, 2020 at 6:28 PM jfarmer08 notifications@github.com wrote:

I just want to see what the response of those people following this repo on adding the Wyze Cam as switch. So my thought is from the app you can turn the camera on and off, way not add this function to HA, but before I go any further is it worth it.

I see this as being good, When i am home I can create or automation and have HA turn the cameras off and when i leave turn them back on.

[image: image] https://user-images.githubusercontent.com/18117255/81991913-54870780-9610-11ea-9889-dfdc922ff604.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPJRXJEL5YQURKMEO7QDZ3RRRWATANCNFSM4NBCP62Q .

jfarmer08 commented 4 years ago

This is for the camera. So that you can turn it on or off. not for the Light.

On Thu, May 14, 2020 at 9:33 PM kdoh82 notifications@github.com wrote:

You can do this currently with the integration as it is. When the lights get added to HA as an entity you can simply call the service "light.turn_on" or "light.turn_off" as part of your automations. Is there something I'm missing here that you're trying to do?

On Thu, May 14, 2020 at 6:28 PM jfarmer08 notifications@github.com wrote:

I just want to see what the response of those people following this repo on adding the Wyze Cam as switch. So my thought is from the app you can turn the camera on and off, way not add this function to HA, but before I go any further is it worth it.

I see this as being good, When i am home I can create or automation and have HA turn the cameras off and when i leave turn them back on.

[image: image] < https://user-images.githubusercontent.com/18117255/81991913-54870780-9610-11ea-9889-dfdc922ff604.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48, or unsubscribe < https://github.com/notifications/unsubscribe-auth/AOPJRXJEL5YQURKMEO7QDZ3RRRWATANCNFSM4NBCP62Q

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-628973498, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEKHFBZ3RWYU2EMGW25I3YTRRSLYBANCNFSM4NBCP62Q .

-- Thanks Allen :)

kdoh82 commented 4 years ago

My mistake... (slowly walks backward out of the room)

On Thu, May 14, 2020 at 9:59 PM jfarmer08 notifications@github.com wrote:

This is for the camera. So that you can turn it on or off. not for the Light.

On Thu, May 14, 2020 at 9:33 PM kdoh82 notifications@github.com wrote:

You can do this currently with the integration as it is. When the lights get added to HA as an entity you can simply call the service "light.turn_on" or "light.turn_off" as part of your automations. Is there something I'm missing here that you're trying to do?

On Thu, May 14, 2020 at 6:28 PM jfarmer08 notifications@github.com wrote:

I just want to see what the response of those people following this repo on adding the Wyze Cam as switch. So my thought is from the app you can turn the camera on and off, way not add this function to HA, but before I go any further is it worth it.

I see this as being good, When i am home I can create or automation and have HA turn the cameras off and when i leave turn them back on.

[image: image] <

https://user-images.githubusercontent.com/18117255/81991913-54870780-9610-11ea-9889-dfdc922ff604.png

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AOPJRXJEL5YQURKMEO7QDZ3RRRWATANCNFSM4NBCP62Q

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-628973498 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AEKHFBZ3RWYU2EMGW25I3YTRRSLYBANCNFSM4NBCP62Q

.

-- Thanks Allen :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-628981112, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPJRXN5Q3XRDC3VFT5QNOLRRSOZTANCNFSM4NBCP62Q .

zas0006 commented 4 years ago

This would be a really great addition, IMHO

SecKatie commented 4 years ago

@jfarmer08 I think that is a fantastic idea. I don't have the time to develop that but it would be a great addition.

jfarmer08 commented 4 years ago

@JoshuaMulliken @markrickert I have added support to HA to add Wyze Cam using RTSP/FFMPEG. I have also gotten the service to work with shutting down the stream and starting the stream. This is the main part that I wanted to add. I do have issues with one camera that will shut down the RTSP stream and i have to restart the camera or open the app to stop and start the stream. Now I would be able to do this using HA.

All that is left to do is test and more code clean up so if anyone would like to help please let me know and I will update my repo. Also if anyone know more about FFMPEG that could help with ARGUMENTS to fine tune this.

I am getting 1 error that does not seem to affect anything, but i would like to fix it. I am pretty sure its caused by the stream trying to get a snapshot. 2020-05-20 16:22:13 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/haffmpeg/tools.py", line 45, in getimage image, = await self._loop.run_in_executor(None, proc_func) File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.7/subprocess.py", line 964, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "/usr/local/lib/python3.7/subprocess.py", line 1735, in _communicate data = os.read(key.fd, 32768) OSError: [Errno 9] Bad file descriptor

jfarmer08 commented 4 years ago

If anyone has time please feel free to help me with camera support.

https://github.com/jfarmer08/ha-wyzeapi/tree/Camera

lmontin commented 4 years ago

Hi. great work! I have wyze cam v2 with rtsp. I tried your instructions. I have this in config yaml ( I wanted to confirm it is the camera MAC as seen in app device info right ? ) wyzeapi: username: xxx password: xxx sensors: false light: false switch: false lock: false camera: MACADDRESSS??: username: xx password: xxxx

the camera username/password is from the rtsp:// url setup . I can connect to the livestream using vlc with those credentials

when i restart HA i get this error

Log Details (ERROR) Logger: homeassistant.core Source: custom_components/wyzeapi/camera.py:57 First occurred: 5:47:21 AM (1 occurrences) Last logged: 5:47:21 AM

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 285, in async_add_entities for entity in new_entities File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 282, in self._async_add_entity( # type: ignore File "/config/custom_components/wyzeapi/camera.py", line 36, in async_add_entities(WyzeCamera(hass, camera) for camera in await hass.data[DOMAIN]["wyzeapi_account"].async_list_camera()) File "/config/custom_components/wyzeapi/camera.py", line 57, in init self._ffmpeg = hass.data[DATA_FFMPEG] KeyError: 'ffmpeg'

lmontin commented 4 years ago

i realised i have installed any kind of ffmpeg before .. do i need to do that first ? something like this http://jollejolles.com/installing-ffmpeg-with-h264-support-on-raspberry-pi/

jfarmer08 commented 4 years ago

What version of HA are you using? Also what type of install? You do have to have FFMpeg but i thought HA would install it for us.

jfarmer08 commented 4 years ago

Also need to note. that the config options do not currently work for the camera.. The Username and password are hardcoded as admin:admin. You will have to change it in the camera.py

lmontin commented 4 years ago

Thanks . I updated the user/pwd directly in camera.py and also I had to add this to my config yaml
ffmpeg: ffmpeg_bin: /usr/bin/ffmpeg

now no errors and I get boxes in the overview UI for my 2 cams. I click to view video and it shows a video control box but shows a "loading" spinner and it doesnt show video .

I am using HA v 0.112.0.dev20200606

jfarmer08 commented 4 years ago

Are you using a raspberry pi? It could be running out of memory.

jfarmer08 commented 4 years ago

@lmontin Were you able to see the cameras?

lmontin commented 4 years ago

after i upgraded HA to 0.112.0.dev20200624 it magically worked . So yes I can now see the live stream. yes i am on a rasp pi 4 2gb. I am running HA on docker.

i am also able to turn the cam on and off using the camera.on/off service .. so i can use it in automatons using person / presence etc . this is a fairly major feature which a lot of people have been asking for eg https://forums.wyzecam.com/t/home-assistant-integration/3971/181 .. maybe you should post there as you will get a lot of people wanting to help test this .

SecKatie commented 4 years ago

@lmontin Great!!

jfarmer08 commented 4 years ago

@lmontin @JoshuaMulliken This is working, but i am not sure its the way to go.. I have been using Motion Eye for the cameras and its seems more stable then using HA. What are your thoughts?

SecKatie commented 4 years ago

@jfarmer08 I had some success with the camera in HA but you are right it is not great. I havn't tried MotionEye I might attempt to set that up soon.

kdoh82 commented 4 years ago

motionEye is definitely the way to go especially if you're wanting to see the camera feed live. HA only updates the preview every 10 seconds so if you're trying to do anything like object recognition/alerts it's not the most efficient.

On Tue, Jul 7, 2020 at 10:22 AM Joshua Mulliken notifications@github.com wrote:

@jfarmer08 https://github.com/jfarmer08 I had some success with the camera in HA but you are right it is not great. I havn't tried MotionEye I might attempt to set that up soon.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-654898695, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOPJRXPG5Z2HO3Z5QWLPAC3R2MVT7ANCNFSM4NBCP62Q .

lmontin commented 4 years ago

my use case is just to use HA automation ( w HA presence etc ) to turn the cams on and off. I dont need the live stream in HA as I will just use the app on my phone to see stream and get alerts. I dont want to set up motion eye .. I just want to control cam on/off using HA abilities so for me its great ( until / if wyze offer API / HA support )

SecKatie commented 4 years ago

Hmm so it sounds like we might want to merge the on/off functionality but leave out the stream.

jfarmer08 commented 4 years ago

Yeah i agree that is the way to go. It should not be hard to add as a switch.

SecKatie commented 4 years ago

@jfarmer08 once i get my ha system back up and running I will try to get that done

zas0006 commented 4 years ago

This sounds like a great way to move forward. I too use MotionEye for the streams as it is much more reliable than HA (zoneminder is good too, and allows for even more control of recording/motion detection in HA, but is much heavier to run) but would love to just turn the cameras on/off based on presence, rules, etc.

On Tue, Jul 7, 2020 at 11:46 AM Joshua Mulliken notifications@github.com wrote:

@jfarmer08 https://github.com/jfarmer08 once i get my ha system back up and running I will try to get that done

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-654953672, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACRXUV7VW6RPFRMP4XJPVR3R2M7ONANCNFSM4NBCP62Q .

Mincka commented 4 years ago

Hello,

Thank you for this integration! This is the closest from what I'd like to do. Great stuff from @jfarmer08 also. I tested successfully the camera support.

Even if the camera support is a great addition, I think you are right about the fact that the streaming support should not be added, or I should say, not like this.

In my case, I still have both RTSP et non-RTSP Wyze cameras. It is clear that Wyze will not open the path for an long term RTSP support for me. There is no sign of it for their latest outdoor camera so it is safe to say that we should not expect new RTSP firmware anytime soon.

I needed to go back to the "master" firmware because I wanted to have Continuous Motion Recording (CMC). So I think we should focus on the support of features that are aligned with the master branch and drop the RTSP streaming support.

There is still some room for things like turn on / turn off like you said, but also for the integration of events, with the data retrieved from the API.

My idea is to use the Events view data to retrieve the latest camera events. I am confident that it would be possible to use it to fire events on the hass bus. However, I am not sure how to present the data in HA. I think a sensor per camera with the timestamp of the latest event as a state (like the last boot sensor) could to the trick. The other attributes of the sensor would include the temporarily links to Amazon with the uploaded video clips and the latest still preview.

In this end, this would allow people using the latest master branch firmware to trigger automations without relying on third-party tricks (IFTTT or triggers based on sent e-mails...). In my case, I would use this to download the video clips locally and use video and still images for rich notifications on mobile. 😄

Finally, if streaming support should be implemented, it would ideally based on the native TUTK protocol, but that's a complete another story. I did not find anyone attempting to implement it with Python.

What do you think about the camera "event sensors"? I could try to include it with this integration.

lmontin commented 4 years ago

great idea. I thought cam on/off access etc was only available with RTSP firmware? .. but if it isnt coupled to that then it would be even better to just have control and event access with normal firmware !!

SecKatie commented 4 years ago

I think the on/off is available for all firmware versions. @Mincka I would be very happy to accept a PR that pulls events from the cameras!

jfarmer08 commented 4 years ago

Yes the on/off is available thru the api.

dimmanramone commented 4 years ago

@jfarmer08 @JoshuaMulliken Turning on/off the cameras sounds really good. Anyway to turn on/off the notifications and turn on/off motion detection?

jfarmer08 commented 4 years ago

@dimmanramone @JoshuaMulliken Yes, You can get Notifications and Motion settings from the API. For example PID value P1001 is Event Recording / Detects Motion and PID value P1002 is Event Recording / Detects Sound. Someone will need to run thru the app comparing the PID returns to get the rest.

The above is the current state of the switches, but i am not sure if you can control the property.

dimmanramone commented 4 years ago

@jfarmer08 @JoshuaMulliken

Great. Maybe we can even get a service in the integration that we can post to the API PID values and deviceId to turn these kind of settings or on off?

fabriba commented 3 years ago

@JoshuaMulliken I don't particularly need the RTSP feature at this stage and I'd rather stay on a better maintained firmware, but I would like the ability to trigger automations on home assistant when my wyzecam detects motion (or ideally when it detects people). Can I get those from the API without moving to RTSP firmware?

SecKatie commented 3 years ago

@JoshuaMulliken

I don't particularly need the RTSP feature at this stage and I'd rather stay on a better maintained firmware, but I would like the ability to trigger automations on home assistant when my wyzecam detects motion (or ideally when it detects people). Can I get those from the API without moving to RTSP firmware?

I don't think so because it would have to be constantly polling the server. This would be a major issue for performance and might be considered bad behavior by WyzeLabs.

SecKatie commented 3 years ago

@fabriba A solution might be to use IFTTT. Wyze can push through ifttt to a webhook in homeassistant if a camera detects motion.

image

Mincka commented 3 years ago

The component is already polling the API on a regular basis so I don't think it could be an issue with the default polling. IFTTT is known to be unreliable. I am not expecting "real time" events from this feature since the events for cameras only appear when the capture is complete so at least 15 seconds after the event.

I didn't have too much time to work on it (and dev setup took me a while since that's the first component I am working on), but I started to analyze the API response.

I am able to get the following information:

I think it would be also possible to easily detect CO and smoke alarm events and extend it to any device.

My idea is to browse through the devices and create a "last_event" sensor like this: sensor.camera1_last_event. Its value would be the last event time and the additional property would be the metadata given by the API (URLs of media, type of detection, person detection...) For instance, it would allow me to use show the still capture in a Home Assistant notification for every motion and trigger some other automation only for person detection. I read iOS also supports video in notifications.

I hope I will be able to share a PoC in a few days. I reused some parts of @jfarmer08's fork (to enumerate the cameras).

SecKatie commented 3 years ago

@Mincka when you have the code I would love to help with the pull request

LordNex commented 3 years ago

I would love if you could get native support for Wyze cams in HA. I can bring any RTSP camera in and they have a beta firmware. But cameras like the Outdoor Cam cannot support RSTP due to the nature of the API and battery usage. But if you could pull the cameras directly from the Wyze api that would be sweet. Really I don't understand why Wyze doesn't open up thier code a bit more. I would guess that over 50% of thier users are techies and are hacking thier hardware is someway or form anyway.

LordNex commented 3 years ago

@fabriba A solution might be to use IFTTT. Wyze can push through ifttt to a webhook in homeassistant if a camera detects motion.

image

I'm currently doing this with thier outdoor cam. I'm basically doing a webhook call and monitoring the ifttt_webhook_received event. When that occurs I have it set to send a tts to my Google speakers. Then send a push notification to our iPhones. The problem is though that I can't get an image or video support for the outdoor cams. The pan cams with the rstp firmware work perfect though and I can push the video.

LordNex commented 3 years ago

If anyone has time please feel free to help me with camera support.

https://github.com/jfarmer08/ha-wyzeapi/tree/Camera

Could you explain if anything needs to be done to add this to HA and try? I have the master installed under HACS but I didn’t know if I needed to add this as a custom HACS repository or if it had been merged yet. I currently have 4 Pan Cams on RSTP and one Outdoor Cam that I would love to use this with.

Ultimately I’d prefer to leave the rstp and go back to standard firmware. Not to mention I would really like to integrate the Outdoor Cam. It doesn’t need a constant stream, periodic updates are fine for Lovelace cards and then I can click on them to trigger the stream. Currently I’m doing this through a bunch of hacks so if you get this working I’d be stoked. Also, have you tried adding and controls to the PTZ ability of the Pan Cam? That would put it over he top and be a true integration HA should natively adapt if you get it to work!

paulmorabito commented 3 years ago

I'm coming to this a little late only having just gotten into HA and purchased a Wyze Cam Pan model. I agree that implementing RTSP via this is unnecessary and I have found that using MotionEye is great for integrating cameras into HA. Also, you can use Frigate for the motion and object detection though I have found my RPI4 struggles with it given it really needs a separate GPU/ML processor.

That leaves only the switches, sensors and statuses. I noticed on the Xiaomi DaFang custom firmware that when you integrate with HA you get a range of these (see here). Would it be possible to add these?

SecKatie commented 3 years ago

@paulmorabito It appears that it is already supported though the page you just showed? I don't think we should add support for any non stock Wyze devices to this integration as it might confuse some users.

paulmorabito commented 3 years ago

@JoshuaMulliken That page is for alternative firmware that works for both Wyze and Xiaomi branded devices (with the reason being they are internally identical and made by the same supplier but with different branding and firmware). I agree it's not a good idea to support non Wyze devices. What I meant was this - If you use the alternative firmware then it is possible to have different sensors and switches for Wyze cameras IN HA. I was curious as to whether it is possible to do similar with Wyze API also but without changing the firmware on the Wyze camera?

LordNex commented 3 years ago

This is what thousands of people have been waiting for. If Wyze would just open up their API and allow a direct integration to be built properly instead of having to hack one together they’d make a killing. Honestly I won’t be purchasing anything from them anymore until they do so. There are just too many other options out there that do integrate well.

Josh, I feel ya bud. It’s a pain to do. But if you could and it does work. There would probably be some people who would happy donate a bit for your time. Just a thought anyway. Once I feel comfortable enough with Python I’ll try. But that’ll probably be a bit at my pace.

On Jan 3, 2021, at 2:02 AM, paulmorabito notifications@github.com wrote:



@JoshuaMullikenhttps://github.com/JoshuaMulliken That page is for alternative firmware that works for both Wyze and Xiaomi branded devices (with the reason being they are internally identical and made by the same supplier but with different branding and firmware). I agree it's not a good idea to support non Wyze devices. What I meant was this - If you use the alternative firmware then it is possible to have different sensors and switches for Wyze cameras IN HA. I was curious as to whether it is possible to do similar with Wyze API also but without changing the firmware on the Wyze camera?

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/JoshuaMulliken/ha-wyzeapi/issues/48#issuecomment-753582381, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACGXNJDUHD34AIBZMCPZ5ATSYAP7ZANCNFSM4NBCP62Q.

shauntarves commented 3 years ago

@LordNex @paulmorabito @dimmanramone @Mincka @lmontin @jfarmer08

I have been working with @JoshuaMulliken to reverse-engineer a generic wyze API. I've finally cracked what they're doing in their newer requests and how they hit their own API. We now have full support for the bulbs, plugs/switches, and the new vacuum. I would love to add support for more devices, but I need someone who has these devices to be willing to work with me directly and share some access/data to I can make the code work. If you're interested in helping out, please email shaun <at> tarves <dot> net

jfarmer08 commented 3 years ago

@shauntarves I am willing to share what i have with no issues. Below is a list of what i have, but I think you have covered it all.

  1. Wyze Pan
  2. Wyze V2
  3. Bulbs
  4. Switch
  5. Scale
  6. Band
shauntarves commented 3 years ago

@jfarmer08 that's awesome - hit me up direct at the email above please - when you do, I'll add you to our slack team

lmontin commented 3 years ago

@shauntarves i have a couple of wyze cam v2s i can test.. I'm using HA on raspi with docker

jscherry commented 3 years ago

I have v2, pancam, v3 cameras, scale, lock and would also be glad to help. Not familiar with snooping programs but learn quickly

shauntarves commented 3 years ago

@jscherry and @lmontin - hit me up direct at the email above please - when you do, I'll add you to our slack team

paulmorabito commented 3 years ago

I've got the Wyze Cam Pan and happy to also contribute. I'm in the middle of an international house move at the moment so likely won't have it in my hands again until middle April though.