Arlo: replacement pyarlo module

Hi Steve,

Thanks for your response - I am in a virtual env and was working fine with version 0.90, but something has broke with live streaming since beta 0.91.

2019-04-02 21:39:34 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 418, in start
    resp = await task
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_app.py", line 458, in _handle
    resp = await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/real_ip.py", line 33, in real_ip_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/ban.py", line 68, in ban_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/auth.py", line 206, in auth_middleware
    return await handler(request)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/http/view.py", line 112, in handle
    result = await result
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 475, in get
    return await self.handle(request, camera)
  File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/components/camera/__init__.py", line 511, in handle
    return await camera.handle_async_mjpeg_stream(request)
  File "/home/homeassistant/.homeassistant/custom_components/aarlo/camera.py", line 164, in handle_async_mjpeg_stream
    from haffmpeg import CameraMjpeg
ImportError: cannot import name 'CameraMjpeg'

@grantc Crap, I’ll take a look!

Hi @sherrell
Have you got time to think about a solution for the delay and the receiving previous snapshot issue?
Thanks!!

@woodmoose
I’m still going to implement the get_snapshot websocket call.

Can you try the latest build from the snapshot branch? This one will only move out of the snapshot state when the snapshot has been taken and the image downloaded to the home-assistant device - ie, camera_thumbnail will read it.

Can I ask how you get the image from the camera?

So I just tried your update. I’m now using from ‘taking snapshot’ to ‘idle’ as a trigger for sending the snapshot over with notify.

There is a major bug though - the state of the cameras freezes and stay on ‘taking snapshot’ state. While testing, I even got one of my binary_sensor.aarlo_motion_cameraName that froze and stay on ‘detected’ state… ?

Not sure if I did something wrong though… I don’t think so …
Here is the code I’m currently using:

- alias: "[Alarm] Take Snapshot When Motion Detected - Frontdoor"
      initial_state: 'on'
      trigger:
        platform: state
        entity_id: binary_sensor.aarlo_motion_frontdoor
        from: 'off'
        to: 'on'
      action:
      - service: camera.aarlo_request_snapshot_to_file
        data_template:
          entity_id: camera.aarlo_frontdoor
          filename: "/config/www/cameras/frontdoor/frontdoor_snapshot.jpg"

    - alias: "[Alarm] Notify With Snapshot When Motion Detected - Frontdoor"
      initial_state: 'on'
      trigger:
        platform: state
        entity_id: camera.aarlo_frontdoor
        from: 'taking snapshot'
        to: 'idle'
      action:
      - service: notify.iphone
        data:
          message: "Motion detected at the front door"
          data:
            attachment:
              url: "http://hassio.local:8123/local/cameras/frontdoor/frontdoor_snapshot.jpg"
              content-type: jpeg
              hide-thumbnail: false

Using this code allows me now to get the correct picture sent to my phone, but it takes pretty long time - almost 5/7seconds ? My local network is not slow… don’t know how to improve the speed ?

edit: actually, I need to improve my code in order to get these automation triggered only when motion is detected, otherwise, each time the camera are taking snapshot (eg. for updating the thumbnail <-- the state stays frozen here too), I will receive a false one…

edit/2: ok I need to go back to the master branch because it stays stucked on taking snapshot each 5 minutes… let me know if you can reproduce and fix - Thanks again :wink:

What kind of camera are you using?

And I reproduced the problem almost immediately. I’ll have a fix in a few minutes. The snapshot request went in but I didn’t handle the shift into idle before it came back.

Hi Sherrell,

So you are aware the issue is still there after the official 0.91 release :frowning:

I tried on the 0.91 beta and I didn’t see the issue. But I’ll try on the official release in a few minutes.

Also, I was trying a virtualenv, I’ll try against a docker too.

Steve

Great, I’ll try your fix later today and let you know.
As for the cameras, I’m using four Arlo Pro 2.

It’s working for me in docker and virtualenv. The stream code will use the Mjpeg code if it can’t find a stream_source() method in the custom camera component. Can you check the code is the latest?

The Pro 2 are pretty quick at snapshot. But there was definitely a race condition of the camera went idle before the snapshot returned.

As for the automation, it’s not guaranteed to move from ‘taking snapshot’ to ‘idle’, it could move back to ‘recording’ too.

Will check when I get home - so the ‘custom:aarlo-glance’ now supports streaming? I have been using just a picture glance card up until now.

From the read me:
Set image_click to play on the aarlo glance card.

Yes I am wondering why it takes so long - I will make some new test and let you know.
I didn’t think about the fact it could move back to ‘recording’ … Do you have any recommendation of what could be more efficient ?

I also see this using the latest snapshot to file branch…

@grantc @Swiftnesses
Is there any ‘stream’ related messages in the start up?
Which branch are you using?

@woodmoose
The speed is mostly controlled by Arlo. I ask it to take a snapshot, it tells me when that is finished, I download the image and then I change the state from ‘taking a snapshot’. If you turn on logging you can follow the messages and state changes.

If you are already recording when taking a snapshot then it is a lot faster then if the camera is idle.

@grantc
Yes, you should be able to live stream to the aarlo-glance card. You can also add a play icon by adding play into the show area.

1 Like

The latest version you committed seems better in term of speed…

In your previous message, you were saying that it’s not guaranteed to move from ‘taking snapshot’ to ‘idle’ - so which trigger should I choose to be best ?

edit: I guess using only from parameter will be fine…

from: 'taking snapshot'

It depends on how you intend to use the camera…

from: taking_snapshot will work.

But I just reread your automation and you’re triggering from a motion detect in which case checking for idle will probably also work.

But if you trigger a snapshot from a stream moving into recording you need to handle the fact the stream can move back to recording or idle.

Clear as mud?

Only to help you i will share a other work around i use for detection of when the snapshot is done.

I use the Folder watcher to see when the file is created and trigger my script from there.

- id: '1553379785046'
  alias: doorbell2
  trigger:
  - event_data:
      event_type: created
    event_type: folder_watcher
    platform: event
  condition: []
  action:
  - data:
      entity_id: script.1553007249921
    service: script.turn_on

Hope it helps have a good day

1 Like

Oh nice, I will give a try and see which one is faster to notify.
Actually, the automation I’m using now seem working well but I’m curious of your solution !
Thanks