[Custom Component] tedee Doorlock

@joerg65 are you sure?
I am rather sure that only lock is added, as we look for “id” in https://api.tedee.com/api/v1.15/my/lock and this “id” only returns lock. Bridge is using “bridgeId”

EDIT: I’m using this modified version of pytedee on my HA and I don’t see bridge added to list of locks … so I think that it’s fine.

EDIT2: I think that U used wrong API - https://api.tedee.com/api/v1.15/my/device
With “devices” API you have 2 x ID’s - and here you would receive 2 locks - lock and bridge
Try using “lock” as per my example above

I see, you have used my/lock. I missed that. Then your suggestion is correct. :wink:
I will update the github code, once I am ready with restoration of my host pc.

I created pull request to your repository - so check if changes are fine for you and commit or drop.

@Nimloth + @joerg65

  1. I am preparing test lock for you it should be in next week available
  2. We now focus to improve the documentation, you should see big update in next week and it will include such info lite DeviceType, LockState and more
1 Like

I have pushed small PR which add using lock properties in get_devices method. I can still see some mistakes in current implementation:

  • the get_state method should update lock is_connected and is_charging properties
  • in open method you assume it will take only 5 seconds but this can take longer depends of user configuration
  • in open/lock/unlock commands you set the state the end state just after calling endpoint but this doesnt must be true. at the end the operation may failure or the lock may jam. it would be better to use in progress state like (4 - unlocking, 5 -locking, 8 - pulling)
  • i do not know how the home assistant works but is there any logic to refresh the devices state periodically?

@Konrad-Tedee, I appreciate your help and thank you very much.
First, the update intervall is 30s as default. A user can change it.
The reason I set the state in form of optimistic is because I haven’t had the right enumeration of state. I saw a difference to what you sent me by email. But with the right information the python module can be corrected. The best would be that the module can receive notifications, then the state is always right and not assumed and must not be requested. In your documentation i saw that the requests for state should not be more than 1 per 10s. So how long must we wait until the lock is in position or failed, to make a request for it’s state? But waiting to long makes a bad user experience as everybody knows with touch devices when they do not react.
Further, homeassistant lock integration knows only Locked and Unlocked. There are no states in between. We can send the real state only as additional argument to homeassistant to show it somewhere, i.e. in a custom button card.
For the time of pull spring I can add a parameter, so the user can change it in homeassistant configuration.
Then, I will need some time to check your pull request.

@Nimloth, I appreciate your help also. Your pull request I have accepted already.

I have pushed the version of pytedee to 0.0.2, because I added a request to duration of pullspring and updated the custom component. The custom component stays compatible to 0.0.1, but to see some additional state attributes, pytedee needs to be updated.
Additional state attributes:

A custom Button-Card with battery icon and different state strings as Locked, Locking, Unlocked, Unlocking, Pulling…

A single tap toggles between lock and unlock, a double tap is to open pullspring (only works when lock is unlocked).
The example code for it:

entity: lock.lock_326b
type: 'custom:button-card'
card_size: 0.5
name: >
  [[[
    if (entity.attributes.numeric_state == 2)
      return "Unlocked"
    if (entity.attributes.numeric_state == 6)
      return "Locked"
    if (entity.attributes.numeric_state == 3)
      return "Half open"
    if (entity.attributes.numeric_state == 5)
      return "Locking"
    if (entity.attributes.numeric_state == 4)
      return "Unlocking"
    if (entity.attributes.numeric_state == 7)
      return "Pulling"
    return "undefined"
  ]]]
state:
  - value: locked
    color: green
    icon: 'mdi:lock'
  - value: unlocked
    color: orange
    icon: 'mdi:lock-open'
styles:
  card:
    - height: 140px
    - width: 250px
  custom_fields:
    bat:
      - position: absolute
      - left: 70%
      - top: 10%
      - height: 20px
      - width: 60px
      - font-size: 12px
      - line-height: 20px
custom_fields:
  bat: >
    [[[
      if (entity.attributes.battery_level > 60)
        return `<ha-icon
          icon="mdi:battery"
          style="width: 24px; height: 24px; color: green;">
          </ha-icon><span>${entity.attributes.battery_level}%</span>`;
      if (entity.attributes.battery_level >= 30)
        return `<ha-icon
          icon="mdi:battery-50"
          style="width: 24px; height: 24px; color: orange;">
          </ha-icon><span>${entity.attributes.battery_level}%</span>`;
      if (entity.attributes.battery_level < 30)
        return `<ha-icon
          icon="mdi:battery-30"
          style="width: 24px; height: 24px; color: red;">
          </ha-icon><span>${entity.attributes.battery_level}%</span>`;
    ]]]
tap_action:
  action: toggle
double_tap_action:
  action: call-service
  service: lock.open
  service_data:
    entity_id: lock.lock_326b

1 Like

I don’t see a new code in custom component for HA.

Oh, sorry. I have forgotten to upload to github. Now it’s there. :slightly_smiling_face:

Thanks, looks nice.
I don’t see reson to keep compability with previous versions … as it’s not yet published to https://pypi.org/ … so no need to complicate code.

When U will publish python base to pypi?

I will look into this over Christmas days, when I have more free time.

@Konrad-Tedee, I can see the lock you installed for testing:


So it seems that this is working, if a user have more than one lock.

1 Like

Looks like Azure B2C Login Page is down for Tedee:

{"CorrelationId":"a5959402-a030-4d4b-80f2-cf1fcffa3d8e","Timestamp":"2020-12-17 20:29:52Z","Detail":"AADB2C: An exception has occurred."}

Only me or U have same?

That is the reason why I like local API so much :slight_smile:

Here too. Lock locked not at 21:30 from the automation.
If I start HA:

2020-12-17 21:39:35 ERROR (MainThread) [homeassistant.components.lock] Error while setting up tedee platform for lock
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 199, in _async_setup_platform
    await asyncio.shield(task)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tedee_lock/lock.py", line 38, in setup_platform
    tedee = TedeeClient(config[CONF_USERNAME], config[CONF_PASSWORD])
  File "/usr/local/lib/python3.8/site-packages/pytedee/TedeeClient.py", line 42, in __init__
    self.get_devices()
  File "/usr/local/lib/python3.8/site-packages/pytedee/TedeeClient.py", line 73, in get_devices
    result = r.json()["result"]
KeyError: 'result'

Edit: Also logged off in the iPhone tedee app.
Edit2: Cloud API is back online

Yes, it was the same here. In the afternoon I was not able to connect with the bridge in HA, also not by Tedee app, but the lock was connected to the app.
I am worried about this can happen always, that servers are down. I would like that we don’t need an external server.
Tedee support: Please think of this. Give the users the chance to decide how they use the lock, security served by you, or in own responsibility by the user.

If you had token (which is valid if I remember correctly for 3 hrs) … then it was mostly working for you, until token expired.
Portal that generate token was down, so any new requests couldn’t be completed :frowning:

@Konrad-Tedee local API is must :slight_smile:

Yesterday our cloud provider Microsoft Azure had an issue. After 30 minutes we it was solved but we still analyzing it.
Even if cloud in unavailable user still can connect to devices using mobile app over Bluetooth, the switch is done automatically by the app. The cloud services can go down like google few days ago. The question is how many of you decided to build own SMTP server? The could give us and you match more versus local solutions.

We apologyse for any inconvenience.

@Konrad-Tedee Thanks for the Feedback. Not big deal for the short outage.

About SMTP:
The setup of a local SMTP is not needed to deliver E-Mails. You could use the existing one from your personal E-Mail provider like Gmail, Web.de, etc. They all provide SMTP services which I use in several local services.