fuatakgun / eufy_security

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

Cameras not arming #690

Closed Ringo982 closed 1 year ago

Ringo982 commented 1 year ago

Hello I'm experimenting problems with the last version of Eufy add-on on the last version of Home Assistant. All my automations that arm_home or arm_away my cameras and Homebase's stopped working. I have homebase2, homebase3, indoor 2k cameras and outdoor 2k cameras, and if I try to run the automations that arm the cameras the status (away or home) does not change anymore.

I have checked add-on and HA logs but I do not find any error.

Can you help please? I'm available to do all the test you need to debug better this issue.

If it is a known issue please inform me.

Thank you very much

Francesco

witold-gren commented 1 year ago

Hey, I have similar issue.. I will say little more.. I tested how camera work with incoming "Received push message " for specific device (T8151) and my observations is that it also stop working even it it works in Eufy Security Add-on. Quick example from DEBUG mode in Eufy Security Add-on:

2023-01-14 18:39:19.448  DEBUG [PushNotificationService.onMessage] Normalized push message received 
{
  name: '',
  event_time: 1673721558681,
  type: 110,
  station_sn: 'T8151P3022070514',
  device_sn: 'T8151P3022070514',
  title: 'eufyCam Solo',
  content: 'Someone has been spotted',
  push_time: 1673721559375,
  channel: undefined,
  cipher: undefined,
  event_session: '20230114_193918',
  event_type: undefined,
  file_path: '',
  pic_url: 'https://security-app-eu.eufylife.com/v1/s/g/123123123',
  push_count: 1,
  notification_style: 2,
  tfcard_status: undefined,
  alarm_delay_type: undefined,
  alarm_delay: undefined,
  alarm_type: undefined,
  sound_alarm: undefined,
  user_name: undefined,
  user_type: undefined,
  user_id: undefined,
  short_user_id: undefined,
  station_guard_mode: undefined,
  station_current_mode: undefined,
  person_name: undefined,
  sensor_open: undefined,
  device_online: undefined,
  fetch_id: undefined,
  sense_id: undefined,
  battery_powered: undefined,
  battery_low: undefined,
  storage_type: 1,
  unique_id: '687db6795fcf953b8bf7f9a123123123',
  automation_id: undefined,
  click_action: undefined,
  news_id: undefined
}
2023-01-14 18:39:19.448  DEBUG [EufySecurity.onPushMessage] Received push message 
{
  name: '',
  event_time: 1673721558681,
  type: 110,
  station_sn: 'T8151P3022070514',
  device_sn: 'T8151P3022070514',
  title: 'eufyCam Solo',
  content: 'Someone has been spotted',
  push_time: 1673721559375,
  channel: undefined,
  cipher: undefined,
  event_session: '20230114_193918',
  event_type: undefined,
  file_path: '',
  pic_url: 'https://security-app-eu.eufylife.com/v1/s/g/123123123',
  push_count: 1,
  notification_style: 2,
  tfcard_status: undefined,
  alarm_delay_type: undefined,
  alarm_delay: undefined,
  alarm_type: undefined,
  sound_alarm: undefined,
  user_name: undefined,
  user_type: undefined,
  user_id: undefined,
  short_user_id: undefined,
  station_guard_mode: undefined,
  station_current_mode: undefined,
  person_name: undefined,
  sensor_open: undefined,
  device_online: undefined,
  fetch_id: undefined,
  sense_id: undefined,
  battery_powered: undefined,
  battery_low: undefined,
  storage_type: 1,
  unique_id: '687db6795fcf953b8bf7f9a123123123',
  automation_id: undefined,
  click_action: undefined,
  news_id: undefined
}

this is log from add-on, but I didn't see any changes in Home Assistant entity. Is anything what I can do to fix this issue? 😀I double check it and for HomeBase 2 it works correctly.. it only not work for camera T8151.

Ringo982 commented 1 year ago

Hey, I have similar issue.. I will say little more.. I tested how camera work with incoming "Received push message " for specific device (T8151) and my observations is that it also stop working even it it works in Eufy Security Add-on. Quick example from DEBUG mode in Eufy Security Add-on:

2023-01-14 18:39:19.448  DEBUG [PushNotificationService.onMessage] Normalized push message received 
{
  name: '',
  event_time: 1673721558681,
  type: 110,
  station_sn: 'T8151P3022070514',
  device_sn: 'T8151P3022070514',
  title: 'eufyCam Solo',
  content: 'Someone has been spotted',
  push_time: 1673721559375,
  channel: undefined,
  cipher: undefined,
  event_session: '20230114_193918',
  event_type: undefined,
  file_path: '',
  pic_url: 'https://security-app-eu.eufylife.com/v1/s/g/123123123',
  push_count: 1,
  notification_style: 2,
  tfcard_status: undefined,
  alarm_delay_type: undefined,
  alarm_delay: undefined,
  alarm_type: undefined,
  sound_alarm: undefined,
  user_name: undefined,
  user_type: undefined,
  user_id: undefined,
  short_user_id: undefined,
  station_guard_mode: undefined,
  station_current_mode: undefined,
  person_name: undefined,
  sensor_open: undefined,
  device_online: undefined,
  fetch_id: undefined,
  sense_id: undefined,
  battery_powered: undefined,
  battery_low: undefined,
  storage_type: 1,
  unique_id: '687db6795fcf953b8bf7f9a123123123',
  automation_id: undefined,
  click_action: undefined,
  news_id: undefined
}
2023-01-14 18:39:19.448  DEBUG [EufySecurity.onPushMessage] Received push message 
{
  name: '',
  event_time: 1673721558681,
  type: 110,
  station_sn: 'T8151P3022070514',
  device_sn: 'T8151P3022070514',
  title: 'eufyCam Solo',
  content: 'Someone has been spotted',
  push_time: 1673721559375,
  channel: undefined,
  cipher: undefined,
  event_session: '20230114_193918',
  event_type: undefined,
  file_path: '',
  pic_url: 'https://security-app-eu.eufylife.com/v1/s/g/123123123',
  push_count: 1,
  notification_style: 2,
  tfcard_status: undefined,
  alarm_delay_type: undefined,
  alarm_delay: undefined,
  alarm_type: undefined,
  sound_alarm: undefined,
  user_name: undefined,
  user_type: undefined,
  user_id: undefined,
  short_user_id: undefined,
  station_guard_mode: undefined,
  station_current_mode: undefined,
  person_name: undefined,
  sensor_open: undefined,
  device_online: undefined,
  fetch_id: undefined,
  sense_id: undefined,
  battery_powered: undefined,
  battery_low: undefined,
  storage_type: 1,
  unique_id: '687db6795fcf953b8bf7f9a123123123',
  automation_id: undefined,
  click_action: undefined,
  news_id: undefined
}

this is log from add-on, but I didn't see any changes in Home Assistant entity. Is anything what I can do to fix this issue? 😀I double check it and for HomeBase 2 it works correctly.. it only not work for camera T8151.

Solved using Guard Mode instead of Alarm Control Panel to set the state home/away

witold-gren commented 1 year ago

In the case of this specific camera T8151, even Guard Mode does not work. The most missing information for me is when an alarm is triggered.

witold-gren commented 1 year ago

I enabled debug mode in logs, and that is result from plugin:


IN EUFY APP SET SECURITY TO "AWAY" STATE

2023-01-15 19:04:35.932 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'guard mode changed', 'serialNumber': 'T8151P3022070514', 'guardMode': 0}}
2023-01-15 19:04:35.933 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'property changed', 'serialNumber': 'T8151P3022070514', 'name': 'guardMode', 'value': 0}}
2023-01-15 19:04:35.951 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'current mode changed', 'serialNumber': 'T8151P3022070514', 'currentMode': 0}}
2023-01-15 19:04:35.951 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'property changed', 'serialNumber': 'T8151P3022070514', 'name': 'currentMode', 'value': 0}}

THE ALARM HAS BEEN ARMED

2023-01-15 19:05:45.614 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7}}

THE ALARM HAS BEEN TRIGGERED

2023-01-15 19:05:58.439 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'guard mode changed', 'serialNumber': 'T8151P3022070514', 'guardMode': 63}}
2023-01-15 19:05:58.444 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'property changed', 'serialNumber': 'T8151P3022070514', 'name': 'guardMode', 'value': 63}}
2023-01-15 19:05:58.459 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'current mode changed', 'serialNumber': 'T8151P3022070514', 'currentMode': 63}}
2023-01-15 19:05:58.459 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'property changed', 'serialNumber': 'T8151P3022070514', 'name': 'currentMode', 'value': 63}}

DISABLE ALARM

2023-01-15 19:08:18.801 DEBUG (MainThread) [custom_components.eufy_security] image 1 - False - None
2023-01-15 19:08:18.802 DEBUG (MainThread) [custom_components.eufy_security] async_camera_image 5 - is_empty True

but even if I see some events _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7}} it is not set directly in any entity in home assistant devices.. 🤔

witold-gren commented 1 year ago

So small summary, from my small investigation I see that I can not change any params for this specific devices in Home Assistant (T8151), but the problem is not this plugin, this is more of a problem with Eufy Security Add-on:

2023-01-15 19:22:14.349  WARN Station T8151P3022070514 - Tried all hosts, no connection could be established 
2023-01-15 19:22:14.350  INFO  Timeout connecting to station T8151P3022070514 
2023-01-15 19:32:15.699  WARN Station T8151P3022070143 - Tried all hosts, no connection could be established 
2023-01-15 19:32:15.701  INFO  Timeout connecting to station T8151P3022070143 
2023-01-15 19:32:34.057  WARN Station T8151P3022070514 - Tried all hosts, no connection could be established 
2023-01-15 19:32:34.059  INFO  Timeout connecting to station T8151P3022070514 
2023-01-15 19:42:35.551  WARN Station T8151P3022070143 - Tried all hosts, no connection could be established 
2023-01-15 19:42:35.568  INFO  Timeout connecting to station T8151P3022070143 
2023-01-15 19:42:52.574  WARN Station T8151P3022070514 - Tried all hosts, no connection could be established 
2023-01-15 19:42:52.575  INFO  Timeout connecting to station T8151P3022070514 

every time I change any parameter I have a message with SUCCESS message is SUCCESS - {'type': 'result', 'success': True, 'messageId': 'station.set_property.2c75570a4f884a9f9a757055d9d78af6', 'result': {'async': True}} but few second later I have a event with connection error: _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'connection error', 'serialNumber': 'T8151P3022070514'}} it means that this addon can't set camera parameters yet

witold-gren commented 1 year ago

However, I discovered another problem with triggering the alarm, Eufy Security Add-on correctly inform about alarm event:

2023-01-15 20:06:56.330  INFO  Received push notification for alarm event
{
  stationSN: 'T8151P3022070514',
  alarmType: 7
}

but this plugin can not correctly proceed this event (I added some more logs to investigate this event):

2023-01-15 21:06:56.334 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _on_message - {'type': 'event', 'event': {'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7}}
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] typ event - {'type': 'event', 'event': {'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7}}
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] station or device - Event(type='alarm event', data={'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7})
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] _stations
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] product: <custom_components.eufy_security.eufy_security_api.product.Station object at 0x7fda0f5dc880>
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] process_event: Event(type='alarm event', data={'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7})
2023-01-15 21:06:56.335 DEBUG (MainThread) [custom_components.eufy_security.eufy_security_api] except ValueError: Event(type='alarm event', data={'source': 'station', 'event': 'alarm event', 'serialNumber': 'T8151P3022070514', 'alarmEvent': 7})

it shows that this event is not supported here: https://github.com/fuatakgun/eufy_security/blob/master/custom_components/eufy_security/eufy_security_api/product.py#L92 is there any chance to fix it? 😀

witold-gren commented 1 year ago

If we need add support for this kind of devices we need add also support for alarm event. I prepared small PoC and tomorrow I will test it. 😀

eufy_security_api/const.py:

class TypeAlarmEvent(Enum):
    """Type of alarm event"""
    ALARM_ENABLED_AFTER_ALARM_ARM_DELAY = 0
    ALARM_TRIGGERED_DUE_TO_MOTION_DETECTED = 7
    ALARM_TRIGGERED_AFTER_ALARM_DELAY = 8
    ALARM_HAS_BEED_TURNED_OFF_VIA_THE_APP = 16

# https://bropat.github.io/eufy-security-ws/#/api_events?id=device-level-events
class EventNameToHandler(Enum):
    """Handler names to incoming event types"""

    verify_code = "verify code"
    captcha_request = "captcha request"
    property_changed = "property changed"
    got_rtsp_url = "got rtsp url"
    livestream_started = "livestream started"
    livestream_stopped = "livestream stopped"
    rtsp_livestream_started = "rtsp livestream started"
    rtsp_livestream_stopped = "rtsp livestream stopped"
    livestream_video_data_received = "livestream video data"
    livestream_audio_data_received = "livestream audio data"
    pin_verified = "pin verified"
    alarm_event = "alarm event"

eufy_security_api/product.py:

class Product:
    ...
    async def _handle_alarm_event(self, event: Event):
        self.properties["alarmType"] = event.data[MessageField.ALARM_EVENT.value]
        if event.data[MessageField.ALARM_EVENT.value] in [
                TypeAlarmEvent.ALARM_TRIGGERED_DUE_TO_MOTION_DETECTED, TypeAlarmEvent.ALARM_TRIGGERED_AFTER_ALARM_DELAY]:
            self.properties["alarm"] = True
        elif event.data[MessageField.ALARM_EVENT.value] == TypeAlarmEvent.ALARM_HAS_BEED_TURNED_OFF_VIA_THE_APP:
            self.properties["alarm"] = False
fuatakgun commented 1 year ago

Hey, this is great but in my test, alarm attribute was updated and property changed event was received so i didn't require to handle this.

Are you saying that, you are not receiving property changed event for alarm attribute?

You can see that, i am not handling motion detected and person detected etc because all of them are coming through property changed

Ringo982 commented 1 year ago

Yes in my case alarm attribute stopped working. At the moment the only way to change the status (home/away) is using guard mode, both for homebases (2 and 3) and for all my cameras (T8400,T844,T8131,..) Thank you

fuatakgun commented 1 year ago

@Ringo982 how is alarm attribute related to guard mode? These are totally different things...

Ringo982 commented 1 year ago

@Ringo982 how is alarm attribute related to guard mode? These are totally different things...

I know this..... I'm only saying that previously I was using alarm attributes also.. it stopped working, and also stopped working the arming_home/arming_away. Now that part of issue is solved using guard mode to set home/away mode.

fuatakgun commented 1 year ago

You cannot solve missing alarm property using guard mode. You are solving missing current mode property, they are just different

fuatakgun commented 1 year ago

Summary of the overall discussion;

witold-gren commented 1 year ago

so I tested this solution with camera T8151 (Eufy Security 4G LTE). And it look like for part of devices we have event property changed but for other devices it doesn't exist. So that is the reason why I start checking all events.. I checked example above and it works correctly for me for camera T8151. Sorry but today I don't have a time to test this solution with other devices.. probably tomorrow I will do it. BTW. I discovered other events which are also send but currently it is not supported.

I'm starting to wonder if I should somehow implement them to add full support for these events to the plugin.

current_mode_changed = "current mode changed"
# Event(type='current mode changed', data={'source': 'station', 'event': 'current mode changed', 'serialNumber': 'T8010P2320390CA9', 'currentMode': 0})

alarm_arm_delay_event = "alarm arm delay event"
# Event(type='alarm arm delay event', data={'source': 'station', 'event': 'alarm arm delay event', 'serialNumber': 'T8010P2320390CA9', 'armDelay': 30})

guard_mode_changed = "guard mode changed" 
# Event(type='guard mode changed', data={'source': 'station', 'event': 'guard mode changed', 'serialNumber': 'T8010P2320390CA9', 'guardMode': 0})

alarm armed event = "alarm armed event" 
# Event(type='alarm armed event', data={'source': 'station', 'event': 'alarm armed event', 'serialNumber': 'T8010P2320390CA9'})

alarm_delay_event = "alarm delay event" 
# Event(type='alarm delay event', data={'source': 'station', 'event': 'alarm delay event', 'serialNumber': 'T8010P2320390CA9', 'alarmDelayEvent': 8, 'alarmDelay': 15}) 

those events I get it from the Eufy Base 2 and Eufy Security 4G LTE devices and comparing what changes in the mobile application. I also have other eufy devices but I haven't tested it with other types of devices yet.

fuatakgun commented 1 year ago

Thanks for looping back, we should not implement any of these, we should just rely on property changed event.

I suggest you to create an issue under eufy-security-ws and share your findings (some events are fired without property changed event).

Maybe, you can even raise a PR to fix them there.

Edit: even further, i was going to raise a PR on eufy-security-ws to remove these events and just purely rely on property changed event. So, you can locally solve these issues with relying other events but they might be gone in near future.

fuatakgun commented 1 year ago

merged into here: https://github.com/fuatakgun/eufy_security/issues/703