How I removed old devices from config.json

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
piet66
Posts: 266
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.
Attachments
updateBackendConfig_V2.3.7.js.zip
(5.78 KiB) Downloaded 226 times
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v3.2.3 from 2022-04-06 04:56:23 +0300
enbemokel
Posts: 482
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.
micky1500
Posts: 298
Joined: 07 Feb 2016 16:29
Location: England

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
updateBackendConfig_V2.3.8.js.zip
Raspi 4 - (Buster - 32 Bit) Zwave Version 4.1.1, Raz 7 Pro, Serial API Version: 07.38
Post Reply