Home Assistant
  • Home Assistant is a smart things hub for everything. For people asking for homekit support Home Assistant is the way to go.

    I would love to be able to use SS with Home Assistant.

    Here is a list of support systems. https://www.home-assistant.io/components/#camera

    I tried using - https://www.home-assistant.io/components/camera.generic/ and https://www.home-assistant.io/components/camera.mjpeg/

    Issue here was the fact I am using H.246 and I don't want to stop using it.

    Ben, am I able to stream from SS to Home Assistant?

    Side note... Home Assistant is amazing and has a great community. I know if you built a plugin for it you would sell a heaps of SS to the community! You would also then have the benefit of all the other amazing thing people could do with SS using Home Assistant!!
  • I just discovered with sub stream is, so I got it working but all the above still applies!!
  • You know you want to Ben..
  • This is interesting, we will have a look at the possibility of a SecuritySpy plugin for Home Assistant, I think that would be a good idea.

    The "Generic MJPEG IP Camera" plugin seems to be the best one to use currently. The MJPEG URL to supply would be something like this:


    (see the SecuritySpy Web Server Specification document for a full description of the ++video request.

    You can obtain the correct camera number from the Camera Info window in SecuritySpy - if you don't currently have this column displayed, click the header bar where you see the column names, and you will get a pop-up menu that allows you to add the Camera Number column.
  • I agree, from what I've seen on the web so far there would be a great demand for something like this. The NEST solution is Clould based and insanely expensive. I genuinely think that a home server solution which could integrate with Google Home and Homekit would be very popular.
  • I am working with Home Assistant to develop a series of switches that arm and disarm individual cameras. The benefit will be to enable the switches to be used with other automatons or scripts within Home Assistant. Here is the yaml I am using in my Home Assistant configuration.yaml.

    - platform: command_line
    command_on: '/usr/bin/curl -k "http://{ip}:8000/++ssControlMotionCapture?cameraNum=3&arm=1&auth={authkey}"'
    command_off: '/usr/bin/curl -k "http://{ip}:8000/++ssControlMotionCapture?cameraNum=3&arm=0&auth={authkey}"'
    command_state: '/usr/bin/curl -k --silent "http://{ip}:8000/++cameramodes?cameraNum=3&auth={authkey}" | grep -oP "(?<=M:).*"'<br /> value_template: '{{ value == "ARMED" }}'

    where {ip} = my camera IP address and {authkey} = my authentication. Ignore the not sure why that keeps popping up value_template is a separate line in the yaml.

    I suspect my error is in the syntax of the grep command because when I use curl on the command line in terminal to fetch the state of the camera it returns


    however, as soon as I add the grep command it fails. If I can get this working I should be able to control this camera's motion capture, notifications, etc.. with switches in Home Assistant.
  • Anyone else have any experience with integrating security spy with home assistant. I am close, but do not have it working successfully yet.
  • Hi jjbanker
    This: {authkey} will not work in a command_line switch. Either you will have to type the full Auth Key or you will have to put the whole line in the secrets file with the typed auth key and then just do something like:
    command_on: !secret cam1_on
    command_off: !secret cam1_off
    command_state: !secret cam1_state

    Your value template is fine and so is you grep command. I use exactly the same and it works.
  • I'd like to get my SS install working with HA too. I'm curious about ben's aug 23rd post. Is this method known to work, or is this just speculation?

    Has anyone made any more progress on this?
  • Things I've done with SS/HASS.

    Cameras display in the HASS dashboard.
    PIR sensors (or any sensors or event changes) in HASS trigger SS recordings.
    Telegram notifications with camera screenshots when an event is triggered.

    I can probably do a write up if people are interested?
  • Thanks for the info Boxgrove, pretty self explanatory. I'll tweak my setup based on your info.
  • Ben mentioned in an earlier post that using the "++video request" method would be the best approach for pulling live video into HA today. It seems to work well, but is there a way to get only the video feed, without the "live" title and links to "main page", "captured files" and "cant view?" ?
  • Hi @bonfireva the ++video request is for the MJPEG live video stream itself. So there is no associated HTML page with titles etc. It sounds like you are referring to the "live" request, which gets you an HTML page with the titles and other text that you describe, containing the video image.

    This "live" page comes from an HTML template, which you can edit to remove the stuff you don't want. Please see Customising SecuritySpy’s Web Interface.
  • Thanks Ben, that's exactly what I was looking for. And you are correct, I was trying to use the new iFrame card in Home Assistant to display live video using the live request feature.
  • Ben, any update on a plugin for Home Assistant?
  • Has anyone had more luck integrating with Home Assistant?
  • I am sure security spy will eventually become a standard integration in home assistant, but I suspect this is pretty low in priority, especially since there are ways to make it work today with some configuring. The security spy server is just as easy to use as setting up cameras are in home assistant. Its actually not that hard, just takes a little tinkering to integrate the two together. See comments from Boxgrove above, Boxgrove was kind enough to share some of his config files. If you are using home assistant you should be familiar with yaml and how to create switches, automations, saving backups, etc..

    I run home assistant in a virtual machine on an old computer, 2012 Macmini in my case, so I just save a snapshot of my working virtual machine before I start tinkering and if I crash home assistant or break my configuration, I just restore my vm from the snap shot and its back up and running.
  • So spending some time with Home Assistant (HA), as I need a better way to control automations vs spending additional$$ for expensive web relays, when I have existing relays in place. Over the years, I've collected switches from TP-Link, Leviton, Eco Plugs, EweLink, and now leaning more towards Shelly relays. I'm finding it hard to find good outdoor motion sensors that tie to HA, so I'm on a quest to learn Node-Red and incorporate SS into HA.

    Thanks Boxgrove for the github files. I'm running my instance of HA on a Raspberry Pi, as I've got my Mac Pro running SS & Plex management, so I'm trying to reverse the thought process between the two platforms.

    My primary goal is when a motion is detected by a camera, then I'd like to 1) Determine if it's night time and 2) If Yes, send a command to turn on the lights associated with that camera and potentially another. Basically, using my cameras a glorified Motion Sensors, but hoping over time the AI interface that Ben has written will help minimize false positives from the occasional wasp or other insect, and thereby scare off potential intruders. My secondary goal, I plan to dissect my alarm system panel, whereby an actual breach of an alarm contact will trigger All Cameras, All Lights (internal/external), and anything else that makes sense that my current alarm system doesn't cover or wants to gouge me on the cost of the service. My current alarm system is an IControl Hub that uses Z-Wave modules and already has a siren and central station monitoring. I'm hoping to figure out how to sniff out the Z-Wave messaging and use HA to drive the other switches/automations.

    Any ideas or ways to simplify this would be appreciated. I agree with the others on this thread, that tying together existing IoT devices with SS is a good thing for Ben and the future of SS for all of us.
  • Hey tlutrick, this is all possible currently with Applescripts. I am using a ISY UDI944i automation system for our house. It is highly customizable with IF, ELSE, COMMANDS. I have AppleScript that read motion from SS to trigger the ISY system. Works flawless.
    Also I have the Streamdeck XL for a physical controller. I posted this solution in a earlier thread. give it a search.
  • tlutrick I use combination of Apple scripts from SS to webhooks on the Pi running HASS

    I’ll share config tomorrow but basically when motion is detected on SS, it sent a curl command to a URL on the Pi (the webhook) which acts as a trigger in an automation. You can then use a condition if it’s night (maybe using the sun sensor component) and then turn on the light as normal.

    EDIT: right this will be very quick and dirty but hopefully you can follow... This is an automation I use to detect motion on a SS camera to flash a light an LED strip in my office. Formatting will probably be screwed up, but if you can't get it working give me a few days and I'll try and get it on GitHub or something.

    make a security spy script: mine is called driveway_ss_trigger_1 - pay attention to that (remove square brackets below) and set that to be an action on motion detection.

    [do shell script "curl -d \"\" \"http://HASS_IP:8123/api/webhook/driveway_ss_trigger_1\""]

    Then my automation in Home Assistant looks like:

    - alias: SS Trigger Driveway Desk Flash
    id: ss_trigger_driveway_desk_flash
    - platform: webhook
    webhook_id: driveway_ss_trigger_1. ### this needs to match up to what the curl command points to

    condition: ### this just links to the occupancy sensor in my office to make sure it doesn't fire when I'm not there
    condition: state
    entity_id: binary_sensor.0x00158d0002c5888c_occupancy
    state: 'on'

    - service: script.driveway_motion #this runs a script that flashes the LED's
    - service: automation.turn_off
    entity_id: automation.ss_trigger_driveway_desk_flash
    - delay:
    minutes: 1
    - service: automation.turn_on
    entity_id: automation.ss_trigger_driveway_desk_flash

    Now you're probably wondering why I turn the automation off for a minute and then back on again... I have the driveway_motion script set up so it first captures the current state of the LED strips to a scene (I have a few different colour modes) flashes them red to indicate motion detected and then returns to it's previous state. So for example if I had them set to blue before motion is detected, they would flash red and then return to blue.

    What I found is that if motion was detected a 2nd time when the red flashes were happening, the script would capture the red flashes as the previous state and keep them turned on. Having the automation turn off for a minute gives the LEDs an opportunity to return to their previous state.

    If you're interested - script.drive_motion is....

    - service: scene.create
    scene_id: before
    - light.wled_desk
    - service: light.turn_on
    entity_id: light.wled_desk
    transition: 3
    brightness: 127
    rgb_color: [255, 0, 0]
    effect: Solid ### just realise they don't actually flash here they just turn red, ha!
    - delay:
    seconds: 10
    - service: scene.turn_on
    entity_id: scene.before

    N.B you can also run multiple curl commands in one apple script - mine actually fires "driveway_ss_trigger_1" and "driveway_ss_trigger". One is a telegram notification with a capture screenshot, and the other is the desk flashing. I have them as two separate automations so I can turn them on and off independently.

    Now this is all probably a lot easier with NodeRED.... but I've always used yaml and it works for me.
  • BoxGrove, this is awesome and appreciate the help. I was on vaca and missed your post. Digging in now
  • BoxGrove,

    Been a terrible week. I've run into significant problems with my HA instance. AT&T had to replace my modem and the new BGW210-700 modem blocks port 443 and screwed up my access, so I spent most of the time troubleshooting the fiasco they created, but now I'm finally good...

    Ok, so I'm working through your scripts (thank you btw) and not following the creation of the entities. I'm still working through this

  • BoxGrove,

    You are FREAKING AWESOME!!! Took me a bit to decipher the syntax and get it working, but I'm rolling now. It is better than expected. DrZzzz's had a YouTube video on Sonoff integrations for local control that allowed me to turn on some other switches with the motion, and it works great. Gave me a better understanding for my ECOPlugs, Leviton switches, TP-Link Switches, etc... Going to move on to MQTT next and look to integrate some of my Shelly 1 switches.

    I'm still having to run my HA instance in HTTP, since I can't figure out a workaround for the whole AT&T Port 443 blocking issue. If I turn on my ssl_certificate and ssl_key, then I can access it remotely via HTTPS, and thereby security, but I can't get HTTP to work. I know I'm doing some rookie mistake, but I'll have to keep tinkering with other options to figure it out. I turned on two part authentication for some added security for now, though I don't know how much that helps. I spent 2 weeks screwing around with HTTP issues, with no joy, and your AWESOME instruction took me just 2 days to get some cool automations going.

    Thanks for the guidance and assist, and I encourage others on here to think about Home Assistant. Very Cool stuff and I've only scratched the surface. Look for me on the HA & GitHub pages as SolarCzar (changing my login to reflect my huge 20kW solar array hobby).

    Later guys
  • Oh, and Ben you're AWESOME as well for the ability to push the webhook scripting and improved AI on motion detection. Makes for a very nice integration now. Much happier and full of ideas on how to better automate my home. Thanks
  • No worries at all mate. Glad you could get it working. I’ve spend so much time messing trying to get it working so glad it’s been helpfully for someone else.

    I’ve noticed you can arm and disarm SS captures
    through shell commands so my next job is to set up automations that arm and disarm motion capture (useful for when I’m on the driveway washing the car, or in the garden). I’ll probably automate with a Wi-fi or RF button by the front door that turns off motion capture for X amount of time. (So I don’t forget to turn it back on)

    Home assistant really is so powerful if you’re willing to take the time to learn and tinker. I found that the AI motion capture on security spy was so much better than the motion sensors I was using through home assistant that had so many false positives.

    I just noticed in my trigger code above there is a random full stop after the webook ID - that shouldn’t be there and hope it didn’t cause too many problems.

    If I’ve got time I’ll shove al that code into a github, one of the most frustrating things with Yaml is the formatting and indentation so hopefully can save someone some headaches somewhere
  • Boxgrove & Ben,

    So I'm noticing that the curl commands aren't executing all the time. I'll test for example the command...

    do shell script "curl -d \"\" \"\""

    which executes an automation in Home Asst and runs fine. I execute it again (from the script editor play button) and it doesn't work. I don't know how to verify that curl commands are going out and being received, but I'm trying to learn. Let me know if you guys can think of something off the top of your head for me to try.

    I got so excited from the initial setup from Boxgrove, that I started adding some more Shelly 1 switches to control more lights to tie to Motion from the cameras. I started noticing that one of my automations related to the garage cameras were really slow. I could walk 20' before the routine would run. That's when I started testing and finding that some routines aren't running all the time.

    Let me know if you have some ideas where/how to test this? Thanks again
  • It might be worth enabling debug logs on Home Assistant to see what it does when receiving web hooks:
  • Just a side note, you may not need to escape all the quotes from your example. Mine looks like this in an Apple Script and it works ok (those are two single quotes after -d):

    do shell script "curl -d ''"
  • So I've got 4 separate script files..

    do shell script "curl -d \"\" \"""
    do shell script "curl -d \"\" \"""
    do shell script "curl -d \"\" \"""
    do shell script "curl -d \"\" \"""

    , but only the garage script actually runs. I've executed the automations within HA and they function correctly, but the webhook ID doesn't seem to be coming through except for the one mentioned. The scripts are identical except for their name, and I did try as paul2020 suggested to change the quote aspects, but with no joy.

    One note, from within Script Editor, I can "play" the garage script and it functions, whereas the others will not. To me, this indicates that the curl command

    I turned on logger: in my configuration.yaml file and it brought my HA to a crawl with too many entries. I changed it to...

    default: warning
    homeassistant.components.automations: debug
    homeassistant.components.webhook: debug
    homeassistant.components.switch: debug

    and this is all it posts...

    2020-07-14 23:23:44 DEBUG (MainThread) [homeassistant.components.webhook] Handling webhook POST payload for driveway_ss_trigger_1
    2020-07-14 23:27:40 DEBUG (MainThread) [homeassistant.components.webhook] Handling webhook POST payload for front_porch_ss_trigger_1
    2020-07-14 23:35:37 DEBUG (MainThread) [homeassistant.components.webhook] Handling webhook POST payload for garage_ss_trigger_1

    notice that the garage_ss_trigger_1 is not a line item, yet it functions perfectly. Thoughts anyone?
  • So I went into Terminal on Mac and entered the curl command, and it executed. Went back into File Editor on HA and found this line in the debug for the appropriate time stamp...

    2020-07-15 00:46:20 DEBUG (MainThread) [homeassistant.components.webhook] Handling webhook POST payload for driveway_ss_trigger_1

    So if I'm thinking about this correctly, the curl command is getting to HA. HA is recognizing the webhook, but it is not executing. I can manually execute the automation in the Configuration and it works. here is the excerpt from the automations.yaml file...
    - id: '1593209500332'
    alias: ss_driveway_motion
    description: Activate lights on SS driveway camera motion
    - platform: webhook
    webhook_id: driveway_ss_trigger_1
    - after: sunset
    before: sunrise
    condition: sun
    - condition: state
    entity_id: switch.shelly_shsw_1_115f00
    state: 'off'
    - device_id: e6629ba0af684d6890b50f41079b5a4d
    domain: switch
    entity_id: switch.shelly_shsw_1_115f00
    type: turn_on
    - delay: 00:10:00
    - device_id: e6629ba0af684d6890b50f41079b5a4d
    domain: switch
    entity_id: switch.shelly_shsw_1_115f00
    type: turn_off

    What am I missing?
  • So I won't know until dark if it's working, but some guys on the HA forum indicated that my condition for when it's dark to turn on a light was wrong and should be...

    condition: state
    entity_id: sun.sun
    state: 'below_horizon'

    We'll check it out tonight, but wanted to reply back to anyone reading this...
  • Ok, another update. The activity is working (Yeah Baby!!!!), but I'm noticing that the amount of time to recognize the motion and then activate the lights is longer than I hoped. I observed that I walked almost 25 feet on my driveway before the light switched on. I thought it was still HA, but I confirmed that the signaling to the Shelly 1 switch is staying local and really quick. When I execute the Apple Script manually on the Mac Pro that acts as the server for SS, it's really fast. So the time from the script activating to the lights turning on is less than 1-2 seconds

    So it's the time from when the motion detection begins, the AI determines it's a person or vehicle (which works great and cuts down false positives enough to make this viable), and sends the Action script. For recording video, it works great. So without sounding ungrateful, how can I improve the timing on this for the switch relay? I like that the lights would not be set off by every insect that flies in front of the camera, but I also don't want to walk completely through the detection area before the lights turn on. Everything is currently set with defaults that Ben wrote.

  • I just installed Home-assistant on the same MacOS server as SecuritySpy. I was able to get a notification to work by using this tutorial as a basis: https://www.nabucasa.com/config/webhooks/#triggering-automation-with-a-webhook

    Start at "Triggering Automation with a Webhook. Once you've enable the web hook, select HTTP POST without parameters and replace the sample url with the one from home-assistant. One caveat is that I'm using the Home Assistant Cloud service. It might work differently without it. The service is $5/month at the time of this post.

    I was thinking it would be nice if Security Spy was one of the integration services, but I'm not sure that would help in this situation. Besides, it's not that much work to do the setup.
  • I hope I'm missing something obvious but after adding the camera and a valid SecuritySpy URL to my HomeAssistant configuration.yaml how do I then add a corresponding card to a Lovelace view?

    Alternatively I've read that the onvif integration is reliable and it detects and connects directly to my Dahua cameras. Is this a better approach for live monitoring?
  • i strongly recommend this integration.
  • What a fantastic integration, thanks for posting the link to it!
  • In response to my question of Apr 19th, I found I needed to add a Lovelace card by entity.
    I now have a Picture Entity Card using the entity "camera.patiostream" which is defined in the following configuration.yaml definition:

    - platform: mjpeg
    username: username_value_here
    password: password_value_here
    name: patiostream
    authentication: basic

    This works for both a dashboard image and a live video when the image is selected.
  • I have been so wrapped up with Home Assistant activities lately, and I just happened across the integration for SS into HA. Set up my cameras on picture entity cards, and now exploring. This works great!

    All my curls are still working to drive actions, but now it should be much more seamless. Now I got to figure out how to use all this stuff.

    Thanks Ben...ps: Dude!, you should have some form of update email/notification when you do all these cool updates for your customers. I could have been jamming months ago, but it's cool, I'm happy today. You're the best.
  • Hi @tlutrick great to hear this is working well for you! We do send in-app update notifications, and also sometimes send an email round to our SecuritySpy mailing list for more major updates and news. As for the "SecuritySpy for Home Assistant" project, this isn't our creation - it is all the excellent work of @briis - many thanks to briis for creating this!
  • Thanks for the kind words Ben.
    One thing that would really improve the HA Integration is a MOTION_OFF event being added to the EVENT STREAM. It is easy to detect when Motion starts but not when it ends. So hopefully you can put that on the 'list of things to do'
  • Hi @briis I'm happy to help here by adding additional information to the event stream, but I'm not sure about something like MOTION_OFF. Assuming you're using the latest version of the event stream (3), SecuritySpy sends MOTION events for each frame that contains motion. Absence of these events indicates no motion. So what you get now is a bunch of MOTION events, and then they will stop.

    But note that in a typical event (e.g. a person walks in front of the camera), you will get some frames with motion and other frames without motion (perhaps the person has stopped momentarily). So you could get something like [MOTION, MOTION, MOTION, MOTION_OFF, MOTION, MOTION, MOTION_OFF, MOTION, MOTION_OFF] for one particular event. I'm struggling to see how this would be particularly useful. Could you please explain how you would want to use these MOTION_OFF events?
  • Hi Ben,
    Basically what my program does is consume the event stream, and updates a State Machine when a new and relevant event happens, that State Machine is then fed back through a Callback to Home Assistant.

    So when a person walks in front of the Camera the Event Stream shows MOTION and the callback tells a binary sensor in Home Assistant that motion is active and turns it on.
    The issue is now when should I turn the Binary Sensor off again. The way it works right now, is that in the Motion Capture settings, I enable Movie Capture and the set the Capture Type to One Movie per Event. Then I watch the Event Stream for the FILE event, and when that occurs I turn the Binary Sensor off.
    But if people have another setting here, the Binary Sensor never gets turned off, or it turns off long after the Motion event is over.
    So therefore it would be great if SecuritySpy could send this MOTION_OFF when it no longer detects motion (Red light Turns back to Yellow in the UI) so that I can watch for this to turn off the Binary Sensor instead of the above workaround.

    I am aware that this can trigger the flow of events as you describe, but that is fine, the sensor will then turn on/off a few times, but that is also what is happening in front of the camera.

    Does this make sense? Or is there any other methods I could use to solve this?
  • Your current method uses the duration of the captured movie file, which is defined by the post-capture time setting, as a proxy for the motion end time. This is reasonable, though the post-capture time could vary a lot from system to system. Plus, as you say, this relies on movie capture being turned on, which is not always the case.

    Instead, how about using a short, fixed delay of a few seconds after the last MOTION event to set the motion end time? If you like, we could add this to SecuritySpy itself to avoid the need for you to implement it. I think this could be better than using the movie end time, and better than the multiple on/off events that would happen if this were done on a frame-by-frame basis. What do you think?
  • Hi Ben,
    Setting the motion end time is a great idea, and even better if you can do it right from SecuritySpy. I can work with that. So if you are going to do that, just let me know when there is something I can start testing. Thanks
  • OK, I've added this in the latest beta version of SecuritySpy (currently 5.3.4b3).

    Now, after one or more MOTION event, there will be a terminating MOTION_END event. The MOTION_END event is sent after there is no further motion trigger for a period of time equal to the "trigger time" setting under Preferences > Cameras > Triggers.

    When you implement this, you may then want to make SecuritySpy v5.3.4 a requirement - you can check the server version via the systemInfo call.

    I hope this does what you want, please let me know your thoughts!
  • Just gave it quick test, and it seems to be exactly what I needed. I will do some more testing later today, and give you feedback. Thanks Ben.
  • Did some more testing, and it works exactly as I had hoped. So thanks for this Ben. Looking forward to official release 5.34
  • Great to hear that!
  • Just found this thread. Super glad there is a Home Assistant integration! I can't wait to try it. @briis, I hope you make the plugin an official integration. Keep up the great work both you and @ben

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!