Logitech Media Server TTS Notify Queue

The LMS Notify TTS platform lets you use the TTS integration Service Say and a LMS media_player to alert you of important events. This integration provides a simple interface to use in your automations and alerts.

  • restores the state, volume, sync group, playlist and media position after playing the notify message
  • queue messages for each player so new messages do not interrupt the current playing one
  • option alert sound before the message
  • option how many times to repeat the tts message
  • option volume for the tts message

Default options can be set in the configuration file or overridden with each message

9 Likes

This is great, exactly what I was looking for! Thanks for your work.

Installed and running without a hitch other than forgetting to set the device_group. Maybe this could be optional? I plan to announce a warning throughout the house when the alarm is triggered to give a visitor time to disarm it before the siren goes off, in which case no entity would be set to ‘home’.

Also playback always resumes at the start of the song rather than picking up where it left off. Is that a bug?

You can use the option force_play to skip the check if the device group is set to home

Playback where left of is a bug and will be fixed in the next update
This is only going to be enabled for players not in an sync group because with me the players are out of sync when I use it
You can try if you experience the same problem by uncommenting line 174 in init.py:
#self.restore_media_possition(player)

I tried the component but I get an error after the message was played and the component tries to resync the players. The media_player in the error message is not the player used for the TTS but it is synced with it.

2021-07-16 16:45:48 ERROR (Coordinator) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/config/custom_components/lms_tts_notify/__init__.py", line 143, in run
    if self.check_done():
  File "/config/custom_components/lms_tts_notify/__init__.py", line 171, in check_done
    if self._queue_listener[player].state_save['state'] == 'playing':
KeyError: 'media_player.radio_kueche'

Also I got an error when I left out the volume for the notify configuration.

For now the best thing is configure every LMS player.
I have some partial code to auto configure all LMS players but do not know when I’ll have the time to finish it

        entity_registry = hass.helpers.entity_registry.async_get_registry()
        lms_players = {}
        for entity_id in hass.states.async_entity_ids():
            entity_domain = entity_id.split('.')[0]
            if entity_domain == 'media_player':
                if entity_registry.async_get(entity_id).platform == 'squeezebox':
                    lms_players[entity_id] = entity_registry.async_get(entity_id).platform

this is fixed in the latest update

Great. Now the component works without any problems.

Works great (also with Google Cloud TTS). However, I notice this component conflicts if you have ‘replay playlist’ as default. It will replay the message non-stop. Since I always use ‘replay playlist’, is there a way to have the action in this component that saves states, also saves repeat state, then:
turns off repeat > send message> and then restore all states including repeat state?

Also somehow it doesn’t restore the media position, but starts the song over again. (ninja edit, I see now: Playback where left of is a bug and will be fixed in the next update)

One last thing: would it be possible for the non-targeted players to keep playing and just re-sync the targeted player? So if all players that are playing are targeted, they just resume where they left off. But if you target player A in a group of 3, then B and C should keep playing. After the message player A should just resync to the group. Currently when targeting a player inside a synced group, all players will stop when the targeted player plays a message.

Playback where left of is only for players not in a sync group because when I try it with players in a sync group they are not in sync anymore
uncomment line 175 #self.restore_media_possition(player) and try if you have the same

Non targeted players in a sync group that stop playing I already noticed but it is not consistent, I do only unsync targeted players and not the whole sync group

Forgot about the replay option because I never use it, looking in to it I see that media_player.repeat_set service is not working with the squeezebox integration

I believe Squeezebox integration needs to use the service call_query. According to the page, this would be the CLI command:

<playerid> playlist repeat <0|1|2|?|>

The "playlist repeat" command is used to indicate or query if the player will stop playing at the end of the playlist, repeat the current song indefinitely, or repeat the current playlist indefinitely. A value of "0" indicates that the player will stop at the end of the playlist, "1" indicates that the player will repeat the current song indefinitely and a value of "2" indicates that the player will repeat the entire playlist indefinitely. Used with no parameter, the command toggles the repeat state.

Example:

Request: "04:20:00:12:23:45 playlist repeat ?<LF>"
Response: "04:20:00:12:23:45 playlist repeat 2<LF>"

Request: "04:20:00:12:23:45 playlist repeat 0<LF>"
Response: "04:20:00:12:23:45 playlist repeat 0<LF>"

Though if I’m being honest, I have never used query commands and this all looks abracadabra to me at the moment lol.

edit: you can use a service call_method and use this as a service call:

service: squeezebox.call_method
data:
  parameters:
    - repeat
    - 'off'
  command: playlist
target:
  entity_id: media_player.kantoor_lms

Might be easier for me to just use a Node-RED flow for this.

latest release turns of repeat and restores the setting

1 Like

works great!

What parameter do you use to unsync a target player? I notice that when I use squeezebox service call to unsync a player, there is no interruption and the group continues te play.

service: squeezebox.unsync
target:
  entity_id: media_player.tv

This works great for me apart from the same problem I’ve always had with TTS on LMS: It does not resume playing after the announcement. I have tried it with a playlist, or a radio station and it fails every time.

I’m running Logitech Media Server Version: 8.1.2. Any ideas?

Thanks.

What does the log show?
What is the content of the playlist "Save-media_player.[LMSPlayerName] "? the items playing before the tts message?

logger:
  default: warn
  logs:
    custom_components.lms_tts_notify: debug

I am running 8.1.1 in docker: Docker Hub and never seen your problem

I’m running LMS in docker as well, although on a separate server. Where do I find the "Save-media_player.[LMSPlayerName] " playlist? Here’s the logs:

2021-07-23 11:23:30 DEBUG (MainThread) [custom_components.lms_tts_notify] Received on event bus: {'entity_id': 'media_player.kitchen_radio', 'message': 'Test', 'volume': 0.8, 'device_group': 'person.pat'}
2021-07-23 11:23:30 DEBUG (Coordinator) [custom_components.lms_tts_notify] Save state: media_player.kitchen_radio -> {'state': 'playing', 'attributes': {'volume_level': 0.5, 'sync_group': [], 'media_position': 21, 'repeat': '0'}}
2021-07-23 11:23:30 DEBUG (Coordinator) [custom_components.lms_tts_notify] Save state: media_player.bedroom_radio -> {'state': 'idle', 'attributes': {'volume_level': 0.2, 'sync_group': [], 'repeat': '1'}}
2021-07-23 11:23:30 DEBUG (Coordinator) [custom_components.lms_tts_notify] Save playlists: media_player.kitchen_radio
2021-07-23 11:23:30 DEBUG (Coordinator) [custom_components.lms_tts_notify] Save playlists: media_player.bedroom_radio
2021-07-23 11:23:30 DEBUG (Coordinator) [custom_components.lms_tts_notify] UnSync media_player.kitchen_radio
2021-07-23 11:23:30 INFO (MainThread) [pysqueezebox.server] Query run on unknown player 00:04:20:1f:00:6f
2021-07-23 11:23:30 INFO (MainThread) [pysqueezebox.server] Query run on unknown player 00:04:20:26:26:ae
2021-07-23 11:23:31 DEBUG (kitchen_radio_queue) [custom_components.lms_tts_notify] Playing message 'Test' 
2021-07-23 11:23:33 DEBUG (kitchen_radio_queue) [custom_components.lms_tts_notify] Waiting for media_player.kitchen_radio to finish
2021-07-23 11:23:33 DEBUG (Coordinator) [custom_components.lms_tts_notify] Restore volume: media_player.kitchen_radio
2021-07-23 11:23:33 DEBUG (Coordinator) [custom_components.lms_tts_notify] Restore state: media_player.kitchen_radio -> {'state': 'playing', 'attributes': {'volume_level': 0.5, 'sync_group': [], 'media_position': 21, 'repeat': '0'}} 
2021-07-23 11:23:33 DEBUG (Coordinator) [custom_components.lms_tts_notify]  Restore playlist: media_player.kitchen_radio
2021-07-23 11:23:33 DEBUG (Coordinator) [custom_components.lms_tts_notify] Restore media_possition: media_player.kitchen_radio
2021-07-23 11:23:33 DEBUG (Coordinator) [custom_components.lms_tts_notify] Players all done: {'media_player.kitchen_radio'}

As a side note, Restore media_possition has an extra “s”.

Look in the LMS interface → Playlists → “Save-media_player.kitchen_radio” and it should contain what was playing before the tts message

I also have LMS docker running on a separate system

The Playlist folder was empty, but I was also getting an error in the LMS logs - bad server config. I realised that it wasn’t able to access the playlist folder, despite the docker-compose.yml entry being correct.
That led me to the LMS Server setting under Basic Settings. The entry there for the Playlists Folder was empty! Setting this to /playlist fixed the problem and now it works perfectly!
Many thanks for your help!

I have a feature request if you have the time (or perhaps you can think of another solution).

I have two networks, the first is for laptops, phones etc and the second is isolated so that my cameras and smart devices can’t access the internet or be accessed directly. My home assistant server can access both of these networks and has a different IP for each.

My LMS and Squeezelite players are on the isolated network and can be accessed by home assistant but when I use the LMS TTS notify queue, the playlist entry for the tts mp3 points to the IP of home assistant on the main network, not the IP of home assistant on the isolated network, so LMS can’t access the mp3 to play it.

My suggestion is an optional setting to specify the home assistant IP/hostname used when adding a tts entry in the LMS playlist. Alternatively, an even nicer solution would be to specify the network adapter to use and pick up the IP/hostname from the HA configuration.

TLDR, I’m getting this:
http://192.168.10.108:8123/api/tts_proxy/xyz_google_cloud.mp3

I’d like to get this:
http://192.168.1.108:8123/api/tts_proxy/xyz_google_cloud.mp3

Hi Floris,

This is great! Now running Sonos, Nest and my ancient SB Radios on LMS. It is probably my yaml capabilities but how to ensure that I can tts multiple mediaplayers at once? Below is not working.

Thanks!

    - platform: lms_tts_notify
      name: woonkamer
      tts_service: tts.google_say
      media_player:
      - media_player.sonos_zitkamer_lms
      - media_player.sonos_...
      device_group: group.all_persons