How to send random text messages from a list


#1

1) Give a description of the problem
I want to send prewritten, randomly selected SMS messages to my phone to give me or my wife information, but not always stated in the exact same way. (i.e. - See ya!; Goodbye!; Take it easy!; etc…)

2) What is the expected behavior?
When me or my wife leave the house, i want to see a variety of different texts that I have added to the piston and have the piston randomly select a text to fire.

3) What is happening/not happening?
Nothing because I have no idea where to begin

Any help would be appreciated! Im sure it a rather simple thing, but I have no idea where to begin. I already have a goodbye piston set up. I just want to add a group of separated text messages to it to be sent at random.


#2

There’s the random() function you can use. Select Expression instead of Value when entering your messages.

random(“message 1”,“message 2”,“message 3”)

Reference: https://wiki.webcore.co/Functions


#3

Thanks! I will give that a shot!


#4

Is there another way to do this? The expression stops letting me add txt after a certain point. I may not be doing it right either… I dunno.


#5

Try composing it in notepad and pasting it in when you’re done.


#6

Never mind, ill sift through examples and hopefully find something there.


#7

Thanks! I will try this with my Arrival piston.


#8

If I want to use random() with a web request such as this http://192.168.1.100:5005/sayall/Hello/50 and have multiple sayings like this only different, how do I enter it into the brackets of random? I tried wrapping quotes around each one but that gave me an error when the piston tried to read it. Should they be wrapped in {}?


#9

Is the URL random one? Sorry, a little slow, on mobile.

Edit: I tried this and it worked. random(“http://www.url1.com”,“http://www.url2.com”,“http://www.url3.com”,“http://www.url4.com”)


#10

The url is to have the speech go through my sonos setup on my unraid server with a docker. When I set it up the way you have it, webCore gave an error. This is the error:

║Error executing virtual command [].httpRequest: (10ms) java.lang.NullPointerException: Cannot invoke method replace() on null object


#11

Ah I just tested it with random() in the console and didn’t do the actual web request. I don’t have a sonos to test it on.


#12

It does seem to work but it won’t accept any variables. ie: {whoCameHome}


#13

Yep, you’re right about the variables within the random(). I thought someone came up with a workaround on that but I don’t remember where I’ve seen it. Maybe one of the more skilled @webCoRE_Minions can chime in.


#14

heres an example of combining random and variables:


#15

Thank you! That’s where I saw it before but didn’t bookmark it. I had pistons where I wanted to do that before but just gave up on it and have not updated it since.


#16

So you know the Arrival piston that you created for me, would I be able to incorporate the whoCameHome variable into random statements? It doesn’t seem to work when I put them in the statement.


#17

Should work. Will take a look later today. Please post a snapshot if you have a modified version of what’s not working.


#18

Here is the piston right now. I was trying to have greetings based on {whoCameHome}. But the random() doesn’t seem to like having a variable in it. Also, I might have messed something up because now when someone leaves it is also triggering this arrival piston. I think it is because the Contact Sensor is always Closed.


#19

I have this piston and something similar setup for departures based on this one. But both are using the Contact Sensor is closed but the departure uses the presence sensor changes to not present and this one uses the presence sensor changes to present. Yet they are both firing when someone leaves.


#20

ok. should we go back to the original and start from there then? if yes, please post:

  1. the post with the original piston if you have a link to it. otherwise i will search thru my history to find it.
  2. the messages as text so i dont have to hand type those in.

thanks.

sorry didnt see this till now … somehow did not get a notification. the reply button on the post notifies the poster there is a response but the reply button on the thread does not. :slight_smile: