Images

Images can be used in various places throughout Homey, such as album art for speakers, camera devices and in Flows.

When an Image is created, it needs a way of providing Homey with its data. This can be either:

  • an URL, available from anywhere on the internet

  • a binary stream through the getStream method

  • a local path to a static image which is shipped with the App.

circle-exclamation
circle-info

You can debug your images in the Developer Toolsarrow-up-right.

Creating an image

Using an URL

URLs should be used when the image is available publicly on the internet.

/app.js
const Homey = require('homey');

class App extends Homey.App {
  async onInit() {
    const myImage = await this.homey.images.createImage();
    // the URL must start with https://
    myImage.setUrl("https://www.example.com/image.png");
  }
}

module.exports = App;

Using a Stream

Streams should be used when downloading an image that cannot be supplied using Image#setUrl()arrow-up-right. Using image streams involves writing data directly into a Node.js stream. Using streams requires homey version 2.2.0 or higher.

Using a Path

Paths should be used when the image is locally available.

Updating the image

Call Image#update()arrow-up-right when the image has been updated, and the front-end will download the image again.

When your image uses a Stream, the method provided in Image#setStream()arrow-up-right will be called again.

At any time, you can switch between delivery type by calling Image#setPath()arrow-up-right, Image#setStream()arrow-up-right or Image#setURL()arrow-up-right.

Retrieving an image

It is also possible to consume an image in your app, for instance through use of Flow Tokens.

Last updated

Was this helpful?