Package: pyaarlo
PyaarloAlpha BuildWelcome to the Pyaarlo alpha build. I'm using the 0.8.x stream to splitpyaarloout fromhass-aarlo. This is partly motivated by thinking about
gettinghass-aarloback into Home Assistant and partly motivated by my
desire to stop having to commit bug fixes in 2 places.Breaking ChangesCached SessionThe code will now save the session details and reuse the authentication token
when possible. This can drastically reduce the number of authentication
requests the code will make (and 2FA requests if needed). If this doesn't work
for you passsave_session=Falseas a parameter toPyArlo().Table of ContentsIntroductionInstallationUsagePyaarlo ExecutableUser AgentSaving Media2 Factor AuthenticationManualIMAPError ReportingLimitationsOther 2 Factor AuthenticationIntroductionPyaarlo is a module for Python that provides asynchronous access to Netgear
Arlo cameras.When you start Pyaarlo, it starts a background thread that opens a single,
persistant connection, anevent stream, to the Arlo servers. As things happen
to the Arlo devices - motion detected, battery level changes, mode changes,
etc... - the Arlo servers post these events onto the event stream. The
background thread reads these events from the stream, updates Pyaarlo's internal
state and calls any user registered callbacks.Differences from PyarloThe biggest difference is Pyaarlo defaults to asynchronous mode by default. The
following code brought from Pyarlo might not work:base.mode='armed'ifbase.mode=='armed':print('it worked!')This is because between settingmodeand readingmodethe code has to:build and send a mode change packet to Arloread the mode change packet back from the Arlo event streamupdate its internal state forbaseI say "might" not work because it might work, it all depends on timing, and
context switches and network speed...To enable synchronous mode you need to specify it when starting PyArlo.# login, use console for 2FA if neededarlo=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_type='SMS',tfa_source='console',synchronous_mode=True)ThanksMany thanks to:PyarloandArlofor doing the original heavy
lifting and the free Python lesson!sseclientfor reading from the event
streamJetBrainsfor the excellentPyCharm IDEand providing me with an open source license to speed up the
project development.InstallationProper PIP support is coming but for now, this will install the latest version.pipinstallgit+https://github.com/twrecked/pyaarloUsageYou can read the developer documentation here:https://pyaarlo.readthedocs.io/The following example will login to your Arlo system, use 2FA if needed,
register callbacks for all events on all base stations and cameras and then wait
10 minutes printing out any events that arrive during that time.# code to trap when attributes changedefattribute_changed(device,attr,value):print('attribute_changed',time.strftime("%H:%M:%S"),device.name+':'+attr+':'+str(value)[:80])# login, use console for 2FA if neededarlo=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_type='SMS',tfa_source='console')# get base stations, list their statuses, register state change callbacksforbaseinarlo.base_stations:print("base: name={},device_id={},state={}".format(base.name,base.device_id,base.state))base.add_attr_callback('*',attribute_changed)# get cameras, list their statuses, register state change callbacks# * is any callback, you can use motionDetected just to get motion eventsforcamerainarlo.cameras:print("camera: name={},device_id={},state={}".format(camera.name,camera.device_id,camera.state))camera.add_attr_callback('*',attribute_changed)# disarm then arm the first base stationbase=arlo.base_stations[0]base.mode='disarmed'time.sleep(5)base.mode='armed'# wait 10 minutes, try moving in front of a camera to see motionDetected eventstime.sleep(600)As mentioned, it uses thePyarloAPI where possible so the following code from the originalUsagewill still work:# login, use console for 2FA if needed, turn on synchronous_mode for maximum compatibilityarlo=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_type='SMS',tfa_source='console',synchronous_mode=True)# listing devicesarlo.devices# listing base stationsarlo.base_stations# get base station handle# assuming only 1 base station is availablebase=arlo.base_stations[0]# get the current base station modebase.mode# 'disarmed'# listing Arlo modesbase.available_modes# ['armed', 'disarmed', 'schedule', 'custom']# Updating the base station modebase.mode='custom'# listing all camerasarlo.cameras# showing camera preferencescam=arlo.cameras[0]# check if camera is connected to base stationcam.is_camera_connected# True# printing camera attributescam.serial_numbercam.model_idcam.unseen_videos# get brightness value of cameracam.brightnessUser AgentTheuser_agentoption will control what kind of stream Arlo sends to you.
The options are:arlo; the original user agent, returns anrtspsstream.ipad; returns aHLSstreammac; returns aHLSstreamlinux; returns aMPEG-DASHstreamSaving MediaIf you use thesave_media_toparameter to specify a file naming schemepraarlowill use that to save all media - videos and snapshots - locally. You
can use the following substitutions:SN; the device serial numberN; the device nameY; the year of the recording, include centurym; the month of the year as a number (range 01 to 12)d; the day of the month as a number (range 01 to 31)H; the hour of the day (range 00 to 23)M; the minute of the hour (range 00 to 59)S; the seconds of the minute (range 00 to 59)F; a short cut forY-m-dT; a short cut forH:M:St; a short cut forH-M-Ss; the number of seconds since the epochYou specify the substitution by prefixing it with a$in the format string.
You can optionally use curly brackets to remove any ambiguity. For example,
the following configuration will save all media under/config/mediaorganised by serial number then date. The code will add the correct file
extension.save_media_to:"/config/media/${SN}/${Y}/${m}/${d}/${T}"The first time you configuresave_media_tothe system can take several
minutes to download all the currently available media. The download is
throttled to not overload Home Assistant or Arlo. Once the initial download is
completed updates should happen a lot faster.The code doesn't provide any management of the downloads, it will keep
downloading them until your device is full. It also doesn't provide a NAS
interface, you need to mount the NAS device and pointsave_media_toat it.2FAPyaarlo supports 2 factor authentication.ManualStartPyArlospecifyingtfa_sourceasconsole. WheneverPyArloneeds a
secondary code it will prompt you for it.ar=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_source='console',tfa_type='SMS')IMAPI recommend usingIMAP, it's well tested now and it works. The other
methods haven't been tested or looked at in a while.Automatic is trickier. Support is there but needs testing. For automatic 2FA
PyArlo needs to access and your email account form where it reads the token Arlo
sent.ar=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_source='imap',tfa_type='email',tfa_host='imap.host.com',tfa_username='your-user-name',tfa_password='your-imap-password')If you have multiple e-mail addresses associated with Arlo, you might also try configuringtfa_nicknameto ensure that the correct factor is triggered:ar=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_source='imap',tfa_type='email',tfa_host='imap.host.com',tfa_username='your-user-name',tfa_password='your-imap-password',tfa_nickname='your-user-name@your-domain.com')It's working well with my gmail account, seeherefor help setting up
single app passwords. If needed, you can specify a port by appending it to the
host.ar=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_source='imap',tfa_type='email',tfa_host='imap.host.com:1234',tfa_username='your-user-name',tfa_password='your-imap-password')Pyaarlo ExecutableThe pip installation adds an executablepyaarlo. You can use this to list
devices, perform certain simple actions and anonymize and encrypt logs for
debugging purposes.Device operations are currently limited...The git installation hasbin/pyaarlowhich functions in a similar manner.# To show the currently available actions:pyaarlo--help# To list all the known devices:pyaarlo-u'your-user-name'-p'your-password'listall# this version will anonymize the outputpyaarlo-u'your-user-name'-p'your-password'--anonymizelistall# this version will anonymize and encrypt the outputpyaarlo-u'your-user-name'-p'your-password'--anonymize--encryptlistallError ReportingWhen reporting errors please include the version of Pyaarlo you are using and
what Arlo devices you have. Please turn on DEBUG level logging, capture the
output and include as much information as possible about what you were trying to
do.You can use thepyaarloexecutable to anonymize and encrypt feature on
arbitrary data like log files or source code. If you are only encrypting you
don't need your username and password.# encrypt an existing filecatoutput-file|pyaarloencrypt# anonymize and then encrypt a filecatoutput-file|pyaarlo-u'your-user-name'-p'your-password'anonymize|pyaarloencryptIf you installed from git you can use a shell script inbin/to encrypt your
logs. No anonymizing is possible this way.# encrypt an existing filecatoutput-file|./bin/pyaarlo-encryptencryptpyaarlo-encryptis a fancy wrapper around:curl-s-F'plain_text_file=@-;filename=clear.txt'https://pyaarlo-tfa.appspot.com/encryptYou can also encrypt your output on thiswebpage.LimitationsThe component uses the Arlo webapi.There is no documentation so the API has been reverse engineered using browser
debug tools.There is no support for smart features, you only get motion detection
notifications, not what caused the notification. (Although, you can pipe a
snapshot into deepstack...) This isn't strictly true, you can get "what
caused" the notifications but only after Arlo has analysed the footage.Streaming times out after 30 minutes.The webapi doesn't seem like it was really designed for permanent connections
so the system will sometimes appear to lock up. Various work arounds are in
the code and can be configured at thearlocomponent level. See next
paragraph.If you do find the component locks up after a while (I've seen reports of hours,
days or weeks), you can add the following to the main configuration. Start from
the top and work down:refresh_devices_every, tell Pyaarlo to request the device list every so
often. This will sometimes prevent the back end from aging you out. The value
is in hours and a good starting point is 3.stream_timeout, tell Pyaarlo to close and reopen the event stream after a
certain period of inactivity. Pyaarlo will send keep alive every minute so a
good starting point is 180 seconds.reconnect_every, tell Pyaarlo to logout and back in every so often. This
establishes a new session at the risk of losing an event notification. The
value is minutes and a good starting point is 90.request_timeout, the amount of time to allow for a http request to work. A
good starting point is 120 seconds.Alro will allow shared accounts to give cameras their own name. If you find
cameras appearing with unexpected names (or not appearing at all), log into the
Arlo web interface with your Home Assistant account and make sure the camera
names are correct.You can change the brightness on the light but not while it's turned on. You
need to turn it off and back on again for the change to take. This is how the
web interface does it.Other 2 Factor AuthenticationI recommend usingIMAP, it's well tested now and it works. These following
methods haven't been tested or looked at in a while.Rest APIThis mechanism allows you to an external website. When you start authenticating
Pyarlo makes aclearrequest and repeatedlook-uprequests to a website to
retrieve your TFA code. The format of these requests and their responses are well
defined but the host Pyarlo uses is configurable.ar=pyaarlo.PyArlo(username=USERNAME,password=PASSWORD,tfa_source='rest-api',tfa_type='email',tfa_host='custom-host',tfa_username='test@test.com',tfa_password='1234567890')Pyaarlo will clear the current code with this HTTP GET request:https://custom-host/clear?email=test@test.com&token=1234567890And the server will respond with this on success:{"meta":{"code":200},"data":{"success":True,"email":"test@test.com"}}Pyaarlo will look up the current code with this HTTP GET request:https://custom-host/get?email=test@test.com&token=1234567890And the server will respond with this on success:{"meta":{"code":200},"data":{"success":True,"email":"test@test.com","code":"123456","timestamp":"123445666"}}Failures always havecodevalue of anything other than 200.{"meta":{"code":400},"data":{"success":False,"error":"permission denied"}}Pyaarlo doesn't care how you get the codes into the system only that they are
there. Feel free to roll your own server or...Using My ServerI have a website running athttps://pyaarlo-tfa.appspot.comthat can provide
this service. It's provided as-is, it's running as a Google app so it should be
pretty reliable and the only information I have access to is your email address,
access token for my website and whatever your last code was. (Note:if you're
not planning on using email forwarding theemailvalue isn't strictly
enforced, a unique ID is sufficient.)If you don't trust me and my server - and I won't be offended - you can get the
source fromhereand set up
your own.To use the REST API with my website do the following:Register with my website. You only need to do this once and I'm sorry for the
crappy interface. Go toregistration
pageand enter your email address
(or unique ID). The website will reply with a json document containing yourtoken, keep thistokenand use it in all REST API interactions.{"email":"testing@testing.com","fwd-to":"pyaarlo@thewardrobe.ca","success":true,"token":"4f529ea4dd20ca65e102e743e7f18914bcf8e596b909c02d"}To add a code send the following HTTP GET request:https://custom-host/add?email=test@test.com&token=4f529ea4dd20ca65e102e743e7f18914bcf8e596b909c02d&code=123456You can replacecodewithmsgand the server will try and parse the code out
value ofmsg, use it for picking apart SMS messages.Using IFTTTYou have your server set up or are using mine, one way to send codes is to useIFTTTto forward SMS messages to the server. I have an
Android phone so use theNew SMS received from phone numbertrigger and match
to the Arlo number sending me SMS codes. (I couldn't get the match message to
work, maybe somebody else will have better luck.)I pair this withMake a web requestaction to forward the SMS code into my
server, I use the following recipe. Modify the email and token as necessary.URL: https://pyaarlo-tfa.appspot.com/add?email=test@test.com&token=4f529ea4dd20ca65e102e743e7f18914bcf8e596b909c02d&msg={{Text}}
Method: GET
Content Type: text/plainMake sure to configure Pyaarlo to request a token over SMS withtfa_type='SMS.
Now, when you login in, Arlo will send an SMS to your phone, the IFTTT app will
forward this to the server and Pyaarlo will read it from the server.Using EMAILIf you run your ownpostfixserver you can usethis
scriptto set up an email forwarding alias. Use an alias like this:pyaarlo:  "|/home/test/bin/pyaarlo-fwd"Make sure to configure Pyaarlo to request a token over SMS withtfa_type='EMAIL. Then set up your email service to forward Arlo code message
to your email forwarding alias.