Forum

Browse topics, discover Works With Legrand community!

Getting Started

Hello,

 

I’m a student and would like to develop a project for home automation.

we have a system of MyHomaUp at home and I would like to develop an android app to connect to my home controller and control lights.

I setup an account and created an application (waiting for approve email).

I would like to understand how I can link to my controller and if you have some sample code (Java).

 

Thanks

Yuval Hirsch

  • This topic was modified 3 years, 2 months ago by Hirsch Yuval.

Hello,

I should have approved your app this morning. Concerning steps to follow, you must first manage authentication, then tokens part, and finally your calls. You can find our tutorials here : https://developer.legrand.com/tutorials/getting-started

You can find Java examples at the bottom of Try It page dedicated to each call : https://portal.developer.legrand.com/docs/services/myhome-up/operations/Plant_GetPlant

I advise you to test via the Try It to build your app

Have a good day,

Leslie – Community Manager

For members here in Australia we custom build commercial roller shutters and industrial roller shutters in our own factory in Sydney. These are to a much higher standard and strength than standard residential shutters and will protect your beloved Ford with higher surety and security.

  • This reply was modified 3 years, 2 months ago by Skinner Tony.
  • This reply was modified 3 years, 2 months ago by Skinner Tony.
Images:
You must be logged in to view attached files.

Hi Leslie,

thanks for your help. After the tutorials ( OAuth-2 authentication) what should I do?

I would like to be able to connect my N4500C unit with my android application.

In addition, I copied code samples from get light’s status in the API’s list and it seems like an ‘old’ code, it gave me error on “setEntity” (Cannot resolve method ‘setEntity’ in ‘HttpGet’).

Thanks, Yuval.

Hi Yuval,

Once you followed the steps for /authentication and /token flow of the tutorial, your gateway is linked to your application and you are able to make your calls

You have to call GET plant’s topology and GET user’s plant to retrieve your home and device ids (you can do it via the Try It, it’s easier)

Then, you can do your calls. Here is a Java example of a working GET light’s status generated with Postman :

var settings = {

“url”: “https://api.developer.legrand.com/hc/api/v1.0/light/lighting/addressLocation/plants/000000005a2xxxxxx/modules/parameter/id/value/00000004741405xxxxxxx”,

“method”: “GET”,

“timeout”: 0,

“headers”: {

“Ocp-Apim-Subscription-Key”: “9a44c88bfaa3xxxxxxx”,

“Authorization”: “Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ilg1ZVhrNHh5b2pORnVtMWtsMll0djhkbE5QNC1jNTdkTzZRR1RWQ….”

},

};

 

$.ajax(settings).done(function (response) {

console.log(response);

});

Have a good day,

Leslie – Community Manager

Hi Leslie,

I understand now that I have to use the Home+Control app to connect my gateway (N4500C) to the internet and than it should be linked to my account.

Than I called ‘get users plants’ (using the ‘try it’) to retrieve plants id but I get response code 200 and empty plants (see below)

should I see my device under my account?

could you check were is my mistake?

Thanks

Yuval

 

<code style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; color: inherit; background-color: transparent; border-radius: 0px;" data-bind="text: headers">Pragma: no-cache
Cache-Control: no-cache
Set-Cookie: TiPMix=48.0532169565806; path=/; HttpOnly; Domain=cwn-website-prod.azurewebsites.net; Max-Age=3600; Secure,x-ms-routing-name=self; path=/; HttpOnly; Domain=cwn-website-prod.azurewebsites.net; Max-Age=3600; Secure
X-AspNet-Version: 4.0.30319
Request-Context: appId=cid-v1:17d898fc-adbd-487e-96a4-c4287796f34d
Access-Control-Expose-Headers: Request-Context
Date: Tue, 13 Apr 2021 12:37:36 GMT
Content-Length: 13
Content-Type: application/json; charset=utf-8
Expires: -1
 <code class="json hljs" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; font-size: inherit; padding: 0px; color: #000000; background-color: #ffffff; border-radius: 0px; display: block; overflow-x: auto; text-size-adjust: none;" data-bind="snippet: { brush: bodyBrush, body: body }">{
  "<span class="hljs-attribute" style="box-sizing: border-box;">plants</span>": <span class="hljs-value" style="box-sizing: border-box;">[]
</span>}

<h2 style=”box-sizing: border-box; font-family: wf_segoe-ui_light, ‘Segoe UI Light’, ‘Segoe WP Light’, ‘Segoe UI’, ‘Segoe WP’, Tahoma, Arial, sans-serif; font-weight: 500; line-height: 1.1; color: #be097f; margin-top: 22px; margin-bottom: 11px; font-size: 2.3em;”></h2>

{

“plants”: []

}

Hello Yuval,

In main cases when you receive a 200 response and an empty JSON it means that you entered wrong credentials

On https://portal.developer.legrand.com/docs/services/59e9ad7f8bda9e0b3caea28c/operations/getusersplants/console in Oauth Server for Eliot API > Authorization code : you are asked to enter credentials. Please check you use the credentials from your Home + Control end-user account (the one you use to manage your devices via our application)

Have a good day,

Leslie – Community Manager

 

Dear Leslie,

I’m using the same credentials as I use to login to Legrand web account.

I always get an empty plandid, also from postman.

any idea? could you check logs from your side?

maybe something is wrong with my account creation?

Best Regards

Yuval

Hi laseli

I managed to get plantid by the third party application menu.

Now when I’m using the java code from the code sample for get user plantid in my application there is an error: “Cannot resolve method ‘setEntity’ in ‘HttpGet'”. When I mark this line as a comment, I get an error: Didn’t find class “org.apache.http.protocol.HttpRequestExecutor” (even when I add import of this).

Can you help me with that?

I copied the code sample from this url: “https://portal.developer.legrand.com/docs/services/59e9ad7f8bda9e0b3caea28c/operations/getusersplants&#8221;.

Thanks,

Yuval

Hi Yuval,

When you talk about “Legrand web account” : is it the account you use to access your developer account here on Works with Legrand ? If yes, it’s not the good one. You must use the one you use to see your devices on Home + Control application

I’m not a Java expert but here is a code snippet that should work :

URL url = new URL(“https://api.developer.legrand.com/hc/api/v1.0/plants&#8221;);

HttpURLConnection http = (HttpURLConnection)url.openConnection();

http.setRequestProperty(“Ocp-Apim-Subscription-Key”, “9a44c8xxxxxxxxxx”);

http.setRequestProperty(“Authorization”, “Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUz……”);

 

System.out.println(http.getResponseCode() + ” ” + http.getResponseMessage());

http.disconnect();

Have a good day,

Leslie – Community Manager

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

Information

10 replies
3 participants