CASAMBI BLE Light Support

Hi, from working with the Casambi consoles I can confirm that it is enough to have a network session. Controlling the lights via the console works after having the session id.

Regarding the HA integration: First of all thanks to @hellqvio for your work :slight_smile: I have Hass.iO running. Therefore i created two new folders under …/config/custom_components: one folder “aiocasambi” where I stored the files out of the “src” subfolder from here: GitHub - hellqvio86/aiocasambi: aio library for Casambi lights. The second folder is “casambi” where I stored the files from here: GitHub - hellqvio86/home_assistant_casambi: Home assistant Integration for Casambi Cloud lights.

To the configuration.yaml I added:

# Light
light:
  # Casambi
  - platform: casambi
    email: !secret casambi_email
    api_key: !secret casambi_api_key
    network_password: !secret casambi_network_password # The network password
    user_password: !secret casambi_user_password # The site password for your user

After a HA restart I am receiving the following error entry in the home-assistant.log file:

2020-06-12 12:46:18 ERROR (MainThread) [custom_components.casambi.light] Error connecting to the Casambi
Traceback (most recent call last):
File “/config/custom_components/casambi/light.py”, line 97, in async_setup_platform
await controller.create_user_session()
File “/usr/local/lib/python3.7/site-packages/aiocasambi/controller.py”, line 80, in create_user_session
data = await self.request(“post”, url=url, json=auth, headers=headers)
File “/usr/local/lib/python3.7/site-packages/aiocasambi/controller.py”, line 215, in request
**kwargs,
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 1012, in aenter
self._resp = await self._coro
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 483, in _request
timeout=real_timeout
File “/usr/local/lib/python3.7/site-packages/aiohttp/connector.py”, line 523, in connect
proto = await self._create_connection(req, traces, timeout)
File “/usr/local/lib/python3.7/site-packages/aiohttp/connector.py”, line 859, in _create_connection
req, traces, timeout)
File “/usr/local/lib/python3.7/site-packages/aiohttp/connector.py”, line 986, in _create_direct_connection
req=req, client_error=client_error)
File “/usr/local/lib/python3.7/site-packages/aiohttp/connector.py”, line 936, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File “/usr/local/lib/python3.7/asyncio/base_events.py”, line 989, in create_connection
ssl_handshake_timeout=ssl_handshake_timeout)
File “/usr/local/lib/python3.7/asyncio/base_events.py”, line 1017, in _create_connection_transport
await waiter
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/config/custom_components/casambi/light.py”, line 99, in async_setup_platform
await controller.start_websocket()
File “/usr/local/lib/python3.7/site-packages/async_timeout/init.py”, line 45, in exit
self._do_exit(exc_type)
File “/usr/local/lib/python3.7/site-packages/async_timeout/init.py”, line 92, in _do_exit
raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError

Seems to be a timeout issue. Several restarts did not show any difference. Any idea from this protocol? Since I cannot use pip with Hass.iO I made the manual copy&paste as described earlier. Maybe that doesn’t work?

That’s strange, do you see the traffic going out to door.casambi.com ?

Sorry all for all the updates to the libraries, I am trying to gray out all the casambi lights when the gateway is offline, which is a problem in my setup.

I might have found Johan76 issue, they have different json structures for unit updates (light update), should be fixed now :slight_smile:

No, I cannot see any traffic. I managed to activate aiocasambi debug logging. The only two entries that I get before the earlier mentioned error throws are these:

2020-06-12 21:50:41 DEBUG (MainThread) [aiocasambi.controller] headers: {‘Content-type’: ‘application/json’, ‘X-Casambi-Key’: ‘’} auth: {‘email’: ‘’, ‘password’: ‘<password-removed’}
2020-06-12 21:50:41 DEBUG (MainThread) [aiocasambi.controller] url: https://door.casambi.com/v1/users/session

I removed the api key, email and password.
What do you think about the place where and how I put the aiocasambi files into the files structures. Should that be allright? Here is a screenshot of the file system:

@hellqvio I got a virtual Raspberry Pi running in VMware today. That gives me the opportunity to use pip which Hass.iO doesn’t. I installed your lib a component. I got it running. After that I ran into the same ‘details’ error that @Johan76 already mentioned. I checked your code and found your fix. But you are trying to read ‘details’ multiple times.
I added the fixes to the remaining locations in the code and created a fork in GitHub:
Update units.py by sMauldaeschle · Pull Request #3 · hellqvio86/aiocasambi · GitHub
Feel free to release it as new version. Minutes ago I was able to switch my Occhio Sento (using Casambi) on and off via the virtual Home Assistant. Happy for the night :slight_smile:

Btw: My Hass.iO. problem moved a bit but has not gone away… I manually changed the manifest.json to required aiocasambi version 0.137. I now can see an established connection. I get a user_session_id. But then comes a quite similar error:

2020-06-14 21:37:30 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.hue
2020-06-14 21:37:32 ERROR (MainThread) [custom_components.casambi.light] Error connecting to the Casambi
Traceback (most recent call last):
File “/config/custom_components/casambi/light.py”, line 98, in async_setup_platform
await controller.create_network_session()
File “/usr/local/lib/python3.7/site-packages/aiocasambi/controller.py”, line 103, in create_network_session
data = await self.request(“post”, url=url, json=auth, headers=headers)
File “/usr/local/lib/python3.7/site-packages/aiocasambi/controller.py”, line 211, in request
**kwargs,
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 1012, in aenter
self._resp = await self._coro
File “/usr/local/lib/python3.7/site-packages/aiohttp/client.py”, line 504, in _request
await resp.start(conn)
File “/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py”, line 847, in start
message, payload = await self._protocol.read() # type: ignore # noqa
File “/usr/local/lib/python3.7/site-packages/aiohttp/streams.py”, line 591, in read
await self._waiter
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/config/custom_components/casambi/light.py”, line 99, in async_setup_platform
await controller.start_websocket()
File “/usr/local/lib/python3.7/site-packages/async_timeout/init.py”, line 45, in exit
self._do_exit(exc_type)
File “/usr/local/lib/python3.7/site-packages/async_timeout/init.py”, line 92, in _do_exit
raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError

Still having some issues. details error again.
Not sure how to update but I removed casambi in custom_components and made the git clone again :slight_smile:
Restarted server.

I can get you some logs if that will help but I thought maybe @sMauldaeschle patch will work for me as well? Not sure if I can get that without you merging first.

1 Like

The patch is merged now and a new version is released, thanks for the help! :slight_smile:

Its easiest to just do a git pull from the casambi directory to update it :slight_smile:

I have not seen the timeout error my self, hopefully I see it soon :confused:

1 Like

I checked my log file and had another error in there from system monitor. I deactivated system monitor and suddenly the casambi integration worked. YEAH!
Nevertheless I just saw the timeout error again a few minutes ago after several restarts. I think I will observe this for a while…

Hej Johan =) Nice to see you here too <3

Yes of course. :slight_smile:
Dont have much time now so I havnt really been doing much more testing as of yet.

When I had a meeting with Casambi a while back and they informed me more about the API possibility I just had to see if anyone made some integration. And the work is started :slight_smile:
My knowledge (and time to learn) programming is unfortunately very limited so I have to rely on other guys for this :slight_smile:

Really cool now. DALI gateway so you can integrate Casambi completely with KNX/DALI system and the API to control from other systems.

I see a bright future!

Just updated and restarted (Have been busy lately). Now it seems to work :slight_smile:
Good work!

1 Like

The addon can now be installed with HACS.

2 Likes

Perfect! Got everything working and can now control my Occhio lights using Homekit :smile:
Would be awesome if color temperature could be controlled as well, but this is already great

I currently only have LD220WCN controllers in my Casambi setup and can only control brightness, which is implemented.

But I am happy to accept PRs :slightly_smiling_face:

Cool! How can I help? What do you need? :slight_smile:
I’ve also registered an issue on GitHub as my lights are said to be offline after some hours of running the addon. Restarting HA resolves this for a short period.

All help is appreciated :slightly_smiling_face:

The problem you have is not seen in the provided log, the api reports that the light is offline and then something happens to the connection.

When you restart HA you setup a new connection to the API, thats why its working then.

The problem is that the error handling is not robust enough, I have not seen it for a while and I need to reproduce it so I have a more detailed idea of whats happening.

That is also my next focus in this project, the android app is the thing that often is the thing that breaks in my setup, but I cannot really control that, the thing I can do is to make the HA integration more robust, so it can handle outages etc.

Hi @hellqvio

I were just wondering if you made any progress on the integration between Casambi & Hass.io

I’ve a new system which relies on Casambi and I would like to perform some interaction with the system & HA

I purchased a BLE Gateway that support Casambi and it’s quite stable (relies on Android 6.0) - https://www.holderscomponents.com/ht_product_category/ble-gateway/

Thank you

Yes, some progress has been made, the addon supports reconnection and disabled devices now.

You have instruction on how to install it in the github repo, it’s a hacs addon current.

Interesting gateway, I will take a look.

Please open a github issue or pr if there is any issue :slightly_smiling_face:

1 Like

If you are running iOS might this be interesting https://github.com/awahlig/homebridge-casambi

I think that project is more feature complete and they probably have a bigger userbase, but I am not a Iphone user currently.

1 Like

Thank you

Me neither but basically the Gateway is only a small PC running on Android. You’ve to install all your need by yourself

Unfortunately the Bluetooth is not always fully reliable. Best thing is to have a BLE module very near the Gateway

Hi! Thank you very much for working on this integration.
I’m giving the plugin a try, but getting “Connected to Casambi but couldn’t log in”. I have double-checked my credentials, they work via the app, and the API-key works through the Casambi API web console.

For what it’s worth, I’ve installed the plugin via HACS.

I am, however, running Home Assistant via (formerly) Hassio, so I’m presuming the aiocasambi library isn’t installed anywhere, as pip isn’t in the picture. I tried copying it over manually under custom components, but I see that it has a dependency of its own.

Am I right in my current assumption that the plugin currently isn’t really supported without pip, or is there something I’m missing/a trick to getting it working in Hassio/Home Assistant?

Thank you very much!