TTS help based on variable


#1

1) Give a description of the problem
I have a list of devices that check battery level. It sends push notification for each device but TTS only reads 1 device name
(The variable names and phrases do not match the values as i had to change battery level to >/= 70 for testing purposes).

2) What is the expected behaviour?
I want the TTS to say all the names of the devices with batteries within range set by the variable.

3) What is happening/not happening?
The piston runs as expected and sends push notifications for each individual device within range but the TTS via alexa only reads 1 device name despite multiple devices being in range

**4) Post a Green Snapshot of the piston!

5) Attach logs after turning logging level to Full

*edited for additional question: Is there a device limit for the deviceList variable?


#2

Not an answer, but you might look into Simple Device Viewer https://community.smartthings.com/t/release-simple-device-viewer/42481. Here is what I get…


#4

You are using a loop, so Alexa ends up getting spammed, and ignoring the 2nd and 3rd commands.

I would likely store the device names into a string variable, and then, outside of the loop, send a single command to Alexa using that string.


#5

While I understand what you’re saying, I don"t know how to write that. To be honest, it took me a couple hours of trial and error and referencing example pistons to get this to work! Can you explain further how to write that please? Or point me to some simple examples? Thanks :blush:

I don’t know if it makes a difference or not my my integer will eventually be set to </= 27% so it shouldn’t have to say a long list of devices at once (hopefully!)


#6

My apologies… I only program loops for clients that insist on it…
but the general idea is something like this:

define
    string lowDevices (no value set)
end define

execute
    IF some trigger happens
    Then
        Set variable {lowDevices} to " "     <-- this clears the old data
        Begin loop
            Set variable {lowDevices} to {lowDevices} + $device    
        Emd loop
        Make a GET request to blah.blah.blah/longUrl&lowDevices
    END IF
end execute

#7

Well…I definitely did not do something right. The tts now lists “empty device list” 3 times


#8

I am open to any better solutions. I am not set on using loops


#9

Yes… You are forcing (setting) that variable on line 20… Long before line 21 is cleared… and long before line 21 is reset.

IE: Remove the hard coding on line 20, and set that variable inside the piston after the loop, and before the GET request.


Pro Tip:

Whenever you have a variable that you wish to be able to change, then up top in the define section should say (no value set)


#10

I have a similar piston. I just save matching devices into another device variable and send the message using that. See below. Note that you only need half my piston below as I have two threads, one on a timer and one when I turn on a virtual switch. You can take your pick but the logic is fairly simple.

One other tip: If you store your URL in a global variable and just use that in your piston, you won’t have to worry about blocking it out when you post for help.


#11

@WCmore thank you. I will look at this later today and let you know it i fixed it.

@guxdude 3 questions

  1. I tried adding a global variable with the url but it kept returning not set
  2. If i use a global variable, do I include the custom phrase in the global or somehow add it after?
  3. Can you provide steps for adding url as global variable?

#12

For the global variable, here is what you need to do:

  1. while editing the piston, click on “+add new global variable”
  2. select type as string and insert a name (e.g., monkeyURL)
  3. For value, put in your URL string. I suggest including everything up to ‘announcement=’ as you have above
  4. In your piston for the GET request use the expression box and just enter (using example name above):
    @monkeyURL ttsMessage

The strings will be concatenated and should work fine. Additional advantage is you can use the global variable in any piston in the future to send messages.


#13

@guxdude Thank you so much!


#14

Thank you for the help. It now works.
To expand on this, I was wanting to use a variable deviceName (to use shorter names) when sending sms/push/tts messages.
Example
device deviceList ■■■, YYY, ZZZ
device deviceName X,Y,Z
string lowDevices (no value set)

I can not figure out how to write this.
I tried
IF trigger happens
for each $device in {deviceList}
set variable {lowDevices} = {lowDevices},{deviceName} + $devices

But that didn’t work. I found a lot of examples but no actual explanations of how to write this. Any suggestions or links to learn from (for someone with minimal coding knowledge) is much appreciated!


#15

I am tied up at the moment… Hopefully someone else can jump in…