a small update: I didn’t have as much time as I wanted, but I made some progress:
All required API-calls are now possible, including the calls to the AWS API. Haven’t started with the websocket/MQTT stuff yet.
It is now possible to extract your full setup, including the status of the devices. Will commit the latest changes as soon as I finished it.
I’ve also started to create a simple home-assistant component, but I’ve got a lot to learn. First thing I noticed was that it is much easier to have an async client. So I’ve started porting the code to async.
I’ve tried to use external libraries, but couldn’t find one that is async, does what we need and is maintained. For now I’ve written a small class that can sign the requests. The login-function still uses some external libraries that are synchronous. For now I leave it as is and call it in an executor.
A small example of my current output (the names are Dutch):
great job. Just got my Xsense package with base station today and i’m really looking forward to bring them into HA. Would make them a lot smarter and maybe one day you can also trigger the different sirenes with other entities.
Don’t expect too much yet, I still have a lot to learn in making integrations, had a lack of time lately and so far it has been a bumpy ride.
This requirement is still missing from the manifest. This is also in an very early stage:
git+https://github.com/theosnel/python-xsense.git@develop#xsense
Just pushed an update. It’s slowly starting to look like a real integration, but I’m still struggling with it.
I added a coordinator to fetch the data centrally as well as some entities. It now supports battery, temperature, humidity and CO.
I’m not totally sure if the updating is working correctly yet. It doesn’t always seem to update.
Last week, I ordered 2 STH51 temperature sensors, which will make testing a lot easier. That sensor works quite well in home assistant now.
I now need to add the remaining entities and still have some stuff to fix with authentication. Right now, it can’t refresh an access token, so after a day, the session is no longer valid.
I’ve got the dumbest of questions: How do I install it?
I got your latest update (1 hr ago) and put into custom_components, then tried to call
xsense:
in the configuration.yaml
It stated it needed a version in the manifest so I added one, still didn’t work
Should I be adding this through HACS or something?
I don’t know if it is already possible to install it as a custom component. I’m using a separate development environment to build it and haven’t tested it yet in my normal installation.
The component needs the python-xsense library, but I haven’t made a release yet, which makes it difficult to add to the manifest.
To get it running you would at least need to install that package somehow.
pip install git+https://github.com/theosnel/python-xsense.git@develop#xsense works for me.
The component uses the config-flow, so I don’t think it is needed to configure it via the configuration.yaml. It should be possible to add the integration via the gui.
Finally, I would suggest to create a dedicated account for it and invite it to your normal account. It seems that you cannot login more than once simultaneously.
Thanks @theosnel for your work !
i don’t understand how to integrate your script on my HA.
i have paste the python’s script in my folder, i tryed to call this script with a service but not working (dictonary not found)
It is still in development, so I’m not sure if you can use it already. Like I said earlier, I use this on a development environment.
The goal is to make the integration good enough so that it can be included in Home Assistant.
I made some progress, just pushed some changes to the library. It is now able to auto-refresh tokens that are about to expire.
The base-station is now visible as well in home assistant and I added several sensor-entities. I still have to doublecheck it, but I will push it soon.
I’m still not sure if it keeps refreshing the data. Sometimes it seems to freeze until I open the mobile app. I might have missed an api-call.
(this post is primarily from the temperature dongle experience, I do not have other devices besides the base station)
That’s what I’ve noticed too. The temperature updates at the API much more readily when the app is open and refreshed (pulling down for a refresh). After a few minutes, it stops updating and seems stuck. This might be a form of throttling, or maybe the app does something that is not obvious
EDIT: wild guess, but could this be some sort of a battery preservation strategy? I remember Amazon reviews mentioning how long XSense devices last on a single set of batteries. Maybe the devices do not communicate with the base station unless they absolutely have to (alarm or user inquiry), and merely log the temperature
quite sure it is how you say. Guess the same is for smoke sensors. They only communicate with basestation if they have alarm, low battery, or the base station wakes them. Otherwise, battery would be drained too much.
I’ve a few ideas to debug it. With mitmproxy I can see all communication from the app. One of the api-calls must be the trigger to refresh the data. Although I’ve tried to copy everything, something must be missing. I can resend all calls to the server and monitor when data is updated. There’s currently one api-call that I could not figure out yet. In the android APK package that id (408201) cannot be found. For testing I use IOS, that call might be IOS specific, but I doubt that.
If that doesn’t work I could try to sniff the traffic to the base station as well. I expect that the base-station will get a message when it needs to update.
The battery usage might be an issue if the devices only send data on demand or in case of an alarm. Home assistant will poll all day long, which might drain the batteries. Maybe it is possible to monitor the 868Mhz frequency for activity, to determine when data is send.
I first want to focus on the other things, like releasing the little library to pypi and finalizing the first version of the integration.