[solved (kind of)] How to completely get rid of discoveryservice?

Hello folks,

I just wanted to refresh if it is already possible or not? Cos i does look like that related issue for discoveryservers doing a lot of I/O is still open here:

And I’m wondering why openhab needs to constantly scan and write stuff to disk when It is not needed nor requeted?

/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ CLOSE_WRITE,CLOSE org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CREATE 1761732059578--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ MODIFY 1761732059578--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CLOSE_WRITE,CLOSE 1761732059578--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ DELETE 1761731754985--org.openhab.core.config.discovery.DiscoveryResult.json

What I want to achieve is completely disable any possible autodiscovery and so unwanted disk writes as possible.

Thanks for hinting me out.

Settings … Add On Management … Show advanced

if you are reffering here

There is no such a thing, if you are reffering to each addon, which is not very systematic approach, then maybe - but eventho I have all discovery flags to false, it still writes those files to jsondb

I’m talking about disablig whole discovery service for everything

There isn’t one discovery service. Under Add-on Management, as you show, there are five discovery services which go out and search your network, plugged in devices, etc for indicators that you have a device or technology which openHAB has an add-on which can be used to integrate that device or technology with OH.

There are lots of different ways that stuff can connect to openHAB (e.g. USB dongles, mDNS, etc) and there is a separate discovery service for each. And since they are separate they are individually controllable.

But I’m pretty sure these only run when OH first starts up or when you open the Add-on store.

That discussion was never an issue. It was merely a discussion about the behavior. It’s also completely unrelated to the add-on discovery services discussed above. There isn’t just one discovery service for Things. Each binding necessarily implements their own Thing discovery because only the binding knows how to discover Things. That’s why when you go to the inbox, you have to choose which binding you want to initiate a scan for new Things instead of just scanning for all bindings.

That is also not an “open issue”. It’s a discussion on the eclipsesmarthome project about what could be a significant architectural change. But that whole project has been archived and openHAB has had nothing to do with ESH since OH 3.0. When OH moved everything back to our own repo, all the relevant open issues were moved too. Looking at the ESH repo for open issues is not relevant to whether that issue is still open for openHAB.

Is there a recent issue in our repos discussing this? If not maybe it was rejected by the maintainers since there are other officially recommended ways to limit SD card writes. At the time of that discussion, ZRAM support in openHABian didn’t exist yet. For those running on SD cards, using ZRAM is the recommended approach to limit writes.

But there has also been a ton of changes made to OH in the seven years since that discussion has taken place. Do we know this is still a problem?

Ultimately, because each binding is necessarily responsible for discovering its own Things, turning on or off that automatic discovery is going to be done on a binding-by-binding basis. How you do that will likely differ based on the binding. For example, to disable the discovery for MQTT, there’s an advanced setting on the MQTT Broker Thing.

i’d say it’s not big issue bit it is very unexpected when

1] logs are in ram tmpfs

2] data are persisted in external influxdb (which has as little as couple of hundreds writes per couple of minutes)

and still OH does over 3k writes to disk every couple of seconds for no obvious reasons. So question is pretty simple and does not really need long elaborate.

By watching what is writing the most, it’s this thing : org.openhab.core.config.discovery.DiscoveryResult.json

so simple question would be: how to completely disable ANY autodiscovery, hence what’s that hard about it?

And @rlkoshak as I’ve mentioned, I do have “enableDiscovery” set to false in all of them, yet those files are still periodically modified nobody knows by what then.

as we can see here

/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ CLOSE_WRITE,CLOSE org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CREATE 1761753407955--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ MODIFY 1761753407955--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CLOSE_WRITE,CLOSE 1761753407955--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ DELETE 1761753286105--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ CLOSE_WRITE,CLOSE org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CREATE 1761753468884--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ MODIFY 1761753468884--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CLOSE_WRITE,CLOSE 1761753468884--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ DELETE 1761753347012--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ MODIFY org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/ CLOSE_WRITE,CLOSE org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CREATE 1761753529821--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ MODIFY 1761753529821--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ CLOSE_WRITE,CLOSE 1761753529821--org.openhab.core.config.discovery.DiscoveryResult.json
/var/lib/openhab/jsondb/backup/ DELETE 1761753407955--org.openhab.core.config.discovery.DiscoveryResult.json
```

and this configuration

had 0 effect to the writes to discoveryResult.json …

update:

so content of that file is everything discovered which alredy have ignore flag set, but for some unknown reason even with everything possible turned off this file gest new update/write every 10seconds and as well it does backups of self.

This looks as a bug to me if I’m not missing any obvious setting I shall tweak.

Set the autodiscovery to OFF for those add-ons that support that, and removing the add-ons that do not.

As I said, there isn’t one discovery service. Each add-on implement discovery individually.

All I can say is if you don’t think it’s hard, please submit a PR. No one else is working on this. Making a change in core which changes the API that all bindings must be adapted to seems pretty hard to me.

You can compare the versions in the backups to see which add-ons are responsible for the repeated writes and file an issue or go fix that add-on. I suspect the problem is you have one or more add-ons which need to be fixed if you are seeing that many writes.

You can follow the official recommendation and use ZRAM for $OH_USERDATA. Then the number of writes doesn’t matter.

I’m not seeing this file written to anyhting close to that much. Maybe a few times a day, but when it is written to it’s because the Chromecast add-on that is doing it (and we already know the Chromecast binding is kind of broken). I suspect MQTT Home Assistant and Alexa also write to it periodically. But I’m not seeing them do it in my backups.

I don’t know if this helps, but make sure your inbox is either empty or any discovered Things which you don’t plan on creating a Thing for is ignored. OH should stop updating that record if it sees it’s already seen it and you’ve ignored it. I’m just guessing at that though.

As was discussed in the link to the ESH discussion, you can set the JSONDB write delay to something larger (Settings → JSON Storage). Then it should save up all the changes for a few seconds before writing. By default mine is set to 500 msecs. if this is set in your system and it’s writing to this file more than that often, file a bug report because something is broken.

To prevent every change from turning into two writes, in that same settings page you can change the number of backup files to 0. Of course that disables the backups so you’d be taking on that risk.

As I explained above, those settings are to control how openHAB goes out and searches your computer and network for devices for which OH has an addon. That’s how the “suggested add-ons” section gets populated in the Add-on store.

They have nothing to do with Things and the DiscoveryResult.json file.

As was discussed in the ESH link you posted above, some bindings rely on the tiemstamp when a device was last seen to do time-to-live. They can’t do that unless they record the time when they last saw the device. But that does answer the question about whether setting the Thing to ignored will change anything.

So it’s not a bug, it’s working as designed.

well agree to disagree, are you trying to suggest that it’s binding issue whenever OH ignores state “ignored” from discovery?

because if I ADD those discovered things it stops to write to DiscoveryResult but if I IGNORE them, it keeps writing that file periodically.

In other words, OH is forcing me to add discovered things eventho I do have added those manually, so I really dont need them again.

But if this is design and working as expected, then … ok, but sounds still as a bug


edit:

yes confirmed, if discovered items are ADDed to the OH, writes goes away immediatelly basically to 0 per minute

if discovered items are IGNOREd, writes are 3k+ per every 10seconds

if you want to know, just throw inotifywait (when using unpriviledged lxc) or iotop if on base system

inotifywait -m -r -e modify,create,delete,close_write /var/lib/openhab

I’m not sure what you are disagreeing with. That it should be easy to “fix”? That is works as I describe?

If the binding can know that the Thing in the Inbox is ignored than yes, it might be a binding issue if it writes to that Thing in the inbox. However, we don’t know what is being written. For me it’s a timestamp only. For you it’s?

But if the binding needs to update the Thing in fways so that if you change your mind and decide to accept it after all, the binding will need to update that entry or else you could never un-ignore a discovered Thing.

It all depends on what is being written, why it’s being written, and what that information is used for.

Most likely the binding doesn’t know that the Thing in the inbox is ignored in the first place. Bindings do not have direct access to the inbox.

Not a bug, but certainly something worth a feature request. Someone might take it on.

And you have found yet another way to mitigate the issue; accept the Things out of the inbox and either don’t link them to any Items or disable them.

To summarize:

  • each binding implements its own Thing discovery, there is no central discovery service
  • many bindings support the ability to disable automatic discovery, some do not
  • to limit writes to the SD card related to discovery:
    • use ZRAM for $OH_USERDATA (official recommendation, default openHABian configuration)
    • do not use add-ons that do not support turning off automatic discovery/ file issues to add the ability to turn automatic discovery off to those add-ons
    • disable automatic discovery at the binding or Thing level (see the doc for the add-on for details) whern not in use
    • disable JSON storage backups to reduce the number of writes by half, though you lose the backup feature
    • accept the Things from the inbox and do not link them to Items and/or disable them to get them out of the inbox
  • The Settings → Add-on Management → * Suggestion settings have nothing to do with Things, the Inbox, nor writes to the JSONDB DiscoveryResults.json file.

whole solution is for now:

  1. add enableDiscovery=false to each bridge (or click fest on UI)
  2. add discovery.:background=false to the runtime.cfg
  3. items which still will be discovered ADD as Things and then disable them
    1. note: IGNORING those Things will not prevent file being updated every couple of seconds!

This is the only way how to stop constant writes to the org.openhab.core.config.discovery.DiscoveryResult.json file

Another solution would be to move whole userdata to the tmpfs, but syncing will be pain in the ass, so this is up to each one of you.

to check whenever you have this issue in lxc unpriviledged container is

inotifywait -m -r -e modify,create,delete,close_write /var/lib/openhab

or iotop if you are running bare system

disagree this is not a bug.

It’s about how OH handles ignored items, and it seems like a bug to me.

suggestion to not to use addons which does not have this ability is kind of strange, as for example Local Time does exactly same issue and it’s ntp official addon :slight_smile:

But anyway, It’s workaround which works and maybe for some people it can help to preserve some unnecessary writes whenever they are not using openhabian nor rpi nor sd cards etc.