Author Topic: Putting variables into the speak string  (Read 3094 times)

Offline signal15

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +1/-0
Putting variables into the speak string
« on: November 11, 2012, 12:12:00 am »
I have this test code, and it doesn't seem to work.  I don't have any errors in my Luaupnp.log either when I run the scene.


Code: [Select]
local currentTemp = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "CurrentTemperature", 48)

luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = "{tone:1} Good Morning.  The current temperature is " .. currentTemp .. " degrees with a high today of 60 and a low of 42.", Recipients = ""}, 46)

Is this the correct way to call variables and insert them into the speak string?

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +763/-142
Re: Putting variables into the speak string
« Reply #1 on: November 11, 2012, 06:17:26 pm »
You need the Device ID for the Temperature Child device.
The service is: urn:upnp-org:serviceId:TemperatureSensor1
You can determine this by letting your mouse hover over the variable name in the Advanced tab for the device variable you want to access.

See my message template design info at: http://RTS-Services.com/VeraTemplates

When I integrate it will Vera Alerts (Any day now!) you will be able to put the following in your Vera Alert Message String:

"Help the temperature is  {device[48].TemperatureSensor.CurrentTemperature} and climbing!"




Offline signal15

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +1/-0
Re: Putting variables into the speak string
« Reply #2 on: November 11, 2012, 09:28:58 pm »
Yeah, I'm a dummy.  Not sure why I goofed up on the serviceID.  I have it working now.  I'm actually just generating the speak string now in a variable and passing that to Vera Alert.  It's much cleaner when setting all of the alerts up.

Code: [Select]
local currentTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 48)
local lowTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 49)
local highTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 50)

local speakMessage = "{tone:1} Good Morning.  The current temperature is " .. currentTemp .. " degrees with a high today of " .. highTemp .. " and a low of " .. lowTemp

luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = speakMessage, Recipients = ""}, 46)

Offline S-F

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +62/-12
  • Clueless N00b
Re: Putting variables into the speak string
« Reply #3 on: November 24, 2012, 09:35:42 am »
Is there a way to get this information from the weatherunderground API?
My forum account was apparently hacked by a leprechaun. And he's drunk all of the time. If a post of mine seems a little off kilter, it's probably because he made it.

Offline signal15

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +1/-0
Re: Putting variables into the speak string
« Reply #4 on: November 24, 2012, 01:01:08 pm »
Is there a way to get this information from the weatherunderground API?

Yep.  The code above pulls it from the Wunderground data if you have the wunderground plugin installed.  Just make sure you get your device ID's correct.

Here's my current code I'm using:

Code: [Select]
local currentTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 48)
local lowTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 49)
local highTemp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1", "CurrentTemperature", 50)
local currentCondition = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "Condition", 47)
local currentWind = luup.variable_get("urn:upnp-micasaverde-com:serviceId:Weather1", "WindCondition", 47)

local speakMessage = "{tone:1} Good Morning.  Current conditions are " .. currentCondition .. ".  The temperature is " .. currentTemp .. " degrees with a high today of " .. highTemp .. " and a low of " .. lowTemp

luup.call_action("urn:richardgreen:serviceId:VeraAlert1", "SendAlert",
                  {Message = speakMessage, Recipients = ""}, 46)

Note that I'm not using the wind in the speak string right now because Vera Alerts would sometimes stop speaking during that part of it for some reason.

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +763/-142
Re: Putting variables into the speak string
« Reply #5 on: November 24, 2012, 06:09:48 pm »
The new version of Vera Alerts will make it much easier to add variables to your message string. In fact you may never need  luup code for this again!

It's released ... just needs to get through MCV audit.

The web page documentation is still being worked on but it's in pretty good shape:
http://RTS-Services.com/Vera/Plugin/VeraAlerts

Offline S-F

  • Hero Member
  • *****
  • Posts: 1248
  • Karma: +62/-12
  • Clueless N00b
Re: Putting variables into the speak string
« Reply #6 on: December 23, 2012, 01:57:50 pm »
@ signal15,

Where do you have a current wind device? The weather plugin gives me a device with wind, speed and conditions all in one.
My forum account was apparently hacked by a leprechaun. And he's drunk all of the time. If a post of mine seems a little off kilter, it's probably because he made it.

Offline signal15

  • Sr. Member
  • ****
  • Posts: 322
  • Karma: +1/-0
Re: Putting variables into the speak string
« Reply #7 on: December 24, 2012, 02:54:21 am »
@ signal15,

Where do you have a current wind device? The weather plugin gives me a device with wind, speed and conditions all in one.

The wind is a variable that you can pull from that plugin via LUUP.