fuatakgun / eufy_security

Home Assistant integration to manage Eufy Security devices as cameras, home base stations, doorbells, motion and contact sensors.
847 stars 73 forks source link

The Eufy Security Integration does not receive all push messages from Eufy Security Add-on #703

Closed witold-gren closed 1 year ago

witold-gren commented 1 year ago

Describe the bug

While using this plugin, I noticed that it does not process all sent messages. When motion is detected by my camera T8151 (Eufy Security 4G LTE) I noticed that there is no logs/action in the plugin.

To reproduce

Steps to reproduce the behavior:

  1. Turn on device notifications in T8151 device
  2. Enable DEBUG mode in eufy add-on
  3. Trigger the motion on camera
  4. Check logs from Eufy Security Add-on
  5. Check the logs in HA on this plugin

Expected behavior

I would expect that even if this notification is not supported, I would see some log.

Additional information

Go to Settings -> System -> Repairs -> Click on 3 dots (...) -> System Information and get Version and Installation Type to below fields;

Hardware Information;

Additional context

I would like to add support for motion detection without a photo and with a photo. I would also like the relevant entities in Home Assistant to update as well.

fuatakgun commented 1 year ago

Hey @witold-gren, there are some push notifications i intentionally skip such as motion detected, person detected, alarm, snooze etc because all these events are also generating a secondary event called property_changed for respective attributes.

I will take simplest example, motion detected event and its respective attribute motionDetected.

Whenever there is an event generated as motion detected, it is immediately followed by property_changed event for motionDetected to True. In my local setup (homebase 2, 4 pieces 2c cameras and one indoor pan tilt) this setup is working fine.

So, given all these, why would we want to explicitly catch motion detected event?

Example below;

2023-01-21 15:38:05.640 DEBUG (MainThread)[custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'device', 'event': 'property changed', 'serialNumber': 'T8113xxx', 'name': 'motionDetected', 'value': True}} 2023-01-21 15:38:05.678 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'device', 'event': 'motion detected', 'serialNumber': 'T8113xxx', 'state': True}}

witold-gren commented 1 year ago

So.. what I noticed is that for camera T8151 we completely don't have this kind of property_changed events. So for me this is a problem because it look like Eufy Security Add-on still not fully support all events (or that is the way how works eufy api service for specific devices) like for others devices. My idea was to try to add this kind of events until it is added/fixed in Eufy Security Add-on. Maybe there is an option to enable these events for specific devices (in HA settings)?

I fully understand your concept of the plugin and the fact that you would not want to duplicate these events, but from my perspective, adding these events is the only option for the correct operation of automation for the indicated cameras (of course, I can also wait for update the add-on, but I have no idea when it will happen 😀).

I also wonder what the reason we have two type of events, and for some cameras they work differently than for the other kind of devices. Is this the action of this add-on or maybe the Eufy api service works like that..

MaikB1972 commented 1 year ago

Hello, may I have the same issue? I am presenting the switches for my installes cameras in Lovelace. Unfortunately some of them don't update when I disable/enable the cameras in my mobile eufy-app (android and ios). But I can disable/enable the cameras using the switches in Lovelace. So the push events from Lovelace/HA seem to be send to Eufy, but the pushes from Eufy to HA are either not send or don't come through. Interesting is, that for some of my cameras both directions work (like my Solocam), for others not. Another point is, that I have most of my cameras connected to the Homebase 3.

It is the same behaviour as in #669.

fuatakgun commented 1 year ago

Why don't we spend our time and energy to fix these under eufy-security-ws? Everyone would receive the benefits?

At least, i will do accordingly

MaikB1972 commented 1 year ago

Hi fuatakgun, I appreciate you effort. Unfortunately my programming experience ended more than 7 years ago and I am trying to get into it again playing with my HA. And I am more than happy where I am now. If I can help you with something please let me know. I will do my best, but I cannot promise anything.

fuatakgun commented 1 year ago

Fair enough, what do you think @witold-gren

witold-gren commented 1 year ago

I can try, but when it comes to python, I have a lot of experience, if we talk about it TypeScript I don't have much experience here.

fuatakgun commented 1 year ago

Ok, let's introduce these hopefully temporary hacks here, would you do this for as many as events @witold-gren ?

witold-gren commented 1 year ago

All I can try to do is add support for events that I can see locally. I was thinking about adding an additional variable to the configuration that would enable and disable this functionality. This means that you don't follow events if you don't want to, but you use them if you want to. The second thing is the approach.. we can, for example, do a simple conversion of those events to property_changed and just update property when we will have this kind of events..

The last question is can you tell me how to enable all events? I haven't fully understood the whole code yet 😀

fuatakgun commented 1 year ago

makes sense, let's define a constant enum to map Event Name to respective Property (motion detected -> motionDetected) and generate property_changed on the fly.

Do you want to pick this up or I can do it.

witold-gren commented 1 year ago

If you have a time you can do it.. of course, I can also think about it, but I certainly won't do it as quickly as you. I'm just wondering how to do it in such a way that in the future you don't have to, for example, remove the code when the library is updated 😀 I'd rather see it as an extra ability to track changes, rather than something we're adding and later we will remove

witold-gren commented 1 year ago

Hey @fuatakgun 👋🏻 I finally found a time to check what happen (sorry but I also support other projects).. after a little investigation, it turns out that this is a eufy and eufy-security-client problem. The main problem is related with the type of message how eufy inform about motion detected.. above is an example of such a message. We should pay attention to this key event_type: undefined. If you check it in the library itself eufy-security-client: https://github.com/bropat/eufy-security-client/blob/master/src/eufysecurity.ts#L947

you will find two executions:

  1. For Station: https://github.com/bropat/eufy-security-client/blob/master/src/http/station.ts#L464
  2. For Device: https://github.com/bropat/eufy-security-client/blob/master/src/http/device.ts#L662

as you can see in my case the message is not handled for the relevant devices and this is the reason why it is not visible in the logs. The only option to fix this is to add additional logic that emits the appropriate events.

fuatakgun commented 1 year ago

Great news @witold-gren , thanks for deep dive, would you raise a PR in eufy-security-client?

witold-gren commented 1 year ago

Hey @fuatakgun , I'm working on this a bit now, unfortunately it's more complicated than I described above.. so far what I've actually found are errors in the correct formatting of the raw answer (it's already been fixed by me..) but I'll keep checking what is the problem really. When I have more information, I'll let you know 😀

NunoMCMoreira commented 1 year ago

I saw something about eufy notification on the app saying, "when we ask full notification mensage abou motion it saves one thumbnail on the hub"

Do we have access to this image, because this way instead we create a image we could use the one automatic created by eufy, that one is really quick.

Screenshot_2023-02-10-16-34-32-247_com oceanwing battery cam