webCore - Randomize announcements?

webcore

(Bryan) #1

Was wondering if there was a way to randomize announcements when using webCore. Would make everything much more entertaining and keep things fresh. Also, if the same things are said over and over people tend to not listen/notice them anymore but change it up and everyone is “what did she just say!?”.

Anyway, here is an example of what I would like to do…is it possible?

BUT instead of it just saying Speak text “Dryer is finished!”, it would have something like…

Speak text (Randomize);
“Dryer is finished”;
“Hot clothes, get them while their hot”;
“Stop the wrinkles, get the clothes now”;
end randomize;

I’m NO programmer so maybe it can already do this and I just don’t know how! lol

Any ideas? @ady624

Thanks


(Jon) #2

Could be done like this

You can use code to import then just change devices and phrases

the variable could be anything from 0 to 9 so you could have 9 different phrases if you want, or as i have done for speed set a range for each phrase


( I hate Mondays) #3

Unfortunately, there is was no easy way. I’ve just added the random() function, so please upgrade to version 0a2 first, then use this:

Syntax:

random([range | value1, value2[, ..,valueN]])

when no parameters are provided, a random decimal between 0 and 1 is returned.
when one parameter is provided, it acts as a range, so an integer between 0 and that number is returned
when at least two parameters are provided, it returns one of the parameters, randomly selected

So use your Speak task, for the text choose an Expression instead of the default Value, and type this in there:

random("Dryer is finished", "Hot clothes, get them while their hot", "Stop the wrinkles, get the clothes now")

You can add as many comma separated parameters, you’ll always get one of them. The parameters can be expressions themselves too…

random(“Dryer is finished”, “Hot clothes, get them while their hot”, "The average temperature is " + avg([Sensors:temperature]), “Stop the wrinkles, get the clothes before {$now + 60000}”, random(‘test’, ‘fireworks’, ‘college’))

Documentation here: https://wiki.webcore.co/Functions#random

Later edit: @Jonpho’s solution above is a very creative (and correct) way of doing the same thing. The random() function did not exist, so he found a way around it. Use any one you like, though the random() function should be much better performance-wise. Thank you for providing a good idea.


(Bryan) #4

Thanks guys for some great ways of doing this! I’ll try them later on today…got to go to Patriot’s Place (Gillette Stadium) to do some shopping today with the family. Early Mother’s Day stuff. :wink:


( I hate Mondays) #5

Go Pats :wink:


(Bob) #6

When you have this working would you mind posting so people (me :wink:) can import and use?
I have something in mind and this could be useful.
Thanks.


(Bryan) #7

Well, not having much luck with this. It seems to run (see logs below) but I don’t hear anything. Any NEW pistons that I try to setup with Speak, nothing comes out of the Sonos. If I run an old (unmodified) piston with speech, it plays out of the Sonos. Wierd.

New Test Piston:


Old Piston that works fine (only modified the time so it would run):



(Bryan) #8

Could someone try to setup a brand new piston with speech and see if it works for them? Just want to see if it’s just my system or not.

Thanks!


(Bob) #9

I tried your piston using speak text and it does not work for me either.
If I change to speak text and resume, it does work.
Could you use this instead?


( I hate Mondays) #10

I was requested to add volume to all three commands - that explains the old vs new pistons - if you edit an old one, it will stop working too. Looks like Sonos does not accept a volume parameter for playText? Any errors in the IDE, for either webCoRE or the Sonos player? The Audio Notification capability has been modified over and over again by ST, it looks like the implementation of Sonos no longer matches the documentation :smiley:

@SBDOBRESCU

http://docs.smartthings.com/en/latest/capabilities-reference.html#audio-notification


(Bobby) #11

I think it still does…

New Piston cannot have “null” volume …

Old Piston works because the volume is not defined

If you go in the new piston and set a volume, your piston should work fine

UPDATE!!!


@ady624 is correct! The playText() command NO LONGER takes the optional NUMBER level argument as noted in the Documentation. Only playTextAndResume() and playTextAndRestore() …

@Jim ?!?



(Jon) #12

Should the ‘optional’ be removed then??


(Bryan) #13

Thanks for working on this guys. Thought I was going nuts there for a little bit. Using “speak text and resume” works great. Now to go through all my speech pistons and randomize everything! Got to keep the family on their toes.

Thanks again.


( I hate Mondays) #14

@Jim any input please? Should playText have a volume parameter (like documentation suggests) or not (like Sonos is implemented)?

Thank you


(Ed) #15

Here is how I do random text. I have a bit more extensive one in CoRE that I haven’t brought over yet but it’s the same idea. Use a switch block with a random variable to select the different cases at random


( I hate Mondays) #16

That is old school. Check out the random() function above


(Bryan) #17

Here a working example of the new Randomize. Hope this helps.

The piston:

An exploded view of the speech:


(Jim Anderson) #18

Which capability are we referring to? Audio Notification supports the playText() command, which takes a required string message, and an optional Number volume argument. But I’m not seeing Sonos implement that capability.


(Bobby) #19

Look at the error in this post. The optional number for volume doesn’t appear to be valid. Or am I interpreting the error wrong?

playText(string) …


(Bobby) #20

The Sonos handler has the following capabilities:

[on, off, refresh, play, pause, stop, nextTrack, playTrack, setLevel, mute, previousTrack, unmute, setTrack, resumeTrack, restoreTrack, ping, playText, playTextAndResume, playTextAndRestore, playTrack, playTrackAndResume, playTrackAndRestore, subscribe, getVolume, getCurrentMedia, getCurrentStatus, seek, unsubscribe, setLocalLevel, tileSetLevel, playTrackAtVolume, playTrackAndResume, playTextAndResume, playTrackAndRestore, playTextAndRestore, playSoundAndTrack]

If playText is used, produces this error …