Welcome to the Athom Community Forum! This is a place to share ideas, ask for help and discuss about Homey in general.

Please read Welcome to the forum to get started.
API

Web API guidance for a total noob

SliripSlirip Member
edited April 11 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 Moderator
    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.
  • SnooZeSnooZe Member
    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 !!




  • PhaetonPhaeton Backer - Geek Edition
    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!
  • dolfjedolfje Member
    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.
  • SnooZeSnooZe Member
    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 4

    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

  • JasperBJasperB Member
    When the API is stable, you can request your ClientId and Secret. 
  • SnooZeSnooZe Member
    Tnx! 
  • PhaetonPhaeton Backer - Geek Edition
    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 11
    Web API is via Athom's cloud.
    So your app -> Athom -> Homey 
  • PhaetonPhaeton Backer - Geek Edition
    Hmnm. I will keep using the rest interface then. Tnx
Sign In or Register to comment.