-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_data.lua
75 lines (63 loc) · 2.32 KB
/
global_data.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
local function readFile(path)
local file = io.open(path, "rb")
if not file then return nil end
local content = file:read "*a"
file:close()
return content:gsub('\r\n', '\n')
end
local function cmd(command)
local f = assert(io.popen(command, 'r'))
local s = assert(f:read('*a'))
f:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
return {
helpers = {
cmd = function(command)
return cmd(command)
end,
cmdDetached = function(command, name, filename)
os.execute('start "'..name..'" cmd /c '.. command..' ^> "/scripts/data/"'..filename)
end,
ping = function(ip, device)
ping_result = cmd('ping -n 1 -w 1500 '..ip)
if (string.find(ping_result, "TTL", 1, true) ~= nill) then
device.switchOn().checkFirst()
else
device.switchOff().checkFirst()
end
end,
forcedState = function(domoticz)
forcedState = domoticz.devices('Forced State')
return forcedState.lastUpdate.minutesAgo < tonumber(forcedState.text)
end,
readFile = function(path)
return readFile(path)
end,
readLocalFile = function(name)
return readFile('/scripts/data/'..name)
end,
sendSms = function(domoticz, message)
smsUrl = 'https://sms.ru/sms/send?api_id=ID&to=PHONE&json=1&msg='
if (domoticz.devices('Send Sms').active) then
domoticz.openURL(smsUrl..message:gsub("%s+", "_"))
end
end,
pushB = function(topic, message, device)
deviceJson = "";
if device ~= nill then
deviceJson = '\\"device_iden\\":\\"'..device..'\\",'
end
json = '{\\"body\\":\\"'..message..'\\",\\"title\\":\\"'..topic..'\\",'..deviceJson..'\\"type\\":\\"note\\",\\"direction\\":\\"outgoing\\"}'
curl = 'curl --header "Access-Token: TOKEN" --header "Content-Type: application/json" --data-binary "'
..json..'" --request POST https://api.pushbullet.com/v2/pushes'
os.execute(curl)
end,
lampCmd = function(cmd)
os.execute('"/scripts/PacketSender/packetsender" -Au IP PORT '..cmd)
end
}
}