This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.
API

Web API guidance for a total noob

SliripSlirip Member
edited April 2018 in Developers
Hi!

A total noob need some guidance.. 
I am trying to build a WebApp, I would like to control/monitor specific lights and trigger flows.

I have linked this to my HTML page:
<script type="text/javascript" src="https://cdn.athom.com/athom-api/2.0.109/athom-api.min.js"></script>

From the Athom Developer docs. 
async getDevice(opts) → {HomeyAPI.ManagerDevices.Device}
I can´t understand how to implement this to my JavaScript code, if somebody could give an example code snippet or something so that i could get a starting point.

Thanks! 
Tagged:

Comments

  • swtttswttt Member
    The web-api gets binded to the window, e.g. window.AthomAPI.HomeyAPI etc.
    From there on you need to do the authorization, and then you can do the device calls.
  • Guys, I'm a "beginner" too but can't figure out the authorization part (or at least, want to know the optimal way of doing things).

    I only want to convert a simple dashboard which I created before (and was integrated with Home Assistant), to my Homey. It will only show the status of some devices and serve as alarm panel. I think the optimal way should be the Web API (and not use the REST api) but don't know how to authorise my account to AthomCloudApi. 

    I know I could use homeydash for this project, but I really want to keep my own dashboard.

    1. Is my assumption of using WEB Api correct?
    2. Do I even need to authorise to AthomCloudAPI in order to receive device statuses and start flows? 
    3. An example of how to do this in code would be really (really!) helpful. Is authorisation possible without the redirect to the homey login-screen (so not like homeydash)? I don't want to run this in any webserver outside my home.

    I think I will manage after that... 

    Thanks in advance !!




  • I have similar issues. I would like to to use the webapi bit fail in the first step. Using the library on the webbpage. How do i bind it to the Window. If i have that working id probably be able to figure it out. If someone could share a code example of how they use the webapi on their webpage we noobs might be able to make the first steps. Thanks!
  • I had the same question last week and asked help on the slack channel. Summary of the what was said. You cannot use it atm. It is beta, you need a developer key/secret that you should ask through email (still no response), and I didn't get the fallback method with bearer working (doubting it works). 

    I asked if it maybe was better to add that  information to the wiki, but it was apparently clear enough because of the 'beta' label...

    Answers on your questions:
    1. Didn't get the code working, but I guess you are right after the authorization of you homey
    2. Yes, authorization is needed.
    3. Even in your network that is needed. But if you know something about web development, there is a workaround. With the development tools open, you should check the request that go to you homey. The important part is the bearer code. You can replay the request if that code is added.
  • Thanks Dolfje for the clear answer! Hopefully athom continues their development on the web api...

    I'll try to find out the "rest endpoints" but this shouldn't be the way to implement things...
  • JasperBJasperB Member
    edited April 2018

    Include the js in your head as Slirip did in his original post

      //declare homeyAPI
      let homeyAPI;
    init() { //Set the configuration AthomAPI.AthomCloudAPI.setConfig({ clientId: "56d84892f8ea8fcd7952e70f", clientSecret: "JScLCb3WWTQGw9vHHejJSaup13ReWdYBsiH086Mh" }); //Make connection to the first Homey const cloud = new AthomCloudAPI(); await cloud.authenticateWithPassword("username", "password"); const user = await cloud.getAuthenticatedUser(); const homeys = await user.getHomeys(); homeyAPI = await homeys[0].authenticate(); return homeyAPI; }

    From this point on you can use homeyAPI to call the web api functions

  • When the API is stable, you can request your ClientId and Secret. 
  • Tnx! 
  • Thanks! I see a lot of "cloud" in the code. Does this this connecto to the cloud or directly to homey?
  • JasperBJasperB Member
    edited April 2018
    Web API is via Athom's cloud.
    So your app -> Athom -> Homey 
  • Hmnm. I will keep using the rest interface then. Tnx
  • JamieJamie Member
    Where about can I find the documentation on the Rest interface?


  • Hi There,

    Is there any documentation ready? Wich url do i need to request??
  • Ok Url i figured out! but. Redirect url is does not match... Where do i have to registrate??? .
    Plans are to create an dash on my webhost. likely homeydash..
Sign In or Register to comment.