I have posted about this in a couple of threads and have been asked if I would share my method. To be clear, I am not proficient at scripting. While the design and methodology are all of my making, I couldn't have built the script without substantial help from my brother GPrade He has given me permission to share his work.
The goal was to be able to send announcements to selected Sonos speakers and to vary the level of these announcements based on priority. There a variety of situations where a single Linkgroup will not work
The first step was two sets of virtual devices to set announcement levels and client enable. The announcement Level devices allow me to fine tune levels for each client otr to mute them for all announcements. I also control the Level devices on certain clients based upon activities, such as watching TV.
The Enable Devices allow me to monitor a clients online status as well as the ability to temporarily mute a client that is online.
I grouped these devices using Jon00's Device Grouping web page to keep them together.
Then I control the enable devices with Events. These are designed to track the Sonos clients with UltraMon conditions and with a 10 second delay to allow temporary manual overrides.
Then I have 3 global devices to 1) vary the amount the level is boosted for alerts, 2) to allow Events to determine if an announcement is active and 3) to store the last announcement text and time. The last device allows me to ask for an announcement to be repeated through an Echo request.
I control the Announcement Active device with a pair of Events that monitor my two Linkgroups.
The ANNOUNCE Linkgroup is the one I control dynamically and the NOCLIENT Linkgroup is for any hs.speak Actions that are not handled by the script.
I also have an Event called by the script that can be used for any pre-announcement needs. This one will also set the Announcement Active device.
In designing the script, I considered passing the text to be spoken as a parameter, but instead decided to use a tagged entry in an .ini file. I also wanted to pass a level override to the script to be used instead of the Adder Virtual Device. While the Adder Device and parameter are designed to add globally to every announcement level, negative numbers can be used to reduce levels if needed. The tagged entry in the ini file has a boolean value as to using the Adder Virtual Device. If an Adder is passed as a parameter, it overrides the setting of the virtual device. The end result is that I pass two parameters, the tag for the announcement text and a level modifier number (if desired). The script could be modified to pass the text as a parameter if desired, but I preferred to keep it all in a configuration file.
The Sonos configuration file contains the Linkgroup structures including the Destination Player, Volume, Mute Override and whether the Player is included in the linkgroup. All Player's UDNs are included in this entry. The config file entry for any Linkgroup can be written by a plug-in function
The script is used to build the linkgroup and write it to the .ini file, then send the TTS string to the Linkgroup. As I wrote above I use two linkgroups - NOCLIENT is used for general hs.speak TTS that is sent to all clients instead of being handled by the script. It is set manually through the Sonos Configuration page. ANNOUNCE is the Linkgroup used by the script and is assembled dynamically by the script..
The goal was to be able to send announcements to selected Sonos speakers and to vary the level of these announcements based on priority. There a variety of situations where a single Linkgroup will not work
- When my wife works at home, she doesn't want announcements in her office
- I power down some clients when they are not used and I don't want to send announcements to devices that are offline
- There are a number of clients that may be online but will not always be used for announcements
- We want alerts to be at a higher level than announcements with the ability to vary this increase in level
The first step was two sets of virtual devices to set announcement levels and client enable. The announcement Level devices allow me to fine tune levels for each client otr to mute them for all announcements. I also control the Level devices on certain clients based upon activities, such as watching TV.
The Enable Devices allow me to monitor a clients online status as well as the ability to temporarily mute a client that is online.
I grouped these devices using Jon00's Device Grouping web page to keep them together.
Then I control the enable devices with Events. These are designed to track the Sonos clients with UltraMon conditions and with a 10 second delay to allow temporary manual overrides.
Then I have 3 global devices to 1) vary the amount the level is boosted for alerts, 2) to allow Events to determine if an announcement is active and 3) to store the last announcement text and time. The last device allows me to ask for an announcement to be repeated through an Echo request.
I control the Announcement Active device with a pair of Events that monitor my two Linkgroups.
The ANNOUNCE Linkgroup is the one I control dynamically and the NOCLIENT Linkgroup is for any hs.speak Actions that are not handled by the script.
I also have an Event called by the script that can be used for any pre-announcement needs. This one will also set the Announcement Active device.
In designing the script, I considered passing the text to be spoken as a parameter, but instead decided to use a tagged entry in an .ini file. I also wanted to pass a level override to the script to be used instead of the Adder Virtual Device. While the Adder Device and parameter are designed to add globally to every announcement level, negative numbers can be used to reduce levels if needed. The tagged entry in the ini file has a boolean value as to using the Adder Virtual Device. If an Adder is passed as a parameter, it overrides the setting of the virtual device. The end result is that I pass two parameters, the tag for the announcement text and a level modifier number (if desired). The script could be modified to pass the text as a parameter if desired, but I preferred to keep it all in a configuration file.
The Sonos configuration file contains the Linkgroup structures including the Destination Player, Volume, Mute Override and whether the Player is included in the linkgroup. All Player's UDNs are included in this entry. The config file entry for any Linkgroup can be written by a plug-in function
Code:
hs.PluginFunction("Sonos", "", "SetLinkgroupZoneDestination", {"LINKGROUP", String})
Comment