Best way to send HTTP command from Camect on an alert

513 views
Skip to first unread message

EnhanceEnhanceEnhance

unread,
Mar 1, 2021, 9:39:42 PM3/1/21
to Camect User Forum
I'd like to trigger an Axis network speaker to play an audio clip when an object is detected in Camect. Ideally, you'd be able to trigger different audio clips based on different object alerts from different cameras.

Basically, an HTTP command in the format "http://192.168.x.x/axis-cgi/mediaclip.cgi?action=play&clip=x" is all that is needed to make this happen. What do you think the best way is to accomplish this with Camect? Home assistant? I'm not very familiar with HASS and have zero Python experience (willing to learn!). Any suggestions on where to start are appreciated!

ar...@hautala.dev

unread,
Mar 1, 2021, 10:24:01 PM3/1/21
to Camect User Forum, EnhanceEnhanceEnhance
One option would be to use the Python Camect API [1] to subscribe to object events. You can then make a call to the speaker with whatever clip is appropriate for the given detected objects.


It's Python, but it really wouldn't take much to wire those together.

Steve Lee

unread,
Mar 1, 2021, 10:45:35 PM3/1/21
to EnhanceEnhanceEnhance, Camect User Forum
In case you were not aware Camect can do audio announcements to any Google Cast device.  There is also a headphone jack on the back of the Camect hub that can be used for audio output into an amplifier.

If the audio has to be through your Axis Network speaker there is also a third party partner to Camect that can send HTTP commands based on alert triggers.

Steve.

On Mon, Mar 1, 2021 at 6:39 PM EnhanceEnhanceEnhance <ma...@subwaytruckparts.com> wrote:
I'd like to trigger an Axis network speaker to play an audio clip when an object is detected in Camect. Ideally, you'd be able to trigger different audio clips based on different object alerts from different cameras.

Basically, an HTTP command in the format "http://192.168.x.x/axis-cgi/mediaclip.cgi?action=play&clip=x" is all that is needed to make this happen. What do you think the best way is to accomplish this with Camect? Home assistant? I'm not very familiar with HASS and have zero Python experience (willing to learn!). Any suggestions on where to start are appreciated!

--
You received this message because you are subscribed to the Google Groups "Camect User Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@camect.com.
To view this discussion on the web visit https://groups.google.com/a/camect.com/d/msgid/forum/5c472bb0-a1cd-4cd7-8bce-c1e290c68199n%40camect.com.

EnhanceEnhanceEnhance

unread,
Mar 1, 2021, 11:27:53 PM3/1/21
to Camect User Forum, ar...@hautala.dev
Would you use something like a Raspberry Pi as the intermediary device to "subscribe" to the object events and then call the HTTP request for the Axis speaker? Sorry, I know these are probably dumb questions. Trying to learn more about how this setup would work. Thanks for the reply!

EnhanceEnhanceEnhance

unread,
Mar 1, 2021, 11:32:10 PM3/1/21
to Camect User Forum, CamectSteve, Camect User Forum, EnhanceEnhanceEnhance
Axis makes an I/O module (P8221) which would could make this work, but would only play the pre-made voice alerts from Camect. This use case is more for a commercial application where we'd like to play specific audio clips based on which camera was activated. For example, a parking lot camera would activate a clip saying this is private property, please leave immediately. On the other hand, an activation from within the perimeter would play a siren and police are on the way (or to that effect).

ar...@hautala.dev

unread,
Mar 1, 2021, 11:56:24 PM3/1/21
to Camect User Forum, EnhanceEnhanceEnhance, ar...@hautala.dev
Yep, and it wouldn't have to be a Pi. Anything that's on while you want the audio alerts would work.
Questions are how we learn ;-) I'm happy to help.

EnhanceEnhanceEnhance

unread,
Mar 2, 2021, 11:33:52 AM3/2/21
to Camect User Forum, ar...@hautala.dev, EnhanceEnhanceEnhance
Gotcha. As a total newb in the Python (and programming in general) world, my eyes glazed over looking at the Camect-py API. Probably over my head trying to figure out the python API and writing code to call the HTTP request.

ar...@hautala.dev

unread,
Mar 2, 2021, 12:36:21 PM3/2/21
to Camect User Forum, EnhanceEnhanceEnhance, ar...@hautala.dev
You hit my soft spot. I haven't tested this, but it should give you what you want, except for conditional handling of the events.

#!/usr/bin/env python

import camect
import requests
import time
import datetime

def handle_event(evt):
    print_event(evt)
    send_to_axis(evt)
def send_to_axis(evt):
def print_event(evt):
    print ('{}: {}'.format(datetime.datetime.now(), evt))
if __name__ == '__main__':
    camect.Home(
        'camect_hostname_or_ip',
        'camect_local_user_name',
        'camect_local_password'
    ).add_event_listener(
        lambda event: handle_event(event)
    )
    while True:
        # keep running while events trigger
        time.sleep( 5 )


Event objects are dictionaries that currently look something like the following. You'll probably be most interested in the "cam_name", "type", and "detected_obj" keys. For "type", you'll be interested in when it is "alert", rather than "mode" and "detected_obj" will contain a list of the detected objects that you can operate on. There's also an "roi" key that contains the boundary of the detected object, which I removed for brevity.

{
    "cam_id": "abcdef0123456789abcd",
    "cam_name": "camera name",
    "desc": "camera name just saw a USPS truck.",
    "detected_obj": [
        "USPS truck"
    ],
    "type": "alert",
}

EnhanceEnhanceEnhance

unread,
Mar 2, 2021, 2:16:28 PM3/2/21
to Camect User Forum, ar...@hautala.dev, EnhanceEnhanceEnhance
Wow, thank you for taking the time to write this. It is really helpful to be see the code needed to make it work so I can do research and learn how it works. When I run the Python script from my Mac, I get "AttributeError:  'module' object has no attribute 'Home'

Any ideas? Thank you again for your time and help!Screen Shot 2021-03-02 at 11.14.55 AM.png

ar...@hautala.dev

unread,
Mar 2, 2021, 2:24:06 PM3/2/21
to Camect User Forum, EnhanceEnhanceEnhance, ar...@hautala.dev
On Tuesday, March 2, 2021 at 2:16:28 PM UTC-5 EnhanceEnhanceEnhance wrote:
Wow, thank you for taking the time to write this. It is really helpful to be see the code needed to make it work so I can do research and learn how it works.

No problem. I had the framework for an existing project and the effort was mostly stripping out code that you wouldn't need. And referencing existing code is a decent chunk of how I learn new languages, so I'm glad it's helpful to you as well.
 
When I run the Python script from my Mac, I get "AttributeError:  'module' object has no attribute 'Home'

So, you actually have a name collision here.
By naming your script "camect.py" you're blocking the "import camect" line which brings in the Camect library. Just rename the script to something like "camect_axis.py" and you should be all set.

Alan Day

unread,
Mar 2, 2021, 4:40:38 PM3/2/21
to EnhanceEnhanceEnhance, Camect User Forum, CamectSteve
May or may not suit.

This could be automated in a Monitoring Station running Sentinel, Immix or the like with a different recording automatically sent to the Axis speaker based on the camera that triggered the event.

Regards

Alan



EnhanceEnhanceEnhance

unread,
Mar 2, 2021, 7:35:20 PM3/2/21
to Camect User Forum, ar...@hautala.dev, EnhanceEnhanceEnhance
Man...this is killing me. I can usually reverse-engineer most things but this doesn't seem to be one of them. Would you be interested in creating a custom script for me for pay? I just don't know enough about Python to understand how the script "listens" for a certain detected object on a certain camera to fire the Axis HTTP request.

To give more info: I'm trying to set up this Axis C3003-E network speaker to play a warning audio clip when a person is detected in our parking lot outside of business hours (eg private property, please live immediately). I'd also like to have it play a different audio clip if a person is detected inside the perimeter after business hours (eg siren clip & police are on the way).

The nice part is the Axis speaker will handle the scheduling portion of the virtual input trigger. The only thing is the virtual input must be "deactivated" before it can be activated again. This is the URL http://192.168.x.x/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1. If you're interested in possibly writing this script for pay, please let me know! Thanks for your help so far!

ar...@hautala.dev

unread,
Mar 2, 2021, 11:48:40 PM3/2/21
to Camect User Forum, EnhanceEnhanceEnhance, ar...@hautala.dev
Yeah, I can help further. I'll send another message off-list.
Reply all
Reply to author
Forward
0 new messages