I’m trying to add a variable to a JSON request. When trying to add the variable to the request, it doesn’t see it as a variable but as part of the message.
Here’s what I have:
rule "Office Temp Test"
when
Item TempInOffice received command ON
then
var OffTemp = OfficeTemp.state
var message = "The temperature in the office is " + OffTemp + "degrees."
var myData = '{
"entity_id":"media_player.office_home",
"message":"The temperature in the office is " + OffTemp + "degrees."
}'
logInfo("Office Temp",message)
loginfo("Office Temp",myData)
sendHttpPostRequest("http://192.168.2.111:8123/api/services/tts/google_say", "HTTP.CONTENT_TYPE_JSON", myData}')
end
The first log entry gives:
2016-12-24 10:12:06.247 [INFO ] [enhab.model.script.Office Temp] - The temperature in the office is 68.6 degrees.
The second gives:
2016-12-24 10:13:41.268 [INFO ] [enhab.model.script.Office Temp] - {
"entity_id":"media_player.office_home",
"message":"The temperature in the office is " + OffTemp + " degrees."
}
How can I get it so that the 2nd is the same as the first so that the request gets passed along correctly?
Thanks