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

Device API Call from commandline to HCL does not work


Rikbast

Question

Hi,

 

I have a strange issue. I am trying to do an API call to my HCL from the commandline:

local config=assert(io.popen('curl -s "http://username:[email protected]:80/api/devices/118"'))

and then do a json decode in order to retrieve the value of 'value' (true of false)

The device is a Fibaro Motionsensor, but I don't get a respons, only a nil return. I use 'retrievedvalue = properties.value'

 

If I do the same for this call:

config=assert(io.popen('curl -s "http://username:[email protected]:80/api/weather"'))

and retrieve value 'Temperature', it works perfect

 

Is there anything different from calling a Fibaro device? How to get it working?

 

I am on software version 4.170 for the HCL

 

Thx,

Rik

Edited by Rikbast
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Can you give a bit more context, please, including the full code.

 

Your code is dependent on Linux OS and flavor. Why do you call curl instead of a native REST library?

 

I'm doing API calls with Python all the time, here is an example showing all devices' property.values.

Please login or register to see this code.

/jayrock

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi,

     

    Here is the full code in Domoticz LUA

     

    commandArray = {}

    json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()  -- For Linux

          
           local config=assert(io.popen('curl -s "http://username:[email protected]:80/api/devices/118"'))
      
           local motion = config:read('*a')
           config:close()
           local MotionSensor = json:decode(motion)
           MovementDetected = MotionSensor.properties.value
           print(MovementDetected)     -- as check if it works

     

    return commandArray

     

    The idea is to get the value 'true' or 'false' into domoticz for further processing.

     

    thx,

    Rik

    Link to comment
    Share on other sites

    • 0

    Does the user have permission to access that specific device?

     

    What's the output if you paste the URI into a browser?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I don’t get an output in a browser, but if I use the HTTP code …/api/weather I do get a response (using the same username/password.)

    So I don’t understand why it does not work for devices. Are there special settings on a HCL? Create an new admin account?

     

    Link to comment
    Share on other sites

    • 0

    If you don't get any output try the API at http://192.168.2.173/docs/#!/devices

     

    Suspect you have a type somewhere or the user has insufficient priviledges.

     

    Why do you try to reinvent the wheel, there are tons of examples for api access in this forum.

     

    Cheers,

     

    jayrock

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Got it working:

     

    local config=assert(io.popen('curl -s -u <username:passwd> "http://192.168.0.33:80/api/devices/118"')) did the trick.

     

    Thx anyway

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