HomeHelper - Action to activate Scenes?
Comments
-
as an aside to this, I've discovered the script possibilities under the actions tab. that's pretty slick that you can create message the plays in spoken word from the computer. wonder if there's a way to airplay that message, and customize it such that "There is a X detected from Y camera" where x is the AI model triggered and Y is the name of the camera. That would be pretty sweet!
-
Unfortunately, HomeKit scenes are only available via Apple's Home app - Apple have not provided an API to access these (the same goes for automations).
I like your idea of triggering speech/sounds in AirPlay speakers. After some research it seems that this should be possible using the Airfoil app. It's a really nice app to synchronise playback across multiple speakers, and it also has a comprehensive AppleScript dictionary that should allow you to achieve what you want. Basically you would tell Airfoil to connect to a particular speaker, then you would use the "say" command to get AppleScript to speak some text.
If you try this, please report back and let us know how well it works. -
Thanks. I'll see if there's a way to selectively (programmatically) send audio to AirPods. wouldn't want all audio from the machine sent all the time.
Alternatively (and maybe easier), if this isn't possible via API, is to create dummy switches in HomeBridge, setup of actions pointing to those switches, and set scenes in HK on activation of those dummy switches. -
Sending alerts to an airplay speaker was one of my main requirements for a home surveillance system. I wanted to have something wake me up if someone was approaching the house in the middle of the night (we're pretty isolated so nobody should be around at night).
I'm happy to report that Ben's suggestion with the Airfoil app works great. I didn't use the "Say" command though because I found the voice was too weird. I ended up making audio files from a text to speech website that had very realistic speech and then added a chime on the beginning and end of the file. I have one audio file for each camera so it lets me know where the person or vehicle was detected. So far I haven't been woken up with a false positive alert, but I may consider raising the Actions AI trigger threshold if I do start getting them. Also, the whole sequence is very fast. I would estimate the alert is sounded within 2-3 seconds of a person being identified in the camera.
Here is the script I used to achieve my results (I am not a coder so there are probably better ways to do it, but this seems to work well for me).
tell application "Airfoil"
set aSource to first system source
set current audio source to aSource
connect to speaker "SPEAKER NAME" -your Airplay speaker name
set (volume of speaker "SPEAKER NAME") to 0.6 -this is adjustable from 0-1 so adjust it to however loud you want the alert to be
end tell
delay 0.5 -I needed the delays because the sound would begin playing over the computer speakers before the airplay speaker was fully connected. You may need to adjust the delay for your use.
do shell script "afplay /Users/path/path/path/audiofile.m4a" -this is the path to your audio file. the file name here has to be one word, no spaces. This drove me crazy for quite a while.
delay 5
tell application "Airfoil"
disconnect from speaker "SPEAKER NAME"
end tell
What I would like to be able to do now is have more control over the actions tab. With this script loaded into the actions tab for each camera, I would get alerts through the speaker every time the AI actions is triggered. I created a schedule preset so that the actions are now armed from 10 pm to 7 am so I only get the alerts at night, which is what I desired. What I found though is that the notifications in the iOS app are gone during the day. It would be nice to separate the App notifications from other actions such as this script. I would like to still have the app notifications during the day.
I hope this helps anyone else trying to get security spy to notify you through an airplay speaker or HomePod.
-
This is great! Many thanks for posting this script, it's a neat solution and I hope this will be useful for others.
At the moment, all Actions for each camera share the same schedule. I understand that sometimes this isn't flexible enough for more complex setups, but this is the situation at the moment. What you could do to achieve what you want is add an initial time check in your script so that it will exit quietly during the times that you won't want it to operate.
-
I just wanted to add that this was incredibly useful for setting up sound activation based on AI detection on my doorbell. Thanks for devising this solution and script!
I was able to separate out the push notifications and HomeKit/scripts by duplicating the cameras, per https://www.bensoftware.com/forum/discussion/4094/schedule-for-homekit-actions.
SecuritySpy has been my greatest software find this year. It just works and has really improved my security setup. Thanks!
-
Great to hear that @mindboggle - so glad that SecuritySpy has been working so well for you!
-
Adding a quick update on this thread as I've found Airfoil and Homepods are not playing nice. What's happening is that sometimes (not always), Airfoil doesn't switch the speaker source, so alerts play on my computer. I can live with this for a motion chime during the day, but for security at night, I want something reliable.
I've found a better solution is to use an alarm plugged into a smart outlet triggered by HomeHelper. For anyone interested, this is what you need:
Alarm/light: https://www.amazon.com/Wired-Strobe-Siren-Light-Sound/dp/B079KZNFF2/
Transformer: https://www.amazon.com/100-240V-Transformers-Switching-Applications-Connectors/dp/B077PW5JC3/
Smart outlet (I've had good luck with Meross): https://www.amazon.com/Reliable-Support-HomeKit-Assistant-Control/dp/B084JML1WN/
Then just use HomeHelper to create an action that turns on the outlet. I like this solution because the sound/light is similar to a fire alarm and it's cheap, so you can deploy a couple of these without having to purchase multiple Homepods.
Hope this is helpful!
-
Just a quick update after a few years of using this setup with Airfoil and HomePods; I have found this setup to be much more reliable now. There was a period of time that I had issues with airfoil failing to connect to the HomePod as commanded in the script, similar to what mindboggle described above, but for the past 6+ months, I have had no issues. I believe they have fixed an issue through a software update that was causing those problems previously. I have updated the script slightly to include a time check like Ben suggested. So now my actions can become enabled at sunset and I will get the notification on my phone, but I won't receive a notification through the speaker until 9 pm. I also removed the disconnect portion of the script at the end and just leave airfoil connected to the speaker continuously. I did this when I was troubleshooting the airfoil issues a while back, but figured I'd just leave it for redundancy when airfoil needs to connect. I haven't had any issues when I use the speaker from another source either; Airfoil will connect reliably and kick the previous source off the speaker. Here's the updated script for those who have tried this setup:
set rightNow to (get current date)
set hoursNow to hours of rightNow
if (hoursNow > 20) or (hoursNow < 7) then
tell application "Airfoil"
connect to speaker "homepod01"
set aSource to first system source
set current audio source to aSource
set (volume of speaker "homepod01") to 0.6
end tell
delay 0.8
do shell script "afplay /Users/mac-mini/SecuritySpy/Sounds/drivewayperson.m4a"
end if
