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 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!!
Comments
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:
http://ss-server-address:8000/++video?cameraNum=0
(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.
switch:
- platform: command_line
switches:
camera_arm:
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:).*"'
value_template: '{{ value == "ARMED" }}'
where {ip} = my camera IP address and {authkey} = my authentication. Ignore the </br> 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
C:DISARMED
M:DISARMED
A:DISARMED
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.
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.
Has anyone made any more progress on this?
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?
https://gist.github.com/boxgr0ve/a0dc40e954b5eb2b703dcda796aea098
automation.yaml (hass)
https://gist.github.com/boxgr0ve/b74699e680cf70f4e823c1501be1fd9d
trigger_motion_capture_scpt (Mac)
https://gist.github.com/boxgr0ve/81973b8b14df2609c8fecc1b5df75207
Hopefully self explanatory ....
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.
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.
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.
Also I have the Streamdeck XL for a physical controller. I posted this solution in a earlier thread. give it a search.
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
trigger:
- 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'
action:
- 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....
driveway_motion:
sequence:
- service: scene.create
data_template:
scene_id: before
snapshot_entities:
- light.wled_desk
- service: light.turn_on
data:
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
data:
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.
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
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
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
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 \"\" \"http://192.168.1.79:8123/api/webhook/driveway_ss_trigger_1\""
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
https://www.home-assistant.io/integrations/logger/
do shell script "curl -d '' http://192.168.1.10:8123/api/webhook/kiosk_doorcam_motion"
do shell script "curl -d \"\" \"http://192.168.1.79:8123/api/webhook/driveway_ss_trigger_1""
do shell script "curl -d \"\" \"http://192.168.1.79:8123/api/webhook/front_porch_ss_trigger_1""
do shell script "curl -d \"\" \"http://192.168.1.79:8123/api/webhook/back_porch_ss_trigger_1""
do shell script "curl -d \"\" \"http://192.168.1.79:8123/api/webhook/garage_ss_trigger_1""
, 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...
logger:
default: warning
logs:
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?