Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
Ros 22
Hi guys,
I thought to share a simple scene that can be called to trigger any IFTTT action via the Webhooks service.
You can call this scene from any other scene or VD just like the smart message hub i.e. fibaro:startScene(sceneID ,{'TriggerID', 'Value1', 'Value2', 'Value3'})
With this you can do pretty much anything IFTTT is capable of. Some examples of what I am using it for below:
- Send myself a message from HC2 to my Facebook Messenger
- Control my geothermal heatpump (Nibe heatpumps support IFTTT)
- Turn on/off main and guest network on the Asus router (also supports IFTTT)
But again, you can use this to trigger pretty much any IFTTT applet.
Credits:
- The logbug function is from Zoran's code (he packs it into all his creations)
- fibaro:args() inspired by Frank's smart message hub
--[[
%% properties
%% events
%% globals
--]]
local deBug = true
local args = fibaro:args()
local TriggerID
local Value1
local Value2
local Value3
local http = net.HTTPClient({timeout=3000})
local Key = '<insert your IFTTT key here>'
if args[1] == nil then TriggerID = '' else TriggerID = args[1] end
if args[2] == nil then Value1 = '' else Value1 = args[2] end
if args[3] == nil then Value2 = '' else Value2 = args[3] end
if args[4] == nil then Value3 = '' else Value3 = args[4] end
if (fibaro:countScenes() > 1) then
logbug('pink', 'The scene is already running')
fibaro:abort()
end
function logbug(color, message)
if deBug then
for line in message:gmatch("[^\010\013]+") do
local txt = line:gsub("([\038\060\062])",
function(c)
return "&#"..string.byte(c)..";"
end)
fibaro:debug(('<span style="color:%s">%s</span>'):format(color,txt))
end
end
end
function IFTTTWebhooks()
http:request('https://maker.ifttt.com/trigger/'..TriggerID..'/with/key/'..Key, {
options={
headers = {['Content-Type'] = 'application/json'},
data = json.encode({value1=Value1, value2=Value2, value3=Value3}),
method = 'POST',
timeout = 3000
},
success = function(response)
logbug('yellow', response.status..' '..response.data)
end,
error = function(error)
print('ERROR: '..error)
end
})
end
IFTTTWebhooks()
Edits: added the missing quotation marks (as per @tampiss)
Edited by RosLink to comment
Share on other sites
10 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.