[Custom Component] tedee Doorlock

I have created a new custom component for the Doorlock from Tedee.
The custom components of Nuki and Kiwi.ki gave me inspiration and I learned from that code as I am not a experienced Python programmer. This project is in early state.
The component can access the Doorlock only, if there is also a Tedee Bridge installed and paired with the doorlock.
You can find the code on my github repository: https://github.com/joerg65/tedee_lock
and the Python module here: https://github.com/joerg65/pytedee

lock:
  - platform: tedee
    username: username
    password: password

How it looks with two button-cards:

2 Likes

Nice … was looking for it as just installed Tedee lock :slight_smile:

Blockquote
2020-11-13 12:02:51 ERROR (SyncWorker_52) [homeassistant.util.package] Unable to install package pytedee==0.0.1: ERROR: Could not find a version that satisfies the requirement pytedee==0.0.1 (from versions: none)
ERROR: No matching distribution found for pytedee==0.0.1

How to solve it ? I installed manually GitHub - joerg65/pytedee on HA server

Hello Nimloth, nice that you are the first test user!
How did you installed the package? I have no well knowledge with HA server. My HA is installed in a venv environment. As I had some trouble to install the package now on my Odroid C2, I used the method to install with pip directly from github as this:

pip3 install git+https://github.com/joerg65/pytedee.git

But before I activated the venv.
This worked for me. But on my C2 I have another error now I have to solve. I have tested the package only on my development machine I set up specially for this.

On my Odroid C2 was missing module ‘requests’:

pip3 install requests

I solved it. As I’m running HA in docker, I had to start bash shell in container and install from there.

Works like a charm :wink:

Missing things:

  • when you open lock, you can also pull spring:
    /api/v1.15/my/lock/pull-spring
  • python component registered in ‘store’ so can be auto installed when needed
  • add it to HACS of official HA integration :wink:

Fine that it works now!
Pull spring is already there. You can define a button or use it in automation: lock.open.
But the lock only takes this command in state Unlock.
For make the component registered and as integration in HACS I have to learn a bit more.
But before I would like to add the push notification functionality into the python module. I am in conversation with tedee support. Hopefully they put an example for it or extend the api documentation with additional information.
The advantage would be that the lock sends push notification also when it is used by hand or with the app. To have the state immediately in HA.
I have tried a lot, I can only register for notification, but not establish a permanent connection.

Yes, open works … already tried it yesteday (checked your python code) :slight_smile:

tedee

Let me know if you need something to test.

EDIT: Also check your code … some spelling errors can be found like:

Blockquote
def lock(self, **kwargs):
“”“Unlock the door.”“”

EDIT2: yea, notification are not synchronized … we can end in state when doors as locked but in HA we see options to lock them and vice-versa. Let us know if support will give some feedback

Yeah, thank you. I corrected the spelling errors (I found two). I changed also the logging behavior of the pytedee module to level warning. So there should not be so much logging messages any more.
If someone need to enable logging, in TedeeClient.py can be changed:

logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("pytedee").setLevel(logging.WARNING)

The urllib3 per default shows the whole requests with readable password.

Logging was messed up. Before how you set debug messages had impact on other components also.
Now HACS or direct HA Intergration :slight_smile:

1 Like

Hi @joerg65 I am here from Tedee team, thank you for implementing integration for Tedee.

The Notification are prepared for mobile and use Firebase (Android) and Apple notifications platform. So you must first register to one of these platforms and then use the endpoint

/api/v1.15/standardnotificationhub/register

as a parameters please use following:

  • isSandbox = false
  • platform = (1 - apple, 2 - firebase)
  • handle = the string you recived from registration to apple/firabes
  • registrationId = the Id of your last call of this enprint if it is your first then empty
1 Like

@Konrad-Tedee, Thank you very much. I will try it next days.

I tried to get notifications, but I am missing something…
I use Python module firebase_admin from Google, as other projects seem to outdated.
I have created a firebase project and I can get a token:

from firebase_admin import credentials
from firebase_admin import messaging
import firebase_admin

cred = credentials.Certificate("/path/to/pytedee-firebase-adminsdk.json")
access_token_info = cred.get_access_token()

With this token I can register at api.tedee.com and I get a registration_id:

handle = access_token_info.access_token
id = ""
notification_payload = {
  "isSandbox": False,
  "platform": 2,
  "handle": handle,
  "registrationId": id
}
r = requests.put(api_url_notification, headers=api_header, data=json.dumps(notification_payload), timeout=5)

But from here I am lost.
Whereto does tedee send the notification?
Is it Cloud Messaging?
If yes, then I have to subscribe to a topic. What would be the topic name? Do I need to create this topic in the firebase cloud messaging, so that tedee notification is accepted?

So far I don’t see a solution. In firebase-admin sdk there is no way to receive notifications, only to send. So I am in doubt that it can be realized in Python. There are existing client SDKs for web in JavaScript, for Android, for IOS, even in C++.
I will see if I can make an example C++ client.

Hi,

thanks for your custom component. After setup the following mesage appears in HA log:
[custom_components.tedee_lock.lock] No lock found

Any idea? Thx

Edit: found it. I renamed my lock in the tedee app. And you look in pytedee for “Lock” in the name. Maybe you could make it configurable in the custom_component.

I see, let me think about best solution.

The tedee API (/api/v1.15/my/device/details) can list device by its type “bridges” and “locks”.
Maybe you could filter only for type “locks” and fetch all IDs from this type. Then the name is irrelevant.

@Konrad-Tedee any advice for registration?

  1. You are interested in only locks so it is better to use this endpoint
/api/v1.15/my/lock

and you will not have to filter.

You should change this part:

        for x in result:
            id = x["id"]
            name = x["name"]
            if "Lock" in name:
                self._lock_id = id
                '''store the found lock in _sensor_list and get the battery_level'''
                self._sensor_list.append(Lock(name, id))
                self.get_battery(id)

Do not use device names to identify locks. And remember that user may have more than one lock.

  1. Notifications

Instead of implementing notifications you can check this https://tedee-tedee-api-doc.readthedocs-hosted.com/en/latest/howtos/get-and-sync-locks.html#refresh-locks-statuses

If you want implement the push notifications I will contact the mobile team and confirm is it doable.

Thank you, Konrad. When I have time, I will look to solve this.

For more than one lock fix is rather easy:

    def get_devices(self):
        '''Get the list of registered locks'''
        api_url_lock = "https://api.tedee.com/api/v1.15/my/lock"
        r = requests.get(api_url_lock, headers=self._api_header,
            timeout=self._timeout)
        _LOGGER.debug("Locks %s", r.json())
        result = r.json()["result"]
        for x in result:
            id = x["id"]
            name = x["name"]
            self._lock_id = id
            '''store the found lock in _sensor_list and get the battery_level'''
            self._sensor_list.append(Lock(name, id))
            self.get_battery(id)
        if self._lock_id == None:
            raise TedeeClientException("No lock found")

@Konrad-Tedee
as we mostly have only 1 lock - do you have some TEST one which can be assigned to access remotelly to test it ?

For notifications - it’s already like you wrote - sync is done but not instantly.
If you unlock lock in Tedee application - status in HA will be updated after a while.

@Nimloth, I appreciate any help. :slightly_smiling_face:
With your suggestion it would append also the bridge to the list of locks:

id:  3342 , name:  Lock-326B
id:  3523 , name:  BRIDGE-D4A8

I tried to filter for ‘type == 2’, then only locks are appended:

        result = r.json()["result"]
        for x in result:
            id = x["id"]
            name = x["name"]
            type = x["type"]
            if type == 2:
                print("id: ", id, ", name: " , name)
                self._lock_id = id
                '''store the found lock in _sensor_list and get the battery_level'''
                self._sensor_list.append(Lock(name, id))
                self.get_battery(id)
        if self._lock_id == None:
            raise TedeeClientException("No lock found")

But
@Konrad-Tedee, the API is missing essential information:

Also for state of lock, this information is missing.