@fmon wrote:
This is a followup to my post about installing HA on MacOS here.
Since then I’ve figured out a few fun tricks that leverage the MacOS and its ecosystem, and having benefited from a lot of kind individuals helping me get un-stuck while building my HA, I feel like putting this out there is a way to give back. Some of this may be possible on the venerable Pi, but what I’ll describe here is tailored for Catalina.
- Make HomePods (or any other Airplay speakers) the voice of HA
I was playing around with tts/media player components and then finally realized that using shell commands in HA that call theafplay
andsay
built-in utilities I could do what I wanted. You can even specify the accent and gender of the voice using the- v
flag withsay
. Steps:
- go to system preferences -> accessibility -> speech and download the voices that you want to use.
- put some mp3s in www/sounds/
- Install Airfoil, which I leave running all the time. This lets you use an applescript to connect the desired speakers as needed (see below). One item of note: Airfoil doesn’t currently support HomePod stereo pairs, so it seems to randomly pick one of the two in the pair… please go to Rogue Amoeba’s site and request this feature!
- Use Bonjour browser (now called “Discovery”) or whatever else to find the MAC addresses of your HomePods/speakers.
- Here we’re going to use a bash script to call some AppleScript to control Airfoil (in my case called
connect_homepods.sh
); put it in www/scripts. This will reconnect your speakers if someone, say, connected to them from a phone or something.#!/bin/bash osascript <<EOD tell application "Airfoil" connect to (every speaker whose id starts with "XXXXXXXXXX1") connect to (every speaker whose id starts with "XXXXXXXXXX2") set (volume of every speaker whose id begins with "XX") to 0.4 end tell EOD
- put your commands in
configuration.yaml
like so:shell_command: connect_homepods: "/users/username/.homeassistant/www/scripts/connect_homepods.sh" say_no_moleste: 'say -v paulina "No moleste per favor."' say_panic: 'say -v daniel "Attention. Someone pressed the panic button."' play_woof: 'afplay "/users/username/.homeassistant/www/sounds/woof.mp3"' play_announce: 'afplay "/users/username/.homeassistant/www/sounds/tibetanbowl.mp3"'
- Now put it together in scripts or automations with a slight delay to allow the HomePods to connect- you may have to tailor the timing to your network:
say_morning: sequence: - service: shell_command.connect_homepods - delay: seconds: 0.5 - service: shell_command.play_announce - service: shell_command.say_morning
- Bonus round: put an
input_text
field in lovelace where you can type something and your HA will speak!shell_command: say_this: 'say -v kyoko {{ states ("input_text.say_this") }}'
This automation will run the script any time you hit return after changing the contents of the
input_text
:- id: id 19 alias: say this trigger: - entity_id: input_text.say_this platform: state condition: [] action: - service: script.say_this
- Start playing a Spotify playlist to Airplay speakers with one click. Here I use a different external script to specify a different volume to Airfoil (because Spotify also has a volume setting).
holiday_music: sequence: - service: shell_command.connect_homepods_music - delay: seconds: 0.5 - service: media_player.select_source data: entity_id: media_player.spotify_user source: "mini" - service: media_player.volume_set data: entity_id: media_player.spotify_user volume_level: 0.75 - service: media_player.play_media data: entity_id: media_player.spotify_user media_content_type: playlist media_content_id: "spotify:playlist:37i9dQZF1DX2zhLcnFr1qI" - service: media_player.shuffle_set data: entity_id: media_player.spotify_user shuffle: true
- Leverage external scripts to restart things- call these with shell commands as above
- Restart your Mac (replace with your Mac username and password on the “send” lines). You won’t need to interact with this script.
#!/usr/bin/expect -f set timeout -1 spawn fdesetup authrestart expect "Enter the user name:" send -- "username\r" expect "Enter the password for user \'username\':" send -- "password\r" expect eof
- restart an ASUS router using a key:
#!/bin/bash ssh -i /Users/username/.homeassistant/ssh/asuswrt_key routerusername@192.168.1.1 -p <portyouareusing> 'busybox reboot'
You now have the power to scare intruders with barking dog sounds, get your playlist going with one click, and annoy the bejesus out of your sig other with annoying sounds. Just be aware that a lot of this came about through trial & error, so your mileage may vary. Enjoy!
Posts: 1
Participants: 1