Axis camera component

I’ve been working with getting push notifications from Axis devices (www.axis.com), and have a basic component available that would hope you guys would be interested in trying out. My goal is to get this integrated into home assistant when I’m satisfied with the level of integration this component delivers.

You can find my gitlab project here: Robert Svensson / axis-component · GitLab later replaced with GitHub - Kane610/axis: Python library enabling easy communication with Axis devices and its metadatastream
I will move this over from gitlab to home assistants GitHub further down the line.

All settings for video and sensors are configured directly in camera right now.

I learned how HASS works and took a lot of inspiration from the Vera component, so thanks @Pavoni!

Firmware requirement: approx 5.50

#System dependencies:

sudo apt-get install python3-gst-1.0 gir1.2-gstreamer-1.0
gir1.2-gst-plugins-base-1.0 gstreamer1.0-plugins-good
gstreamer1.0-plugins-ugly gstreamer1.0-tools python3-gi

You might also need to link your packages to your site packages
ln -s /usr/lib/python3/dist-packages/gi /srv/homeassistant/lib/python3.4/site-packages

Example configuration.yaml entry

axis:
m1045:
name: M1045-W
host: 192.168.0.90
include:
- camera
- motion

Configuration variables:

name (Optional): The Axis device’s name to display in the front end
host (Optional): The Axis device’s IP address. Default is 192.168.0.90
username (Optional): The Axis device’s username. Default is root
password (Optional): The Axis device’s password. Default is pass
location (Optional): The Axis device’s physical location.
include (Required):

  • camera (Optiona):
  • motion (Optiona): Motion detection sensor
  • pir (Optiona): PIR sensor
  • audio (Optiona): Audio sensor
  • Observe that it is not recommended to keep the root users password as default
    and for all features in this component there are no need to expose a user above
    viewer privileges (might change with development).

Possible additional features:
Additional sensor support: Input ports, Day night state for IR lights,
Live stream access, tampering, recording and storage alerts
Triggering of output ports and relays
Light control
Media player platform for TTS to speaker
Audio stream from camera for voice control

5 Likes

Looks nice. However it seems like your Gitlab project is configured too strict since the code isn’t visible.

It is supposed to allow everyone with gitlab accounts, will look into it!

Edit: changed settings to public

I’m now seeing the same without login as with: project description and the registry. But the code is not visible.

Opening up more stuff, some things aren’t clearly defined at gitlab it seems. Have tried in a browser without being logged in and I can now download the repository

Works! Will give it a try tomorrow when I’m back at the office :slight_smile:

1 Like

Great! I’m grateful for any feedback, I don’t think I will get too many using this plugin, so I don’t expect a widespread beta testing phase.

BTW! Something I’ve forgotten to write about; I think it is a requirement of firmware 5.50 or similar to use the metadatastream which I base this on.

I have M3005 cameras and testing this. Do i change in config file to m3005?
When i run “ln -s /usr/lib/python3/dist-packages/gi /srv/homeassistant/lib/python3.4/site-packages” i get access denied error. Im new to this. Do you know what I’m doing wrong?
I now gett Invalid Config in HASS and pointing to axis.

Are you the right user? If you are using hassbian I think you need to go in to your virtual env and be the home assistant user

Hi @Robban

Could I ask you how your are monitoring/pulling the metadatastream is there a way of capturing this. I use axis cameras a lot through work and have a couple on the house so I’m really interested in this add on.

Although slightly off topic I need to monitor the metadatastream for a project at work, so wondering if you could point me In The right direction?

Cheers

I will break the project up in to multiple stand alone files further down the road.

But you can just use the MetaDataStream class and its dependencies on its own. It’s all available in the top most axis.py file

/R

Cheers. I will take a look, although python is not one of my strong point yet :see_no_evil:

I like python in that it is designed to be easily read :slight_smile:

I will do what I can to explain if you need help

I tried to install the component but since it’s the first time i install a custom component i run into issues.

I am running Home Assistant in a docker container.

I created a folder custom_components and places the axis.py and the two folders binary_sensor and camera into it so it looks like this

config

  • custom_components
    axis.py
    • binary_sensor
    • camera

but i get a problem it can’t load or find the component :

2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up input_boolean
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up updater
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up verisure
2017-05-19 13:28:11 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.axis. Make sure all dependencies are installed
Traceback (most recent call last):
File “/usr/src/app/homeassistant/loader.py”, line 141, in get_component
module = importlib.import_module(path)
File “/usr/local/lib/python3.5/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 986, in _gcd_import
File “”, line 969, in _find_and_load
File “”, line 958, in _find_and_load_unlocked
File “”, line 673, in _load_unlocked
File “”, line 673, in exec_module
File “”, line 222, in _call_with_frames_removed
File “/config/custom_components/axis.py”, line 15, in
from axis import AxisDevice
ImportError: No module named ‘axis’
2017-05-19 13:28:11 ERROR (MainThread) [homeassistant.loader] Unable to find component axis
2017-05-19 13:28:11 ERROR (MainThread) [homeassistant.setup] Setup failed for axis: Component not found.
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up discovery
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up config
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up logbook
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up tts
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up zeroconf
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up device_tracker
2017-05-19 13:28:11 INFO (MainThread) [homeassistant.setup] Setting up ios
Failed config
General Errors:
- Component not found: axis
- Setup failed for axis: Component not found.

Successful config (partial)

I also tried to create a folder named axis inside custom_components and then place the files/folders there but it still won’t work.

I did run the :

sudo apt-get install python3-gst-1.0 gir1.2-gstreamer-1.0
gir1.2-gst-plugins-base-1.0 gstreamer1.0-plugins-good
gstreamer1.0-plugins-ugly gstreamer1.0-tools python3-gi

but i can’t run :

ln -s /usr/lib/python3/dist-packages/gi /srv/homeassistant/lib/python3.4/site-packages

since the path does not exist in the docker container i have or i don’t know what it is here, i don’t know if this is the reason it doesn’t load the component so any help would be great :wink:

donnib

1 Like

So it sounds like you have put the files in the right place but can’t find the place where hass has got its package installs. Observe! Those paths are just suggestions, they may differ on different systems and setups.

To simplify debugging I’d suggest wait till tomorrow when the component will be part of the release. Then we only need to care for making sure that hass can find the gi package.

If I get the time I will have a look on docker as well

1 Like

Found this path on the docker hub

./local/lib/python3.4/site-packages

And in your logs a local/lib /python3.5 is mentioned, if that directory had a site-packages folder, that is probably the correct target folder

@Robban thx for getting back. I installed the newest docker image 0.45 where the component should be part of it. I did following :

  • Run apt-get update
  • Run apt-get install python3-gi gir1.2-gstreamer-1.0
  • Run ln -s /usr/lib/python3/dist-packages/gi /usr/local/lib/python3.4/site-packages
  • Restarted the docker image but the gi can’t be found, see log bellow.

Any ideas what i am doing wrong ?

2017-05-22 10:50:51 ERROR (MainThread) [homeassistant.setup] Error during setup of component axis
Traceback (most recent call last):
File “/usr/src/app/homeassistant/setup.py”, line 188, in _async_setup_component
None, component.setup, hass, processed_config)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/app/homeassistant/components/axis.py”, line 162, in setup
if not setup_device(hass, config):
File “/usr/src/app/homeassistant/components/axis.py”, line 170, in setup_device
from axis import AxisDevice
File “/usr/local/lib/python3.6/site-packages/axis/init.py”, line 1, in
from .stream import MetaDataStream
File “/usr/local/lib/python3.6/site-packages/axis/stream.py”, line 2, in
import gi # pylint: disable=import-error
ModuleNotFoundError: No module named ‘gi’

I can see that home-assistant has upgraded to python 3.6 so i tried this :

ln -s /usr/lib/python3/dist-packages/gi /usr/local/lib/python3.6/site-packages

and now i get a slight variation in the error :

2017-05-22 11:16:01 ERROR (MainThread) [homeassistant.setup] Error during setup of component axis
Traceback (most recent call last):
File “/usr/src/app/homeassistant/setup.py”, line 188, in _async_setup_component
None, component.setup, hass, processed_config)
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 55, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/src/app/homeassistant/components/axis.py”, line 162, in setup
if not setup_device(hass, config):
File “/usr/src/app/homeassistant/components/axis.py”, line 170, in setup_device
from axis import AxisDevice
File “/usr/local/lib/python3.6/site-packages/axis/init.py”, line 1, in
from .stream import MetaDataStream
File “/usr/local/lib/python3.6/site-packages/axis/stream.py”, line 2, in
import gi # pylint: disable=import-error
File “/usr/local/lib/python3.6/site-packages/gi/init.py”, line 42, in
from . import _gi
ImportError: cannot import name ‘_gi’

That seems to be some internal issue with gi. Possibly related to python 3.6/Docker.

I will need to set up an environment for this and investigate this. Will probably test with both a 3.6 as well as Docker (first time for me). Sorry for the inconvenience!

/R

So I’ve been able to look in to this a little bit, and it seems that the version of gi available on raspbian does not support python3.6, which is a shame.

I’m gonna mention for @balloob that there might be other external dependencies that doesn’t work with python3.6 out of the box.

Anyway, I’m gonna try to build a newer version of gi to see if I can get it to work at all with python3.6. But that is probably gonna take a few days since this is not something I know very well.

In the mean time if you wanna use the Axis component I guess you would need to not use the Docker together with python3.6.

/R