I have made a global helper (in global_data) where you can send Pilot messages to some or all known recipients. At the top I defined some users with their keys. And you can send messages like this:
Code: Select all
domoticz.helpers.notifyPilot(domoticz, 'Some subject', 'Some message', 'John')
domoticz.helpers.notifyPilot(domoticz, 'Some subject', 'Some message', 'all') -- send to all
domoticz.helpers.notifyPilot(domoticz, 'Some subject', 'Some message', {'John', 'Katy'})
I use this global function in all my scripts. Works like a charm and even encodes nasty characters in messages. Here is the code:
Code: Select all
local pilotUsers = {
['John'] = 'xxxx', -- use pilot key
['Mary'] = 'yyy',
['Katy'] = 'zzz'
}
return {
helpers = {
notifyPilot = function(domoticz, subject, message, user)
if (subject == nil or subject == '') then
subject = '–'
end
if (message == nil or message == '') then
message = '–'
end
--http://api.pilot.patrickferreira.com/KEY/SUBJECT/MESSAGE
-- generic function for sending messages
local _notifyUser = function(key, name)
domoticz.log('Notify Pilot user: ' .. tostring(name) .. ';' .. tostring(subject) .. ';' .. tostring(message), domoticz.LOG_INFO)
local msg = tostring(key) .. '/' .. domoticz.utils.urlEncode(subject .. '/' .. message, '%20')
local url = 'http://api.pilot.patrickferreira.com/' .. msg
domoticz.openURL(url)
end
if (user == 'All') then
for name, key in pairs(pilotUsers) do
_notifyUser(key, name)
end
elseif (type(user) == 'table') then
for _, name in pairs(user) do
_notifyUser(pilotUsers[name], name)
end
else
_notifyUser(pilotUsers[user], user)
end
end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.