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

Can not get API data from url


Question

Guest Zooitje
Posted

I have a HomeWizard Energy P1 device connected to my electric meter.

This device has al local api that does not require authentication.

 

There are two api calls:

 

http://<ip-address>/api/v1/data

and

http://<ip-address>/api/v1/telegram

 

http://<ip-address>/api/v1/data gives u the following response:

Please login or register to see this code.

While http://<ip-address>/api/v1/telegram returns the native P1 response.

 

I created a scene wher I want to read the P1 device but with no luck.

My code looks like this:

 

function process(response)
  local http = net.HTTPClient();
  http:request("http://192.168.178.61/api/v1/data",
               { options = {method = "GET"},
                 success = process,
                 error = error });

 

  if (response ~= nil) then
      fibaro:debug(response.data);
 

When I run the scene, nothing happens. The response is nil.

If I change data into telegram, I do get a response with the correct data but it is NOT the data that I want.

 

Can anyone tell me why the response is nil when using: http://<ip-address>/api/v1/data

 

 

4 answers to this question

Recommended Posts

  • 0
Posted

First question, do you intend to make a scene or quickapp?

  • 0
Guest Zooitje
  • Inquirer
  • Posted

    I have a HC2 so I want to make a scene.

     

    I tested it in a VD and that works with the following code (in a VD button).

    (port = 80).

     

    local self_id = fibaro:getSelfId();
    local ip = fibaro:get(self_id, 'IPAddress');
    local port = fibaro:get(self_id, 'TCPPort');

     

    http = Net.FHttp(ip, port);
    response, status, err = http:GET("/api/v1/data");


    result = json.decode(response);

     

    fibaro:call(self_id, "setProperty", "ui.TellerLabel.value", result.active_power_w);
     

    • 0
    Posted

    Oh, you could update your profile, so we know. 
     

    maybe you can use this example to make a quick start met a VD:

     

     

    • 0
    Guest Zooitje
  • Inquirer
  • Posted

    Thanks.

     

    In a VD I have it running but I prefer a scene.

     

    When calling the api in a scene the variable "response" remains nil.

    I copied the code from another scene that reads the output of my solar panels (SolarEdge) an there it works fine.

     

    Could it be that the format of the "data" is wrong?

     

     

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