Automation to Detect Person, Packages, Animal, and Vehicle on  an Arlo Camera and Announce the Detection on a Sonos Speaker

Portrait of Rod Alcidonis

Rod Alcidonis

Published on October 14, 2022

Subscribe to my YouTube channel
Buy me a beer
Picture of an Arlo Pro II Camera

In this tutorial, I will be showing you how to create a Home Assistant automation to identify person, vehicle, animal, or package on your Arlo camera and then announce the object to your household on a Sonos speaker. I am using Appdaemon to program the automation using Python codes. To successfully implement this automation, you will need to download and configure a few integrations in Home Assistant.

Part I

You obviously will need to have an Arlo camera installed to implement this automation in your Home Assistant Instance. You may use any Arlo Camera that provides for motion detection and object recognition. Please first ensure that your Arlo camera is working as expected outside of Home Assistant before moving on to next steps.

Part II

Then, you will need to download and configure the Appdaemon integration in Home Assistant. The instructions for downloading and configuring Appdaemon can be found here. I will be using Appdaemon to code my automation using the Python programming language.

Part III

You will also need to download and configure the Home Assistant Aarlo camera support integration (Aarlo is the name of the integration as written). This is the integration that will allow you to gain access to your Arlo camera in Home Assistant. You can download the Aarlo integration here. It is crucial that you verify that the integration is working properly with your Arlo camera before proceeding any further with this automation. I will be using the motion detection feature on the Arlo camera as my automation trigger to detect motion, and the object recognition feature to identify which object the camera detected.

Part IV

Once you are certain that your Arlo camera is in working order and that the Home Assistant integration is properly configured, you will also need to download and configure the Home Assistant Sonos Cloud integration. The Sonos Cloud integration uses the cloud-based Sonos control API to send  audio clip commands to your Sonos speaker. I will be using this integration to play the TTS announcements over my Sonos speaker. If you do not use Sonos in your house, you can skip this part and instead use the Home Assistant integration that works with your particular speaker system.

You can download the Sonos Cloud integration here.

Part IV

Display of computer codes

You have now configured the Appdaemon, Aarlo Camera support, and Sonos cloud integrations in Home Assistant. You are ready to start coding the automation. To get started, open a Notepad document or a blank document in a programming interface of your choice. You first will need to register an App in Appdaemon to begin the automation. Please watch my YouTube video to learn how to register and configure an Appdaemon automation app in Home Assistant if you require additional assistance with this step. I also would encourage that you read the Appdaemon API documentation to better familiarize yourself with the tool.

I have created my Arlo camera object detection Appdaemon app as follows:

Front Door Camera Object Detection Announcement:
  module: camera_object_detection_announcement
  class: CameraObjectDetectionAnnouncement
  motion_sensors:
    camera_motion: binary_sensor.aarlo_motion_front_door

Please note, the above code has to be placed in the Appdaemon’s “apps.yaml” file in your Appdaemon file directory and not in the file that contains the code for the automation.

Part V

With the Arlo camera detection Appdaemon app successfully registered in Home Assistant, we will proceed with coding the actual automation. First, I will be importing the Appdaemon library, create a subclass of the library so I’m able to use the code in the automation, and initialize the app so it is activated in Home Assistant.

You will notice that I use the “#” symbol throughout the code. This is a Python’s way to indicate a line has been commented. This is how I will be commenting each line of the code to explain how the automation is configured, and at the end, I will be sharing the complete code without any comments for your use.

# Importing the library
import appdaemon.plugins.hass.hassapi as hass
#Creating the subclass and naming it “CameraObjectDetectionAnnouncement”
class CameraObjectDetectionAnnouncement(hass.Hass):
	#Initializing the app
	def initialize(self):

At this point, my Appdaemon automation is alive and running in Home Assistant but it is not doing much in its current state. Next, I will be creating a state change listener to monitor motion detection on my Arlo camera.

The state change listener method is the trigger for my automation in Home Assistant. The listener method requires  a “callback” method as a parameter. I have named my “callback” method “self.on_motion_detected.”

Additionally, I need to tell the listener method which camera whose motion I want to monitor. I am using this code: “self.args[“motion_sensors”][“camera_motion”]” to identify the Arlo camera in my listener method. This is the procedure you should follow to access the camera entity that we included in the Camera Detection app that we created in Appdaemon’s “Apps.yaml” file.

The information or attribute I am interested in monitoring on the camera is its motion state. The code to access that information is this: “attribute = “state”, new = “on”).” The reference to “new = “on” is Appdaemon’s way of identifying when the state of the Camera sensor changes to on in Home assistant.

		#Creating the listener method
		self.listen_state(self.on_motion_detected, self.args["motion_sensors"]["camera_motion"], attribute = "state", new = "on")

My listener method has been created in Home Assistant and it is monitoring motion detections on the Arlo camera. Next, I need to code the “callback” method that I passed to the listener method, which contains the logic for my automation. The “callback” method will detect motions on the Arlo camera and  processes those activities to determine whether the camera detected either a person, an animal, a vehicle, or a package. It then will announce on the Sonos speaker what image the Arlo camera actually detected.

	#Creating the “”callback” method.” This is the exact procedure to do so in Appdaemon
	def on_motion_detected(self, entity, attribute, old, new, kwargs):
		# Using a conditional statement to ascertain if motion has been detected on the Arlo camera
		if new == "on":
			# Checking whether the motion was on the front door Arlo camera
			if self.get_state(entity, attribute = "camera_name") == "Front Door":

If motion was detected on the front door, I need to know what type of object the Arlo camera detected. I am going to capture and save the object_type in a variable. The reference to “sensor.aarlo_last_front_door” is the sensor in Home Assistant that the Aarlo integration uses to capture and store the object that is detected by the Arlo camera.

				# Saving the object type in a variable
				self.object_name = self.get_state("sensor.aarlo_last_front_door", attribute = "object_type")
				# Checking to make sure that the Arlo camera actually identified a  recognizable  object. The camera cannot process everything.
				if self.object_name is not None:
					# If an object was identified, announce on the Sonos speaker which object the Arlo camera identified.
					self.call_service("media_player/play_media", entity_id = "media_player.family_room", media_content_id = "media-source://tts/cloud?message="+f'{self.object_name} detected on the {self.friendly_name(self.camera_entity)}'.format(), media_content_type = "music", extra = {"volume": 0.40})

This is the procedure for formatting your code to call the media player service in Home Assistant using the Sonos cloud integration. Next, I am going to log a message in the Appdaemon log file to test whether my code is running as expected.

					# Log message to know which camera detected the object
					self.log(self.friendly_name(entity)+ " has detected " + self.object_name)

Part VI

This is the complete code, without any comments, starting with the Appdaemon app:

Front Door Camera Object Detection Announcement:
  module: camera_object_detection_announcement
  class: CameraObjectDetectionAnnouncement
  motion_sensors:
    camera_motion: binary_sensor.aarlo_motion_front_door

import appdaemon.plugins.hass.hassapi as hass
class CameraObjectDetectionAnnouncement2(hass.Hass):
	def initialize(self):
		self.listen_state(self.on_motion_detected, self.args["motion_sensors"]["camera_motion"], attribute = "state", new = "on")
	def on_motion_detected(self, entity, attribute, old, new, kwargs):
		if new == "on":
			if self.get_state(entity, attribute = "camera_name") == "Front Door":
				self.object_name = self.get_state("sensor.aarlo_last_front_door", attribute = "object_type")
				if self.object_name is not None:
					self.log("lo")
					self.call_service("media_player/play_media", entity_id = "media_player.family_room", media_content_id = "media-source://tts/cloud?message="+f'{self.object_name} detected on the {self.friendly_name(self.camera_entity)}'.format(), media_content_type = "music", extra = {"volume": 0.40})
					self.log(self.friendly_name(entity)+ " has detected " + self.object_name)

I hope you found this article, "Automation to Detect Person, Packages, Animal, and Vehicle on  an Arlo Camera and Announce the Detection on a Sonos Speaker", informative and useful. For more smart home automation content, you might want to read this article next: What is a Smart Home and How Does it Work?. If you found this article helpful, Subscribe to the On Motion Detected YouTube Channel, or sign up for our newsletter for more smart home automation content delivered to your inbox.

Leave a comment

Your email address will not be published. Required fields are marked *