Hi.
I’ve been playing around with Home Assistant for a month or so and having a lot of success but I’ve never been able to get the Arlo module to work satisfactorily - images wouldn’t appear, video streams wouldn’t work, my base stations spent a lot of time in the Unknown
state, things taking too long messages…
Looking at the traces from Home Assistant any number of threads could be using pyarlo
but looking at the pyarlo
module it doesn’t look thread safe and it seems this can cause several potential issues:
- pyarlo can’t handle more than one base station simultaneously. Looking at the Arlo website traces the base stations should share an event stream but the code opens one stream per base station - opening a second one closes the first.
- In
publish_and_get_event
the thread opening the event stream might close it before another thread, arriving at the function later, has finished using it. It should be reference counted. - In
publish_and_get_event
the loop reading packets should wait up to 10 seconds for a response to arrive but if 2 non response packets arrive - any number of unrelated packets can arrive on an event stream - the loop will exit almost immediately. This can happen with multiple or single threads. - It can’t handle library videos from a deleted camera.
I started off trying to fix these issues but realised a better solution would be to make the whole module event driven. That allows it to react to changes in the background and means the functions Home Assistant uses never have to wait for network activity. I spent some time this weekend trying to get a drop in replacement and the new version:
- does as little as possible on the start up thread
- subscribes to all base stations at start up and opens a single event stream in a background thread
- monitors event from Arlo and will update thumbnail images, video libraries, signal strength battery levels… in the back ground
- has preliminary support for doorbells
- will pickle some state across reboots
The experimental module is here: https://drive.google.com/file/d/1IjvJoSD2dCvep9k9zRqsabZdG6zOvGw1/view?usp=sharing
I use a docker to host Home Assistant and the following instruction will install the experimental package for me:
# copy py-0.3.tgz into your home assistant config directory
# assuming your instance is called home-assistant
$ docker exec -it home-assistant bash
root@skippy:/usr/src/app# cd /config/
root@skippy:/config# pip uninstall pyarlo
root@skippy:/config# pip uninstall sseclient-py
root@skippy:/config# pip install py-0.3.tgz
root@skippy:/config# exit
Then stop and restart the container:
$ docker stop home-assistant
$ docker start home-assistant
The new module is pretty chatty and you should see regular updates in the log files. It will also dump packets into /config/packets.dump
so you can see what Arlo is sending you.
If it all breaks you can revert to your the original version of pyarlo with:
$ docker exec -it home-assistant bash
root@skippy:/config# pip uninstall pyarlo
root@skippy:/config# pip install pyarlo
root@skippy:/config# exit
$ docker stop home-assistant
$ docker start home-assistant
It’s very alpha, it’s working for me but please back up your data before trying or just bring up a new Home Assistant instance. My immediate plan is to tidy the code up - I can see the tracker.py file disappearing, fill in the missing interfaces and to add motion and audio detection support with callbacks. The problem I have right now is it’s so cold here (-25C) that all my cameras have shut down.
This is only my second time posting here so I apologise if I broke any site rules. Also, it wasn’t my intent to step on any toes, I just had some spare time last week and wanted to figure out the Arlo issues I was seeing.
Thanks,
Steve