Disable insights programmatically for specific capabilities

I apologize if this has been asked and answered before, but search has not yielded anything i could use, so here we go.

I’m creating an app for a smart power meter, and it offers various data like phase voltage/current, as well as separate consumption and production values for power.

As not everybody has their own solar cells, i thought it would be nice to be able to remove these additional details, and i have the app setup to remove the production capabilities.

Additionally i would like to be able to not create insights for stuff like voltage/current/line power, but I’m having less luck with that.

I’m currently attempting to disable insights like the following :

  • Setting device Capability option “preventInsights” to true
  • Getting the ManagerInsights InsightsLog for every capability and calling delete on it

I get absolutely no errors, but somehow insights are still created, so I’m guessing i’m not going about this the right way.

Code below

async disableInsights(capability: string, value: boolean) {
    await this.setCapabilityOptions(capability, { "preventInsights": !value }).catch((error) => { if (this.debug) throw (error); else this.log(`onSettings: setCapabilityOptions ${error}`); });
    if (value === false) {
      let insightsLog: Homey.InsightsLog | void = await this.homey.insights.getLog(capability).catch((error) => { if (this.debug) throw (error); else this.log(`onSettings: create_insights ${error}`); });
      if (insightsLog)
        await this.homey.insights.deleteLog(insightsLog!).catch((error) => { if (this.debug) throw (error); else this.log(`onSettings: create_insights ${error}`); });
    } else {
      await this.homey.insights.createLog(capability, { "title": capability, type: "number" });
    }
  }

Any hints ?

Have you checked https://apps.developer.homey.app/the-basics/devices/capabilities ?

Capability options can be set using the capabilitiesOptions object in the driver’s entry in the App Manifest.

I’m already doing that, but it’s sadly not working as I hoped it would.

It may be the sparse documentation, but the way I read it, it prevents insights from being automatically created, like when you add a device.

I’m setting it anyway because I can’t find the proper way to do it, so I’m kinda just throwing everything but the kitchen sink at the problem :slight_smile:

I’ve been trying to look at the source code for “Device Capabilities” but it’s rather complex, so I was hoping for a simpler example.

I’m not sure if you can set preventInsights programmatically like that, or only during the pairing process when the capabilities are created (see below).

But I don’t really understand why you wouldn’t want to create insights for information like voltage/current/line power, though.

Also, removing production capabilities afterwards sounds like the wrong way around: during the pairing process, you can pass the capabilities that your device should support in the pairing data, so if there is no production available, just leave out those capabilities. You don’t have to specify the capabilities of a device in app.json, they can also be set dynamically during the pairing process. The same goes for capability options, see this.

1 Like

Actually that might be good start, for sure Arie included this functionality in the app.
AVD

I would search for CreateInsights in the Bitbucket

What about repair process ? (not arguing about provided explanation which is probably the best way around (learning myself…))

The issue is that the data is always present in the data from the smart meter, regardless if there is production or not, it’s simply just a kWh counter (and negative plus reactive power per phase).

The device delivers data over MQTT, and you can’t select which properties to get, and how would i know if it’s a production site, it can only tell by power flowing “backwards” through it.

I was under the impression that “too many” insights could slow down the device, so i figured that i would make an option to disable getting insights for “less important” information like phase current/voltage and individual phase load (which is kinda redundant when you have voltage/current per phase).

If that’s not a problem i will just leave the insights there, and perhaps start the device out without the production capabilities enabled, and people can then enable them after adding the device.

It looks like he does set it programmatically (here), so I guess is should work.

1 Like

Ah right, in that case removing them later makes more sense (although perhaps it would be possible to determine from the counter value if there has been any production already?).

AFAIK Insights isn’t a huge resource hog so it should be fine to just include them.

I would have thought so too, but despite never having had any production on my meter, I still have a non zero reactive power measurement, and not just in the low kW area, but around 2500 kWh.

I could of course have received a used power meter, or it could be some testing procedure, but since my sample size is 1, I really can’t tell.

So I figured I would make an option to exclude production metrics.

I ended up simply excluding production metrics when first setting up the device, and then added a checkbox to enable production metrics, which will then add the needed capabilities to the device.

1 Like