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


RonS

Member
  • Posts

    14
  • Joined

  • Last visited

About RonS

  • Birthday 11/26/1961

Profile information

  • Gender
    Male
  • Country
    The Netherlands
  • Gateway/s
    Home Center 2

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

RonS's Achievements

Newbie

Newbie (1/8)

0

Reputation

  1. @jgabI am flabbergasted. Spend day and a half on this and it turned out I should use json.decode instead of json:decode. I tried so many variations ... So how does this work in terms of convention? I use fibaro:debug but must use json.decode; when to use a ":" and when a ".". But thanks a lot for your help .. small things do matter.
  2. Thanks! However, the code both give the same output and result. For whatever reason this picture did not make it into the post. I just do not understand how to work with the output as I keep getting errors. Ron
  3. I am building this for my own educational purpose and got stuck thinking I was almost there. I build a table that holds my devices and their id’s. The table tutorial helped a great deal. I can traverse through the table. I store the table via an encode into a GlobalVar. Which seem to succeed. Next I do a Get on the GlobalVar which is successful (status 200), I get a table when I extract the response (response.value). But when I traverse with the “in pairs” construct I receive an error. Apparently, the response is now a string. function getDeviceTable() response, status = api.get("/globalVariables/DeviceTable/", { name="DeviceTable" }); fibaro:debug(status); fibaro:debug(response); fibaro:debug(response.value); local table = response.value; --local jtable = json:decode(table); --fibaro:debug(jtable); for k,v in pairs(table) do print("first level key: " ..k..", first level value: ".. tostring(v)) --for k2,v2 in pairs(v) do -- This works because we KNOW v is a table. --print(" second level key: " ..k2..", second level value: "..v2) --end; end; If I json:decode response.value the outcome is the same. So, how do I get a response from the GlobalVar that I can work with? Thanks for your help.
  4. @haterThanks for your response. Can you be a bit more specific or post a piece of code I can use. Thanks in advance. Ron
  5. Hello, I am trying to read my Smile P1 interface to my electricity- and gasmeter. If I call this URL in my browser: http://my_local_ipaddress/core/domain_objects I receive a response just in plain text that holds the data I need. However, if I use this in a VD using the following code I do not see any data in the variable response, in fact the debug output does not even show this line (the one in bold). Despite the html status 200, Fibaro errorcode 0 and when I evaluate the response length it provides a number that could fit the browsers response. PI1 = Net.FHttp("my_local_ipaddress"); PI1:setBasicAuthentication("smile", "my_smile_id"); local response, status, errorCode; response, status, errorCode = PI1:GET("/core/domain_objects"); fibaro:debug("Response length: " .. string.len(response)); fibaro:debug("Response: " .. response); fibaro:debug("Status: " .. status); fibaro:debug("Errorcode: " .. errorCode); Here the debug info: [DEBUG] 13:04:35: Status: 200[DEBUG] 13:04:35: Errorcode: 0[DEBUG] 13:05:08: This device: 95[DEBUG] 13:05:08: Response length: 23541[DEBUG] 13:05:08: Status: 200[DEBUG] 13:05:08: Errorcode: 0[DEBUG] 13:05:41: This device: 95[DEBUG] 13:05:41: Response length: 23541[DEBUG] 13:05:41: Status: 200[DEBUG] 13:05:41: Errorcode: 0[DEBUG] 13:06:14: This device: 95[DEBUG] 13:06:15: Response length: 23541[DEBUG] 13:06:15: Status: 200[DEBUG] 13:06:15: Errorcode: 0 I am obviously missing something so help would be much appreciated. Ron
  6. @cag014 @jgab Thanks a lot for your contributions. Indeed the order does not prevent the execution but I was just curious and indeed in some cases it does matter. Also thanks for the explanation. Now it does make sense and will help along the way. Ron.
  7. Thanks @cag014. This idea works. [DEBUG] 11:19:47: Temp:3919[DEBUG] 11:19:47: {"properties":[{"id":81,"value":3919,"size":2}]} However, the order of size and value has been swapped. Can you enforce a specific order? Ron
  8. Simple statement where I update the led temperature of a lightbulb. The first works like a charm. jtable = '{"properties":{"parameters":[{"id":81,"size":2,"value":4999}]}}' HC2:PUT("/api/devices/240",jtable); [DEBUG] 13:28:04: {"properties":{"parameters":[{"id":81,"size":2,"value":4999}]}} Now I want to have the value 2700 in a variable so I can dynamically update the bulb. jtable = '{"properties":{"parameters":[{"id":81,"size":2,"value":TempKelvin}]}}' or jtable = '{"properties":{"parameters":[{"id":81,"size":2,"value": ".. TempKelvin .."}]}}' [DEBUG] 13:29:02: {"properties":{"parameters":[{"id":81,"size":2,"value":TempKelvin}]}} [DEBUG] 13:30:45: {"properties":{"parameters":[{"id":81,"size":2,"value":".. TempKelvin .."}]}} and whatever I have tried it does not replace the variable with its value. Any suggestions? Ron
  9. I want to store my or a group of my device_id's and a logical name in a table and store that table in a global var. That works fine via the API. To retrieve the global var I use the Get request that gives me a response body in JSON. The values stored can be found in response.value which gives me these values: [DEBUG] 09:50:21: [{"id":"103","device":"Vloerlamp"},{"id":"215","device":"LampOpStatief"},{"id":"101","device":"TuinLinks"},{"id":"55","device":"TuinRechts"},{"id":"116","device":"Schuur"},{"id":"61","device":"Boedha"},{"id":"105","device":"Eiland"},{"id":"213","device":"Heklicht"},{"id":"48","device":"LedBoekenkast"},{"id":"154","device":"Yielde"},{"id":"177","device":"Kerstboom"},{"id":"178","device":"Kerstverlichting"},{"id":"194","device":"Buddha"},{"id":"217","device":"Leeslamp"}] I would expect a table = json:decode(response.value); would give me the table I need to build a loop and do something with the devices like turnoff or turnon. But I get this error on the decode: [DEBUG] 10:14:05: 2019-08-11 10:14:05.372820 [ fatal] Unknown exception: /usr/share/lua/5.2/json/util.lua:55: bad argument #1 to 'pairs' (table expected, got string) If I use the GetGlobal() statement and passes that reponse to the decode the it works without an issue and I can process the table. I have read a lot of topics on this but until now I am still clueless. Any help appreciated. I am also a bit confused with how LUA handles strings, tables and JSON.
  10. @Sankotronic I was and am aware of that. My standard account has these priviliges and I even made a new account with admin rights but the outcome remains the same. I use port 88 in the case mentioned above. If I change the user or password I do get an user name or password error. Ron
  11. @Sankotronic I have been fiddling around with this but whatever I do I get the following response when I debug the VD: [DEBUG] 08:50:01: Result = 0 [DEBUG] 08:50:01: Response = -3 [DEBUG] 08:50:01: Status = 200 The -3 seems to indicate an authorisation problem but the credentials I have used are right. What might go wrong? Ron
  12. @Sankotronic Thanks for your quick response. I have a long weekend ahead so hope to find some time to work on this. In the posted examples I cannot see the .png images (yet). Ron
  13. I have a Foscam C2 camera. It works fine in HC2 (except on iOS devices outside my network). I want to control the C2 via LUA. So, if a motion sensor sets an alert I want the cam to start recording and likely take other actions as well, etc. How to send commands to the C2 in LUA, either directly of via VD buttons? So far the only interface to the C2 is via the CGI interface. Thanks, Ron
×
×
  • Create New...