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

Simple question about a HTTP script for virtual device


Question

Posted

Hi all, 

 

I build a controller for my central extraction fan. This was done by wiring a hardware switch to a Wemos D1.

In HTTP i have got 5 links for this switch, to control the 5 options. When i open this link in a browser it pushes the button on the switch once.

 

 

Link 1: 192.168.0.xx/Mode1

Link 2: 192.168.0.xx/Mode2

Link 3: 192.168.0.xx/Mode3

Link 4: 192.168.0.xx/Mode4

Link 5: 192.168.0.xx/ModeT

 

The IP-adres is the same with all links.

 

How can i add these links to a virtual device in Fibaro HC3? So i can control the device within my scenes?

 

Thanks in advance!

 

 

6 answers to this question

Recommended Posts

  • 0
Posted
10 minutes ago, erikland said:

Hi all, 

 

I build a controller for my central extraction fan. This was done by wiring a hardware switch to a Wemos D1.

In HTTP i have got 5 links for this switch, to control the 5 options. When i open this link in a browser it pushes the button on the switch once.

 

 

Link 1: 192.168.0.xx/Mode1

Link 2: 192.168.0.xx/Mode2

Link 3: 192.168.0.xx/Mode3

Link 4: 192.168.0.xx/Mode4

Link 5: 192.168.0.xx/ModeT

 

The IP-adres is the same with all links.

 

How can i add these links to a virtual device in Fibaro HC3? So i can control the device within my scenes?

 

Thanks in advance!

 

 

 

Make a scene with a declaration when the button is pressed. Then use what i have. Change the local url.

I make http calls like this:

 

fibaro.emitCustomEvent("links")
function 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
 
local url = "http://192.168.1.35/api/scenes" .. urlencode("?sceneId=37")
net.HTTPClient():request(url, {
    options={
      headers = {
        ['Content-Type'] = 'application/json',
      },
      method = 'GET',
    },
    success = function(response) 
            print(response.status)
            print(response.data)
    end,
    error = function(message)
            print("error:", message)
            end
     })
 
 
  • 0
  • Inquirer
  • Posted
    17 minutes ago, ppeterr said:

     

    Make a scene with a declaration when the button is pressed. Then use what i have. Change the local url.

    I make http calls like this:

     

    fibaro.emitCustomEvent("links")
    function 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
     
    local url = "http://192.168.1.35/api/scenes" .. urlencode("?sceneId=37")
    net.HTTPClient():request(url, {
        options={
          headers = {
            ['Content-Type'] = 'application/json',
          },
          method = 'GET',
        },
        success = function(response) 
                print(response.status)
                print(response.data)
        end,
        error = function(message)
                print("error:", message)
                end
         })
     
     

    Thanks for the fast reply.

     

    I tried this code, but it does not work. This is a script for a scene, i would like to have a virtual device. Can you help me with this?

     

    Not so much an expert. ;)

    • 0
    Posted (edited)

    I havent got much time this evening, but i exported a quickapp that does the same.

    It has a global variable, just uncomment that in the scipt, and change to your url.

     

    More or less, if you edit this. It will open the URL when the virtual button is pressed in the quick app.

     

     

    This is for a one action button, ofcourse you can add the other actions. 

    maybe it helps you.

     

    Anyway i am no expert :) good luck

     

     

     

    Please login or register to see this attachment.

    Edited by ppeterr
    • 0
  • Inquirer
  • Posted

    Thanks @ppeterr

     

    One more question, what global variables should i uncomment?

    • 0
    Posted (edited)

    Line 21, 22 you dont need.

    Line 23 you dont need either. if you replace the whole url with your own IP included in the code.

     

    Otherwise, if you want you could still use line 23. But then enter the IP in the variable field of the quickapp.

     

    Also rename the label of the button, to something like "start fan"

     

    If that works, you can copy the code. Make a second button, change the IP link with a new action :)

     

     

     

    Edited by ppeterr
    • 0
    Posted

    I made it for you, just change line 21

     

     

    Please login or register to see this attachment.

    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...