Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

MQTT Integration #43

Open
nonsleepr opened this issue May 27, 2020 · 19 comments
Open

MQTT Integration #43

nonsleepr opened this issue May 27, 2020 · 19 comments

Comments

@nonsleepr
Copy link
Contributor

I have limited resources right now.
It would be awesome if someone integrates that package though: https://github.com/nonsleepr/python-eufy-security-mqtt

@rschoolm
Copy link

I’ll have mine installed this weekend. I can test if you still need it.

@joepadmiraal
Copy link

I would love to test this but I am having some trouble in running the example.
I changed the variables in subscribe.py and when I run it I get this:

python3 subscribe.py
Traceback (most recent call last):
  File "subscribe.py", line 2, in <module>
    from eufy_security.mqtt import DoorbellEvents
ModuleNotFoundError: No module named 'eufy_security'

What do I need to do before I can run the example?

@nonsleepr
Copy link
Contributor Author

@joepadmiraal You need to pip install . first.

@joepadmiraal
Copy link

Thanks.

When I run it now I get this error:

Connection rejected with code '5'
Connection failed: ConnectException('Connection rejected by broker')

I got the userId by reading from the passport/login API call.
For email I used the same email address that I used in the app.
I red android_id by going into the adb shell of the emulator and running settings get secure android_id

I also changed the url to security-mqtt-eu.eufylife.com:8789 in the init file because I am based in the Netherlands.
But that gave the same results.

Googling code 5 seems to reveal it is an authentication issue.
Any idea what I could try next?

Thanks

@nonsleepr
Copy link
Contributor Author

Try running the following script (requires mosquitto-clients installed, you can get eufy.crt from the package):

#! /usr/bin/env bash
set -x

device_sn=T8200N0XXXXXXXXX
[email protected]
# adb shell settings get secure android_id
android_id=deadc0dedeadc0de

username=eufy_$user_id
password=$email
client=android_EufySecurity_${user_id}_${android_id}

mosquitto_sub \
 --cafile eufy.crt \
 -C 1 -F '%p' -N \
 -h security-mqtt.eufylife.com \
 -p 8789 \
 -t "/phone/doorbell/$device_sn/push_message" \
 -u "$username" -P "$password" -i "$client"

@joepadmiraal
Copy link

I ran this (replaced some details with X):

set -x

user_id=cc05d0a796a1877a352e7ee80XXXXXXXXXXXX

device_sn=T8010PXXXXXXXXXX
[email protected]
android_id=f404f4XXXXXXXXXX

username=eufy_$user_id
password=$email
client=android_EufySecurity_${user_id}_${android_id}

mosquitto_sub \
 --cafile eufy.crt \
 -C 1 -F '%p' -N \
 -h security-mqtt.eufylife.com \
 -p 8789 \
 -t "/phone/doorbell/$device_sn/push_message" \
 -u "$username" -P "$password" -i "$client"

Result:

mosquitto_sub --cafile eufy.crt -C 1 -F %p -N -h security-mqtt.eufylife.com -p 8789 -t /phone/doorbell/T8010PXXXXXXXXX/push_message -u eufy_cc05d0a796a1877a352e7ee80XXXXXXXXX -P [email protected] -i android_EufySecurity_cc05d0a796a1877a352e7ee80XXXXXXXXX_f404f4XXXXXXXXX
Connection error: Connection Refused: not authorised.

After it did not work I replaced the android_id with one from a real device which also has the app installed.
That gave the exact same result.
Also replaced the host with security-mqtt-eu.eufylife.com.

Is it correct that the email address is used as password?

@nonsleepr
Copy link
Contributor Author

Yes, that's how it's implemented in the Android app. Have you tried another host (security-mqtt-eu.eufylife.com) here too?

@nonsleepr
Copy link
Contributor Author

nonsleepr commented Jun 4, 2020 via email

@joepadmiraal
Copy link

I figured out I mixed up two accounts.
So now it is not giving me any errors when I start the script.
However it also does not show any events at all.

I'll create a temp account and email it to you.

@PrayerfulDrop
Copy link

@joepadmiraal

How did you execute the passport/login API to get the userid?

@joepadmiraal
Copy link

I changed api.py so it reads and exposes auth_resp["data"]["user_id"].
With that I could let test_api.py print the userId.

@PrayerfulDrop
Copy link

@joepadmiraal @nonsleepr

Thank you for the info on finding the user_id. Needed to modify the api.py in my usr/bin/lib directory.

With the above script, are you doing this to acquire a new eufy.crt that is associated to your eufy doorbell?

If I create an executable script with my user_id, serial_number and email addy I get an error that the the file cannot be found.

If I copy the file eufy.crt from the src folder to my getcert.sh location then I get "connection refused not authorized."

What am I potentially doing wrong?

getcert.sh

set -x
user_id=955b3b9241fa76f2559ece18247XXXXXXXXXXXXX

device_sn=T8200N00XXXXXXXX
email=aXXXXXXXXXXXXXXXXXXXX.cc
android_id=deadc0dedeadc0de

username=eufy_$user_id
password=$email
client=android_EufySecurity_${user_id}_${android_id}

mosquitto_sub
--cafile eufy.crt
-C 1 -F '%p' -N
-h security-mqtt.eufylife.com
-p 8789
-t "/phone/doorbell/$device_sn/push_message"
-u "$username" -P "$password" -i "$client"

@keshavdv
Copy link

It's possible that the wireless version of the doorbell relies on the FCM path like the floodlight rather than MQTT, in which case, I don't think would show any events. I can confirm the MQTT integration did work for me with a wired doorbell so it's still probably worthwhile to integrate for at least that set of users to be able to get realtime motion events for HA.

@PrayerfulDrop
Copy link

@keshavdv i have the wired doorbell and cannot connect to the Mqtt service. Can you provide guidance?

@joepadmiraal
Copy link

@joepadmiraal @nonsleepr
With the above script, are you doing this to acquire a new eufy.crt that is associated to your eufy doorbell?

I deleted the certificate and ran make in the repository directory to create a new certificate.
I don't know if that is actually needed.

If I copy the file eufy.crt from the src folder to my getcert.sh location then I get "connection refused not authorized."

What am I potentially doing wrong?

I rechecked it today and I am now also getting errors again when using the eu servers.
With the standard security-mqtt.eufylife.com server from the script it does not give a authorization error.

Now that I think of it, another reason for why I don't get any MQTT messages could also be because I have a European model instead of a US model.

@butabi
Copy link

butabi commented Jun 27, 2020

i can sub to "#" on security-mqtt-eu.eufylife.com - (i'm having a homebase with 4 eufycams 2 and 2c, no doorbell).

Like joe i'm not getting any messages either. Not sure what to expect actually :)

@multinet33
Copy link

multinet33 commented Jul 1, 2020

Hello all

Thank you for all the code you provide !
After installing dependencies I can run a python3.7 python-eufy-security-p2p/examples/test_api.py with error (some information hidded but ):
pi@domoticz:~/domoticz/scripts/personnels/python-eufy-security-p2p/examples $ python3.7 test_api.py
DEBUG:asyncio:Using selector: EpollSelector
INFO:eufy_security.api:Switching to another API_BASE: https://security-app-eu.eufylife.com/v1
INFO:root:------------------
INFO:root:Camera Name: Allée
INFO:root:Serial Number: T811
******************
INFO:root:Station Serial Number: T800****************
INFO:root:Last Camera Image URL: https://zhixin-security-eu.s3.eu-central-1.amazonaws.com/thumb/2020/07/01/station/T8002H********************************
INFO:root:Enabling OSD
Traceback (most recent call last):
File "test_api.py", line 62, in
asyncio.get_event_loop().run_until_complete(main())
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "test_api.py", line 36, in main
await camera.enable_osd(True)
AttributeError: 'Camera' object has no attribute 'enable_osd'

But most important for my : this problem

when I try to run a python3.7 python-eufy-security-p2p/examples/test_p2p.py I got an error :
pi@domoticz:~/domoticz/scripts/personnels/python-eufy-security-p2p/examples $ python3.7 ./test_p2p.py
Traceback (most recent call last):
File "./test_p2p.py", line 8, in
from eufy_security.types import GuardMode

Do you know how I can fix that problem ?
Thanks to @joepadmiraal @nonsleepr if they can have a look at my post ;)

For sure i've done previously a pip3 install python_eufy_security with succes:
pi@domoticz:~/domoticz/scripts/personnels/python-eufy-security-p2p/examples $ pip3 install python-eufy-security
Requirement already satisfied: python-eufy-security in /home/pi/.local/lib/python3.7/site-packages (0.3.1)
Requirement already satisfied: aiohttp==3.6.1 in /home/pi/.local/lib/python3.7/site-packages (from python-eufy-security) (3.6.1)
Requirement already satisfied: chardet<4.0,>=2.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp==3.6.1->python-eufy-security) (3.0.4)
Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp==3.6.1->python-eufy-security) (19.3.0)
Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp==3.6.1->python-eufy-security) (1.4.2)
Requirement already satisfied: multidict<5.0,>=4.5 in /usr/local/lib/python3.7/dist-packages (from aiohttp==3.6.1->python-eufy-security) (4.7.6)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /usr/local/lib/python3.7/dist-packages (from aiohttp==3.6.1->python-eufy-security) (3.0.1)
Requirement already satisfied: idna>=2.0 in /usr/local/lib/python3.7/dist-packages (from yarl<2.0,>=1.0->aiohttp==3.6.1->python-eufy-security) (2.10)

@ping-localhost
Copy link

Are there any updates related to this? MQTT for the doorbell would be amazing!

@nonsleepr
Copy link
Contributor Author

IIUC MQTT only works with wired doorbell (T8200).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants