Using Alexa TTS to Announce Opening of Alarm Zone

I’m on vacation at the moment, and won’t be home until mid-week.

The gist of what you want to study is this:

  1. Let’s say you make an expression variable called sensors that contains an array of the sensors you want to monitor: list(31,44,127,212)
  2. You can use this with the iterate() expression function to make an array of tripped sensors in tripped_sensors = iterate( sensors, if( getstate( _, "urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped") == "1", _, null ) )
  3. You can make an array of the names of those sensors in tripped_names with iterate( tripped_sensors, getattribute( _, "name" ) )
  4. You can make a text message out of that with "Alert Zones " + join( tripped_names, ", " ) [note there is a space after the comma inside the second parameter to join()]

You can then send that string to your TTS if the number of tripped sensors > 0. Then len() function will give you the length of the array.

1 Like

All good, thought you were back already. Enjoy the rest of the trip I’ll try out some things with that info thanks :blush:

Here’s my current set up

Group TTS Alarm -(And)
-Group House Modes -(XOR)
- House is any of: night, away or vacation
-Group Alarm Zones -(OR)
-list of all the alarm zones

I believe what Rigpapa said is what you’re suggesting. Listing the devices, then referencing that list to see which devices are tripped and having a line of code spit out the names into a line of speech.

1 Like

So I was able to get the expressions up and running! Now im just stuck on the TTS part. From my understanding each expressions results are stored in a state variable. How would I insert the ‘message’ state variable into my TTS string that looks like this:

luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”, {Text="{message} has been opened", Volume=50, GroupZones=“Arman’s Sonos One”, Repeat = 1}, 632)

luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”, {Text= ..message.. "has been opened", Volume=50, GroupZones=“Arman’s Sonos One”, Repeat = 1}, 632)

I think will do it. Where ‘message’ is the name of your variable

C

You don’t need Lua. Choose a Device Action in the activity, choose your TTS device, Say action, and set Message to {message}. Note that you cannot include other text there. It can only be {message}. If you want more text prepended/appended, do it in the expression that creates message as my example shows.

Also note that Sonos plugin uses a different definition for GroupZones. In Sonos, only values ALL or CURRENT or blank are allowed. If you want to specify devices, they go in GroupDevices. Not sure how the Alexa TTS approached this but it looks like it’s different.

1 Like

sigh didn’t realise we could use Reactor natively for TTS!

Thanks!

C

Any action declared and supported by any device.

1 Like

Nice catch, I didn’t notice in the service definition. I will add GroupDevices to a future release, because for VeraAlexa groups or devices are used in the same way.

Let me know if I can be of any help clarifying their usage/values. I also see you’ve added Repeat to the action, which is a great power-up, so I’ll carry that into Sonos when I get home.

1 Like

Thanks everyone who chimed in! I finally got it working, and have learnt a lot in the process. :slight_smile: Last question do expressions use more up more memory than a regular reactor activity? Noticed since I added the expressions ive been sitting at a lower ~130,000 KB

Temporary memory spikes during evaluation, but relatively small (a few K). The bigger hit is that LuaXP (the expression parser/evaluator) has to be loaded. If no expressions are used at all, no need. But one instance is shared among all ReactorSensors, so it’s unlikely to be consequential.

Also expressions vs activities is not a comparison… ecpressions vs conditions would be more correct.

By loaded Im assuming you mean clicking the ‘Results export to state variable’, in my case I had it clicked but from reading the docs id only need it if I was using the expression results outside the RS itself.

No, the existence of any expression requires the evaluator to be loaded. Export state does not matter. But don’t sweat it, it’s not large enough to worry about except maybe on an unreasonably-loaded Lite.

1 Like

Rigpapa,
I know I am asking alot here, but would it be possible to write a description of the steps to follow in order to get Alexa to speak based on my Vera Plus actions.
Everyone mentions writing ( Expression and Reactors ) where does one write the required information.
I would know where to start.
Thank You
Dom

I’ll get on it!

1 Like

So here is my setup, there may be a few issues with it but in my preliminary testing it works. The conditions only allow zone announcments when the house is night/away/vacation mode and the alarm is armed and any of my alarm zones are opened. (see screenshot)


The expressions I have shown are pretty cut and paste, for the ‘sensors’ expression all the numbers are the Device ID numbers of the zones that I want to be monitored for a state change. The ‘message’ expression is also cut and paste and you can add or remove other text in the same manner.

For the activities in my case im using the Alexa TTS plugin for my Sonos/echo devices. You can use any other TTS plugin, as long as your referencing the expression in curly brackets {} and adding nothing else in the text variable. To reference a result of an expression simply put the name of the expression, for my example ‘message’, in curly brackets: {message}

My setup can be altered to work at anytime during the day by simply removing the ‘Night/Away Mode or Armed’ condition and adding any other conditions as needed. Again I want to thank everyone who chipped in and helped me out, truly have opened many doors for more advanced automation.

Thanks Pabla, I was able to view some of the videos posted on You Tube, by rigpapa, they were great it gave me some insight on how to get started.

And now with your added input makes the whole process much more understandable.

Thankn You so much.

1 Like

Let me know if you have anymore questions!

Best Home Automation shopping experience. Shop at getvera!

© 2020 Vera Control Ltd., All Rights Reserved. Terms of Use | Privacy Policy | Forum Rules