Using Tasker and AutoRemote to deliver spoken messages

I was looking for a way to get Vera messages spoken in my home, even when my Internet connection wasn’t available. Below is my solution. It can be used for delivering messages to be spoken or whatever you want to make your phone do for you. It could send out an SMS for example.

I use an old Android Phone (Samsung Galaxy SII) with a cracked screen connected to a bluetooth speaker They are on constant charge and will work also if there is a power outage.

Both VeraAlerts and Autoremote (in combination with Tasker) required a working Internet connection to be used until recently. Now You can use Tasker/AutoRemote with a LAN URL (or IP address) (without the need of a working Internet connection) to run any Tasker profile. (This is a recent feature that may not yet have hit the playstore. So if you get an org.json.JSONException error message, try the following version of AutoRemote: https://drive.google.com/file/d/0B8G77eDgeMdwZWQwUFBSb3NHT2s/edit?usp=sharing )

Note: The AutoRemote WiFi service needs to be running. Start is as a task whenever phone boots. Go into a Task in Tasker and add the “AutoRemote Wifi” action.

You should use your own IP and password in the example below. SpeakIt is the name of the tasker profile used to speak messages.

local url = "http://192.168.1.XXX:1817/?message=SpeakIt=:=Hello%20World&password=jUYGugkUGH" local httpStatusCode, theContent = luup.inet.wget(url, 10)

Now I always use AutoRemote/Tasker whenever I want to deliver a message locally in my LAN. I use VeraAlerts for messages going ouside of my home.

Below is a lua script (myFunctions.lua) that I use in every PLEG as “startup.lua” and globally in Vera as Startup Lua. By specifying the code “require(“myFunctions.lua”)”. In case You want to use it, or use any part of it, you’ll need to make necessary adjustments to it to reflect your systems configuration.

[code]-- Defined variables only work in the scope of the functions below
local VAdId = 62 – Vera Alert Plugin
local VCdId1 = 53 – System Variables 1 VariableContainer
local VCdId2 = 54 – System Variables 2 VariableContainer

– Common URN:s
local TSUrn = “urn:upnp-org:serviceId:TemperatureSensor1”
local MSWUrn = “urn:dcineco-com:serviceId:MSwitch1” – MultiSwitch
local VAUrn = “urn:richardgreen:serviceId:VeraAlert1”
local VCUrn = “urn:upnp-org:serviceId:VContainer1”
local CTUrn = “urn:futzle-com:serviceId:CountdownTimer1”
local SWUrn = “urn:upnp-org:serviceId:SwitchPower1”

function isNight()
local night = luup.variable_get(“urn:rts-services-com:serviceId:DayTime”, “Status”, 33)
return (night == ‘0’)
end

– VariableContainer functions
function setVCvar(devID, varN, msg)
if(msg == nil)then msg=0 end
luup.variable_set(VCUrn, “Variable”…varN, msg, devID)
end

– getVCvar() get variable from VariableContainer
– A variable may have several values stored in a single pos separated by “;”
function getVCvar(devID, varN, partN)
local var = luup.variable_get(VCUrn, “Variable”…varN, devID)
if(partN == nil) then
return var
else
local tokens = {}
for w in string.gmatch( var, “([^;]+),?” ) do
tokens[#tokens+1] = w
end
return tokens[partN]
end
end

– MultiSwitch set function, defaults to 0 (off) if newValue is omitted
function setMultiSwitch(devID, swN, newValue)
–luup.variable_set(MSWUrn, “Status”…swN,newValue or 0, devID)
luup.call_action(MSWUrn,“SetStatus”…swN,{[“newStatus”…swN]=newValue or 0},devID)
end
function getMultiSwitch(devID, swN)
local value, tstamp = luup.variable_get(MSWUrn,“Status”…swN,devID)
return value
end

function runScene(sceneNo)
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”, “RunScene”, {SceneNum = sceneNo}, 0)
end

function homeAwake()
return (getVCvar(120, 1) == “HomeAwake” and true or false)
end

function getHomeState()
return (getVCvar(120, 1))
end

function urlencode(str)
if (str) then
str = string.gsub (str, “\n”, “\r\n”)
str = string.gsub (str, “([^%w ])”,
function (c) return string.format (“%%%02X”, string.byte(c)) end)
str = string.gsub (str, " ", “+”)
end
return str
end

function speakVera(speakMessage, deliverTo, canSpeakAtNight)
speakMessage = speakMessage or “Nothing special to say”
canSpeakAtNight = canSpeakAtNight or 0
if ((deliverTo == “”) or (deliverTo == nil)) then deliverTo = getVCvar(VCdId2, 5) end
if (not homeAwake()) and canSpeakAtNight == 0 then
return – Do not speak when I am supposed to sleep or when I am not at home unless urgent
end
if ((deliverTo == “MyHome”) or (deliverTo == “MyPhone” and (getMultiSwitch(57, 1) == “1”)) or (deliverTo == “SomeCellPhone” and (getMultiSwitch(57, 2) == “1”))) then
local ip = “192.168.10.” … (deliverTo == “MyPhone” and “5” or (deliverTo == “SomeCellPhone” and “4” or (deliverTo == “Rental” and “8” or “6”)))
local url = “http://” … ip … “:1817/?message=SpeakIt=:=” … urlencode(speakMessage) … “&password=kjuh-Igkj”
local httpStatusCode, theContent = luup.inet.wget(url, 10)
else
– Use VeraAlerts to deliver this message
luup.call_action(VAUrn, “SendAlert”, {Message = speakMessage, Recipients = deliverTo}, VAdId)
end
end[/code]

Edit reason: VeraAlerts does not require a working Internet connection when used with the proper profile. (Vera Alerts Mobile LAN).

[i][b]Vera Alerts Mobile[/b][/i] sends the Notifications to the Vera Alerts Exchange and then off to your Android phone using Google's GCM (Google Cloud Messaging). The GCM provides for storing the message until your phone is ready to receive it.[i][b] Vera Alerts Mobile LAN[/b][/i] sends message right from Vera to the Mobile App without any intermediate stops.

Thank You RichardTSchaefer for pointing that out for me. I was unaware of that. ;D

Thanks for this, I’ve been looking for something along these lines. I’ve saved it to my Evernote

Obviously you can ignore the request to elaborate I made over on “What did You do With Vera Today”, I hadn’t seen this yet :slight_smile:

Vera Alert can be used locally without the Internet!

Thank You RichardTSchaefer for pointing that out for me. I did not know. I’ve made a correction of my initial post. :wink: