This is exactly what I’m looking to do, but I’m missing something somewhere.
I am new to all of this running mopidy and snapcast, but have it working with two instances of mopidy pointing to one snapserver and I can choose between the two mopidy instances from each snapclient.
Yay!
Now I’m trying to do what you are saying and figure out how to inject something else into the stream.
I’ve been trying picoTTS from HA and the mopidy instance(s) stop what they were playing, but I don’t hear anything. picoTTS works with other media players.
I know this isn’t what this thread is about and I don’t want to take it off topic, but if you have an example of how you play your door chime maybe I could learn something from it.
Will this work for TTS on HA Host Raspberry Pi audio output jack… as Mopidy ded before it was removed? And I assuming you use the same media_player config.
@danbutter
Sorry for the late reply. Real life has a way to rear its ugly head sometimes…
So, real life example.
My doorbell is a voip device connected using SIP to my Asterisk PBX.
My Asterisk server has a queue which triggers the execution of a bash script.
Said script calls the HA API to execute a HA script.
This is possibly not the best way to do it, but I needed to come up with something fast at the time, as I had enough of OpenHAB, and wanted to switch overnight.
---
doorbell_ring:
alias: Doorbell is ringing
description: The doorbel is rining, play doorbell
sequence:
- service: mopidy.snapshot
data:
entity_id: media_player.figrindan_local
- service: media_player.volume_set
entity_id: media_player.figrindan_local
data:
volume_level: 0.2
- service: media_player.play_media
entity_id: media_player.figrindan_local
data:
media_content_id: http://<my local webserver>/notifications/big_ben.mp3
media_content_type: music
- delay: 00:00:10
- service: mopidy.restore
data:
entity_id: media_player.figrindan_local
...
The real script I took this from has more, but I just copied the relevant parts for mopidy.
So the sequence has 4 steps:
Make a snapshot of what is playing, and all other settings at the time (including volume)
Set the Volume to 20%
Play my Big Ben mp3 which I keep on my local web server (this could be a URI through Mopidy just as well)
Wait for 10 seconds
Restore mopidy to the state it was when creating the snapshot.
It took me a while to understand the playback action does not wait to be completed. It needed to have the delay action to postpone the restore action.
I have no experience with TTS or PicoTTS, as I’ve never ventured into this. But I expect something similar can be achieved with TTS.
If you’re willing to give me more details of your setup (a PM is fine if you value your privacy), I can try to mimic what you have and try to get it working overhere.
@REALogics
I have no clue. I haven’t tested this (yet). If you would care to share your setup, I am willing to give it a shot.
No apologies needed…I try to check in here a few times a week, but really only get any time to play with this stuff on weekends. Thanks for the reply. Makes sense how you are calling the different services in a sequence.
I’ve messed around with the TTS a bit more and can’t get it still. I can get TTS to work by using another media player entity like browser_mod.
The only thing I found that I even suspect is the URI may be off. When I try to send TTS using developers tools - services I can see it in the Iris Now playing section. It gives the address like this:
I’m running HassOS in a VM and my mopidy instances are all on the same network.
Can anyone else type into the text to speak box in the media player card for their mopidy instance and hear it?
Well I figured out why it didn’t work and it was the URL. Since I have a duckdns address the local address that is being sent didn’t resolve. I temporarily changed my internal URL in HA to be that of my duckdns address and TTS to various mopidy instances I have setup started working.
Unfortunately I can’t leave it that way. I am one that like these things to work when the internet is down so this setup can’t be permanent.
I’ll have to do some more searching on how to do TTS when you have duckdns setup. Or reverse proxy…or???
I had a quick look, and shuffle and repeat are supported by my platform.
The default media player card doesn’t seem to offer a button for this functionality, it seems, but mini-media-player does, at least for the shuffle part.
hide:
shuffle: False
If you want to offer a repeat option, you’ll need to create a button and have it execute a service
service: media_player.repeat_set
target:
entity_id: media_player.figrindan_local
data:
repeat: all
replace all with one to repeat the current song, or off to turn off the repeat alltogether.
The shuffle question made me think…is there a way to search? I use the mopidy youtube functionality and don’t see a way to search for anything in HA. I use iris to search now, but if I’m just missing something I’d like to figure it out.
That’s a shortcoming of the media library, unfortunately…
What I could do is create a mopidy-only search service, that can be called.
Arguments for each album, artist, track and source.
And the result of this is sent as a playlist to mopidy.
The downside, is there’s no way I see to make the search ‘dynamic’ and auto-completing like modern-day search engines.
Boy as time goes on and I play with this whole Home Automation hobby I really with I could do some programming. I’ve not got the skills though so I’m afraid I’d not be much for help. I could test, but that is about it.
Thanks again for your work and also for letting me know I didn’t miss anything related to the searching.
only one of the attributes (any, album, …) being required
The result of this would then be added to the existing playing tracklist (if any)
Or maybe I should add another attribute controlling this? ie clear_current_tracklist?
I love the snapshot/restore feature, which I use extensively, as I’m usually playing a a radio stream, which is interrupted by a lot of voice notifications…
But I don’t seem to get a hang of volume setting… does a snapshot also save and restore volume value or should it always be set manually prior snapshot and after restore? If later, is there a way for volume level to be included in a snapshot?
If you scroll up, you can find how I use the snapshot feature, if you didn’t see that already.
Also, make sure you’re running the latest version. It’s been a long time, but I remember committing a couple of updates to the repo when working on the snapshot/restore functionality.
If it stil doesn’t work, could you provide me with your script/whatever used to control snapshot/restore?
Sorry, stupid me, in two of my automations (don’t ask me why) I had command order messed up (volume set to 100% prior to snapshot), therefore it seemed like it’s not working as volume remained 100% after restore - well, I instructed him to do so :). Got it sorted now, works perfectly, thanks anyway :).
Still not quite perfect, one issue is still bugging me. I have an automation, which triggers, if kitchen window is opened more than 15 minutes. When triggered, it runs this script:
If mopidy is playing, when it triggers, it works fine.
But if mopidy is off, when it triggers, I would expect, that it will turn back to off after my TTS is spoken, but it doesn’t. It just plays the last thing from mopidy (that means the last thing, that has been played
before turning it off, whenever it hapened) and at 100% volume level. So basically, something is restored, but not what has been snapshot.
If I understood correctly, the snapshot is made also if it’s off and it should also restore to off state, or not?