Hi,
Trying to figure how interaction with other devices’ API is meant to be handled.
I have a device on lan with an API, from which I want to get data into my Homey app, but somehow I can’t get it right using a ordinary fetch in onInit.
fetch(“http://ip-address/endpoint”)
.then((response) => {
// Do something with response
})
.catch(function (err) {
console.log(“Unable to fetch -”, err);
});
Is the approach to fetch from Homey and store in a variable or do I have to put from other device to Homey, having enabled Homey API?
Sorry for being unprecise,
Searching the docs for how to read from another devices’ API, but could only find information regarding Homey API, hence my question if I had to enable HomeyAPI and put from my rPi (tried to make a request using fetch without luck). Some trial and error led me back on track though, using require node-fetch (which I assumed was already loaded from start and that I could use same syntax as in HomeyScript).
Well, problem solved, and to answer my own question:
No, you don’t have to use HomeyAPI, you can fetch from another devices’ API using node-fetch module.
I assume that your goal is to access information for devices from other apps? If so, you should use homey-api, which can be used from an app directly (no need for Raspberry Pi’s or anything like that).
Hello, thanks for your reply.
I have the Pi connected to the modbus interface on my energy recovering ventilation unit. In the Pi, I have created an API for the ventilation unit and up til now, I can control it with a simple web app on LAN. It would be neat to add it to Homey though, to interact with temp sensors, heat pump etc. I realize that I probably won’t get the app published because of the Pi’s custom requirements (could post the API code on git and make it available, but it’s still have a rather specific use case)