Smart Alarm Audio Notifications

I would just like to question the method used in Smart Alarm to trigger audio notifications?

The only playback method that works on my Samsung M5 speakers is the playTrack method, as shown here:
playTrackAndRestore(https://s3.amazonaws.com/smartapp-media/tts/you_are_now_in_home_mode.mp3, 6, 50)

However audio notifications in Smart Alarm dont seem to run from the same command.
Is there anyway of changing this in the code so that I can make it work with my speakers?

Thanks
Dean

In the current documentation, the “Music Player” capability doesn’t have any of the commands below, but I’ve found that most speakers use them.

  • playSoundAndTrack
  • playTrackAndRestore
  • playTrackAndResume
  • playTextAndResume
  • playTextAndRestore

It looks like the only Music Player command that Smart Alarm supports is playText, but maybe @Gecko can change that?

If you want to customize Smart Alarm for your specific situation, I think if you make the change below to line 1667 of the code found here, you should be able to use it with your speaker.

Old:
settings.audioPlayer*.playText(phrase)

New:
settings.audioPlayer*.playTrackAndRestore(textToSpeech(phrase)?.uri, 6, 50)

In the example above, 6 is the duration and 50 is the volume.

The “correct” way to implement this would be to setup preferences for volume and restore track instead of hardcoding them, but if you just want it to work for yourself, I the above suggestion should be fine.

Edit: Corrected new code.

1 Like

Thank you for this! However - it appears that the command alone does not generate a custom MP3.

I checked Live Logging and I can see the correct command is sent, but its as if its being seen as a speech device and thinks the speaker can recognize plan text… which it cant.

How does one link the custom message to be able to generate custom MP3 files or reference them from the Amazon cloud?

Thanks

Sorry about that, try this:

settings.audioPlayer*.playTrackAndRestore(textToSpeech(phrase)?.uri, 6, 50)

Edit: I just made another minor change to that line.

1 Like

Legend! This worked a charm. Looks like this is the only ability the Samsung speakers have to play sound.

All other speech related functions fail to play.

Something that might be worth note’in @slagle for the Samsung Speaker series integration

I am assuming I am having the same issue as @deano12 because I have the Samsung M7 WAM-750 speakers. I can tell the speakers are getting some kind of signal because the blue LED is blinking however I can’t hear anything as if the volume is off.
I ran into a problem. When I changed the line 1667 like suggested I get this error when I try to save; “There was a problem saving. You probably aren’t logged in anymore.” Yet I just logged in? UPDATE: I used a different browser and I got it to save. Must have been a cache issue. So the good news is it works for me as well on the M7. Thanks @krlaframboise

I am not a programmer. How do I do this the correct way by setting up preferences for volume and restore track? I don’t have a clue where to start. I did a search in the source code for “preferences” and nothing hit so apparently it won’t be as easy as I was hoping. :worried:

The code should really validate to ensure that valid numbers were entered into the settings, but if you make the changes below you’ll at least be able to set the volume and restore track through the settings:

Change line 1667 to:

settings.audioPlayer*.playTrackAndRestore(textToSpeech(phrase)?.uri, settings.audioPlayerRestoreTrack, settings.audioPlayerVolume)

Insert the lines below at line 841:

input "audioPlayerRestoreTrack", "number",
    title: "Enter Restore Track:",
    multiple: false,
    defaultValue: 1,
    required: false
input "audioPlayerVolume", "number",
    title: "Enter Volume:",
    multiple: false,
    defaultValue: 50,
    required: false

Thanks Kevin! That did it! :grinning: I feel like I learned something as well when I moved the modifications up one line so the formatting was more consistent by keeping the “Notify on Alarm” and “Notify on Status Change” together.

Now I feel I am dangerous :astonished: So is there a resource to learn “groovy for dummies” so I can better understand how to modify or read code? I want to read up about your suggestions on validating the entries and see what does Restore Track values mean.

SmartThings has alot of documentation including a section for learning groovy. There are some bugs and it’s lacking in some areas, but it’s gotten a lot better over the last couple of months.
The documentation is located: http://docs.smartthings.com/en/latest/

I went through the documentation at the beginning of the year, but I don’t remember reading anything that would help you with the validation. I probably go overboard or validation, but the easiest thing to do is ensure that the preferences you create have a default value and the number is within range.

For example, see the preferences documentation to learn how to restrict the volume preference to values 1-100.

Once you become more familiar with Groovy and you want to play the notification at the same volume that the device is already set to, you can get use the volume preference as a fallback and attempt to play it using the same volume that the device is already set to. The Music Player device should have the level attribute so you would just pass that into the function instead. It’s more complex than that, but it’s basically all it does.

Restore Track isn’t related to Groovy. I think the speaker allows you to pass in a track that can be restored to a specific spot after the message is played, but I don’t have a speaker so that’s just a guess.

1 Like