Jump to content

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


  • 0

[SCENE] IFTTT Webhooks


Ros

Question

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 Ros
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Nice one :-) Thank you. Just a quick fix in Values

 

from fibaro:startScene(sceneID ,{'TriggerID', 'Value1, Value2, Value3'})

to fibaro:startScene(sceneID ,{'TriggerID', 'Value1', 'Value2', 'Value3'}) 

 

There were quotation marks missing in the example.

 

M.

Link to comment
Share on other sites

  • 0

I use webhook of ifttt in action (then) part a lot to trigger different scenes by executing a php file on my vm.  @Ros your script looks the way around unfortunately I do not understand how to use it lol.  is it..

 

if fibaro:getGlobal('aaa') == "0" then

fibaro:startScene(webHookId)

end?

 

What are those TriggerID, value1 value2 etc use for?

 

Thanks!

Link to comment
Share on other sites

  • 0
  • Inquirer
  • 14 hours ago, Sirhideo said:

    I use webhook of ifttt in action (then) part a lot to trigger different scenes by executing a php file on my vm.  @Ros your script looks the way around unfortunately I do not understand how to use it lol.  is it..

     

    if fibaro:getGlobal('aaa') == "0" then

    fibaro:startScene(webHookId)

    end?

     

    What are those TriggerID, value1 value2 etc use for?

     

    Thanks!

    If you read the Webhook documentation, it needs to know the TriggerID  - which action to launch and up to three values to feed parameters into the action being launched. Just read the Webhook documentation at IFTTT...

     

    Link to comment
    Share on other sites

    • 0

    Hi @Ros man this can be a huge change of smart home infrastructure as long as internet is up.  I can imagine I can use your scene to control my retired smartthings hub even with different z-wave frequency devices...

     

    I created an IFTTT recipe with webhook event 'push_test', then trigger ifttt notification as a test.

     

    On HC2 I simply created a lua scene with 1 line,  fibaro:startScene(194 ,{'test_push', 'Value1', 'Value2', 'Value3'}), and run it 2 times. I got the below debug message from your scene though.

     

    1) ERROR: Operation canceled - I can receive the notification

    2) ERROR: Transport endpoint is already connected. - no notification received

     

    Am I doing anything wrong?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Now taking it one level further: The above can trigger IFTTT, but the below is the best way I've seen so far to take an HC2 action triggered by IFTTT.

     

    Many of us are concerned about the security of IFTTT Webhook accessing  HC2 via basic authentication. People have generally tried creating a new user and limiting the rights for that user. For those even more paranoid about security, there is another, more sophisticated solution (tried and tested):

    • IFTTT Webhook sends commands to ThingSpeak channel via API
    • ThingSpeak channel data insertion triggers a Matlab analysis app in the cloud. You can use this app to generate a mathematical encryption of the command you want to forward to HC2. Sky is the limit for encryption here (you can read the Cryptonomicon for insipartion:)
    • ThingSpeak sends an HTTP API request to HC2 to trigger a scene with the encrypted command in the body of the request (to be used in fibaro:args())
    • HC2 Scene processes takes the command from the fibaro:args(), decrypts it and takes appropriate actions

    Here are the reasons this solution works:

    • You have all the versatility of IFTTT
    • You have the flexibility of ThingSpeak Matlab - you can post process and encrypt...
    • On HC2 you only have to give the 'IFTTT user' the right to access that one scene that decrypts the command and takes action

    Speed is ok - requests triggered by IFTTT take 2-4 seconds to be executed by HC2.

     

    Unless Fibaro develops a genuine IFTTT service, the above is the most secure and versatile solution I've come across.

    Also the Google Assistant integration of Fibaro is a joke. But with the above you can do anything you want with GA via IFTTT service - devices, scenes, global variables, all of it together, etc.

    • Like 1
    Link to comment
    Share on other sites

    • 0

    Hi @Ros, really nice stuff you created. Can you please detail the facebook messenger integration? 

    What specific values do we need for 'TriggerID', 'Value1', 'Value2', 'Value3' ? 

    startScene(sceneID ,{'TriggerID', 'Value1', 'Value2', 'Value3'})

    Thanks.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 10 hours ago, crissmil said:

    Hi @Ros, really nice stuff you created. Can you please detail the facebook messenger integration? 

    What specific values do we need for 'TriggerID', 'Value1', 'Value2', 'Value3' ? 

    startScene(sceneID ,{'TriggerID', 'Value1', 'Value2', 'Value3'})

    Thanks.

    Man, you've got to build an IFTTT applet with 2 services: if (webhook) then (facebook messenger). Just read a bit about how IFTTT works, especially the webhook service. You  can set any values you want there....

    Edited by Ros
    Link to comment
    Share on other sites

    • 0

    Thanks. I got it. It's really useful to have my notifications on facebook messenger too. Thanks again.

    Link to comment
    Share on other sites

    • 0

    I am the only one having problem with facebook messenger? Since yesterday I cannot receive anymore messages over IFTTT. My personal IFTTT activity page is frozen since yesterday.

    The scene debug is ok: [DEBUG] 13:43:45: 200 Congratulations! You've fired the Fibaro_to_Facebook event

    Link to comment
    Share on other sites

    • 0

    I am having problem on ifttt without doing any changes recently. super slow response and occasionally 502 error.

     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...