together with Tasker for that. It works very well. You can send the text to be spoken as an argument to Your autoremote command.
Here are some functions that I use.
Code: Select all
local function MyDomo()
local utils = require('scripts/lua/Utils')
local self = {
['utils'] = utils,
['PRIORITY_LOW'] = -2,
['PRIORITY_MODERATE'] = -1,
['PRIORITY_NORMAL'] = 0,
['PRIORITY_HIGH'] = 1,
['PRIORITY_EMERGENCY'] = 2,
['ALARMSTATE_ALERT'] = 'Alert',
['ALARMSTATE_ARMHOME'] = 'Arm Home',
['ALARMSTATE_ARMAWAY'] = 'Arm Away',
['ALARMSTATE_ERROR'] = 'Error',
['ALARMSTATE_DISARMED'] = 'Disarmed',
['ALARMSTATE_TRIPPED'] = 'Tripped'
}
local EMPTYSTRING = 'Empty String'
self.localhost = uservariables['DomoticzUsername']..':'..uservariables['DomoticzPassword']..'@'..uservariables['DomoticzHostname']..':'..uservariables['DomoticzPort']
if (self.localhost == ':@:') then self.localhost = 'localhost:8080' end
function self.setVar(uservariablename, uservariablevalue, uservariabletype)
-- uservariabletype: 0 = Integer, 1 = Float, 2 = String, 3 = Date in format DD/MM/YYYY, 4 = Time in 24 hr format HH:MM
uservariabletype = uservariabletype or 2 -- Defaults to 2
if (uservariablename ~= nil) then
if (uservariablevalue == nil or uservariablevalue == '') then
if (uservariabletype == 0) then uservariablevalue = 0
elseif (uservariabletype == 1) then uservariablevalue = 0.0
elseif (uservariabletype == 2) then uservariablevalue = EMPTYSTRING -- Empty strings are problematic in an URL
elseif (uservariabletype == 3) then uservariablevalue = os.date ('%x')
elseif (uservariabletype == 4) then uservariablevalue = os.date ('%H:%M')
else
utils.log('Invalid uservariabletype passed to setVar function', utils.LOG_ERROR)
return
end
end
if (uservariables[uservariablename] == nil) then
--print('Create a new User Variable: '..uservariablename..' Value: ' ..uservariablevalue..' Type: ' ..uservariabletype)
self.OpenURL('http://'..self.localhost..'/json.htm?type=command¶m=saveuservariable&vname='..uservariablename..'&vtype='..uservariabletype..'&vvalue='..utils.urlencode(uservariablevalue))
--print('http://'..self.localhost..'/json.htm?type=command¶m=saveuservariable&vname='..uservariablename..'&vtype='..uservariabletype..'&vvalue='..utils.urlencode(uservariablevalue))
else
--print('The User Variable '..uservariablename..' already exists, just update it')
commandArray['Variable:'..uservariablename] = tostring(uservariablevalue)
end
end
end
function self.getVar(uservariablename)
local v
v = uservariables[uservariablename]
if v == EMPTYSTRING then -- Newly created string variable that needs to be set to ''
commandArray['Variable:'..uservariablename] = ''
v = ''
end
return v
end
function self.homeAwake()
return (otherdevices_svalues['Z1 Alarm'] == self.ALARMSTATE_DISARMED and true or false)
end
function self.getSecurityState()
return otherdevices_svalues['Z1 Alarm']
end
function self.blinkLight(light, times)
times = times or 2
local cmd1 = 'Off'
local cmd2 = 'On'
local pause = 0
if (otherdevices[light] == 'Off') then
cmd1 = 'On'
cmd2 = 'Off'
end
for i = 1, times do
commandArray[#commandArray + 1]={[light]=cmd1..' AFTER '..pause }
pause = pause + 3
commandArray[#commandArray + 1]={[light]=cmd2..' AFTER '..pause }
pause = pause + 3
end
end
function self.OpenURL(url)
-- The commandArray also supports nested tables to send the same command type multiple times.
-- To do this, give the command a numeric index
commandArray[#commandArray + 1]={['OpenURL']=url }
end
function self.setTextDevice(idx, sValue)
self.OpenURL("http://"..self.localhost.."/json.htm?type=command¶m=udevice&idx="..idx.."&nvalue=0&svalue="..utils.urlencode(sValue))
end
function self.AutoRemote(arMessage, deliverTo)
local url
if ((deliverTo == '') or (deliverTo == nil) or (deliverTo == 'Narva2')) then deliverTo = 'Default' end
if (otherdevices['Internet'] == 'On') then -- We have Internet access, use GCM Server for delivery
url = 'https://autoremotejoaomgcd.appspot.com/sendmessage?key='
url = url .. (deliverTo == 'MastersCellPhone' and self.getVar('ARKey1') or (deliverTo == 'SonsCellPhone' and self.getVar('ARKey2') or (deliverTo == 'Uth' and self.getVar('ARKey4') or self.getVar('ARKey3')))) .. '&message=' .. utils.urlencode(arMessage) .. '&password=' .. self.getVar('ARPassw') .. '&sender=Vera'
elseif (deliverTo == 'Default') then -- No Internet but Use LAN access to device for inhouse Speaker
url = 'http://vera-voice.private.narva2:1817/?message=' .. utils.urlencode(arMessage) .. '&password=' .. self.getVar('ARPassw') .. '&sender=Vera'
else -- No Internet access for externa host so delivery is not possible
return
end
self.OpenURL(url)
end
function self.speak(speakMessage, deliverTo, canSpeakAtNight)
local NOTHINGTOSAY = 'Inget att säga' -- You may translate this into your own language
speakMessage = speakMessage or NOTHINGTOSAY
canSpeakAtNight = canSpeakAtNight or 0
--if ((deliverTo == '') or (deliverTo == nil)) then deliverTo = self.getVar('RecDef') end
if ((not self.homeAwake()) and canSpeakAtNight == 0) or ((otherdevices['Mobiltelefon JMC'] == 'Off') and (otherdevices['Mobiltelefon JMC på Guest VLAN'] == 'Off') and deliverTo == 'SonsCellPhone' and canSpeakAtNight == 0) then
return -- Not a good time to speak unless canSpeakAtNight flag was specified
end
if (speakMessage ~= '') then
self.AutoRemote('SpeakIt=:=' .. speakMessage, deliverTo)
end
end
-- SMS messages are sent by making HTTP calls through the Clickatell API
function self.sendSMS(SMSText, PhoneNumber)
if ((PhoneNumber == '') or (PhoneNumber == nil) or (PhoneNumber == 'SMS-Away')) then PhoneNumber = uservariables['SMS-Away'] end
self.OpenURL('https://api.clickatell.com/http/sendmsg?user='..uservariables['ClickatellAPIUser']..'&password='..uservariables['ClickatellAPIPassw']..'&api_id='..uservariables['ClickatellAPIId']..'&from=+'..uservariables['ClickatellSender']..'&to='..PhoneNumber..'&text='.. utils.smsEncode(SMSText))
utils.log('Sending out SMS to ' .. PhoneNumber, utils.LOG_DEBUG)
end
-- Notifications are sent by making HTTP calls through the NMA API
function self.sendNotification(event, description, priority)
priority = priority or 0
self.OpenURL('https://www.notifymyandroid.com/publicapi/notify?apikey='..uservariables['NMAapikey']..'&application=Domoticz&event='..utils.urlencode(event)..'&description='..utils.urlencode(description)..'&priority='..priority)
end
return self
end
return MyDomo
Code: Select all
local self = {
LOG_ERROR = 1,
LOG_EXEC_INFO = 2, -- Default unless overridden locally. Higher numbers won't show.
LOG_INFO = 3,
LOG_DEBUG = 4,
}
function self.fileExists(name)
local f=io.open(name,'r')
if f~=nil then
io.close(f)
return true
else
return false
end
end
function self.osExecute(cmd)
os.execute(cmd)
end
function self.runcommand(command)
h=io.popen(command)
response=h:read('*a')
h:close()
return(response)
end
function self.print(msg)
print(msg)
end
function self.log(msg, level, logPre)
level = level or self.LOG_INFO
logPre = logPre or 'MyDomo'
local lLevel = _G.logLevel==nil and 2 or _G.logLevel
if (level <= lLevel) then
self.print((level < 2 and '(Error) ' or (level < 3 and '(Exec info) ' or (level < 4 and '(info) ' or '(debug) ')))..logPre..': '..(level < 2 and '<span class="logerror">' or '')..msg..(level < 2 and '</span>' or ''))
end
end
function self.smsEncode(str)
-- Convert to GSM 03.38 character set and URL-encode
local utf8Chars={'%%','\n',' ','"','&',',','%.','/',':',';','<','=','>','?','¡','£','#','¥','§','Ä','Å','à','ä','å','Æ','Ç','É','è','é','ì','Ñ','ñ','ò','ö','Ø','Ö','Ü','ù','ü','ß', '\\', '*', '\'', '%(', '%)', '@', '%+', '%$', '%[', '%]', '%^', '{', '|', '}', '~'}
local gsmChars={'%%25','%%0D','%%20','%%22','%%26','%%2C','%%2E','%%2F','%%3A','%%3B','%%3C','%%3D','%%3E','%%3F','%%A1','%%A3','%%A4','%%A5','%%A7','%%C4','%%C5','%%E0','%%E4','%%E5','%%C6','%%C7','%%C9','%%E8','%%E9','%%EC','%%D1','%%F1','%%F2','%%F6','%%D8','%%D6','%%DC','%%F9','%%FC','%%DF','%%5C','%%2A','%%27','%%28','%%29','%%40','%%2B','%%24','%%5B','%%5D','%%5E','%%7B','%%7C','%%7D','%%7E'}
for i = 1, #utf8Chars, 1 do
str = string.gsub(str, utf8Chars[i], gsmChars[i])
end
return str
end
function self.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
-- Return a Unix Timestamp
function self.normalize(a)
local m,d,y,h,mi,n=a:match('(%d+)/(%d+)/(%d+)%s+(%d+):(%d+)%s+(%w+)')
if n=='PM' then h=h+12 end
return string.format('%04d%02d%02d%02d%02d',y,m,d,h,mi)
end
function self.timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
return self
The above requires a few uservariables to be set up but you might figure it out ...