How I removed old devices from config.json

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
Posts: 134
Joined: 04 Feb 2017 17:00

How I removed old devices from config.json

Post by piet66 »

Seems that more people have a lot of old devices in config.json and want to remove them.

It's not really necessary, but it's a kind of ballast. You can follow the way I did it, but on your own risk :) .

Start with installing my MxInfo tools and start ConfigJson.html. Tapping on the last button in first line you see if you have old devices.

The first idea I had was to remove the old devices in the program buffer, download the new config.json onto the local PC and exchange it manually on server PC. But I'm not sure whether it is save to do so.

So I did it in this way:
- in ConfigJson.html tap on the last button in the second row to store the list of old devices into a file on server.
- add the lines below to updateBackendConfig.js at to appropiate place.
- start zway server again and the old devices mentioned in the file are deleted

If you have too many old devices, only the first part is stored. There is any limit, maybe buffer length. So you must repeat the whole procedure (store file + restart server) maybe several times.

Code: Select all

// ----------- code added 2019-02-11 start ---------------------------------
// remove old devices from config.json
        var fil = 'MxInfoOldDevices.json';
        try {
            var devOldArray = loadObject(fil);
	    console.log("Info: cleaning config.json via "+fil);
            if (devOldArray.length > 0) {
                devOldArray.forEach(function(oldDevId) {
                    delete config.vdevInfo[oldDevId];
                    config.profiles.forEach(function(profile, ix) {
                        var indx;
                        indx = config.profiles[ix].dashboard.indexOf(oldDevId);
                        if (indx >= 0) {
                            config.profiles[ix].dashboard.splice(indx, 1);
                        indx = config.profiles[ix].hide_single_device_events.indexOf(oldDevId);
                        if (indx >= 0) {
                            config.profiles[ix].hide_single_device_events.splice(indx, 1);

                saveObject(fil, '[]');

        } catch(e) {
	    console.log("Error: cleaning config.json via "+fil+".json: ", e);
// ----------- code added 2019-02-11 end ---------------------------------

	  // Save changes
	  if (oldConfigJSON !== JSON.stringify(config)) { // do we need to update the config?
		try {
		  saveObject("config.json", config);
		} catch (e) {
		  console.log("Error: can not write back config.json to storage: ", e);
You can test this code before changing updateBackendConfig.js in ConfigJson.html tapping onto button 'Remove all old Devices'. This does it only in program buffer.

I added my enhanced version of updateBackendConfig.js for V2.3.7 to this post.
(5.78 KiB) Downloaded 77 times
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster)
RaZberry by Z-Wave.Me ZW0500 6.82.01 05.39/35498 1024/2
Z-Way version v3.1.0 from 2020-09-01
Posts: 400
Joined: 08 Aug 2016 17:36

Re: How I removed old devices from config.json

Post by enbemokel »

Hi Piet, I will try this sometimes, thanks for your work.
Posts: 154
Joined: 07 Feb 2016 16:29

Re: How I removed old devices from config.json

Post by micky1500 »

Hello Piet,
I had 607 old devices.
It took 200 out each time, I had to run it 4 times.
Has tidied things up nicely.

Thank you.

If anyone wants the 2.3.8 modified file. Here it is. /opt/z-way-server/automation/updateBackendConfig.js
(5.83 KiB) Downloaded 110 times
Raspi 4(Buster), Zwave Version 3.1.2
Post Reply