How to get settings in widgets api implementation

Hi there,

I try my first widget and configured a settings in the widget.compose.json as described in the documentation.

...
"settings": [{
    "id": "imageServerIp",
    "type" : "text",
    "title": {"en": "IP Address"},
    "value": "http://<ipaddress>/rest/latest",
    "hint": "The IP address for the imaging rest api"
  }],...

I created a function in the api.js file. This works fine, the function is called. But how do I retrieve the setting in this function?

async getLatestImage({ homey, query }) {
    // you can access query parameters like "/?foo=bar" through `query.foo`

    // you can access the App instance through homey.app
    // const result = await homey.app.getSomething();
    // return result;

    // perform other logic like mapping result data

    const imageServerIp = homey.settings.get("imageServerIp"); 
    var settingsKeys = homey.settings.getKeys();

    console.log(`ServerIP: ${settingsKeys}`);
    return `${imageServerIp}`;
  },

The result in imageServerIp is always null…

regards,
Christian

You can only get the widget settings from within the widget HTML page. See https://apps.developer.homey.app/the-basics/widgets/settings accessing settings.

So you will need to pass in the widgets settings via the API call as part of the query parameter.

How is is possible to SET / UPDATE the settings for the widget. there is only getSettings() but not able to update or setSettings

Not possible.

Can I make a request somewhere for Homey to implement this this is really needed. you need to be able to update your settings somewhere. Now Im working with sessionStorage.
Or is there an eventlister when saving the widget settings.

1 Like