How I removed old devices from config.json

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

How I removed old devices from config.json

Post by piet66 » 04 Mar 2019 18:11

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 14 times
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 9 (stretch)
Z-Way version v2.3.8 from 2018-10-10 00:47:52 +0300 (build 854d8c466afa676694043ff7a9d17febb3bb01d6)

enbemokel
Posts: 258
Joined: 08 Aug 2016 17:36

Re: How I removed old devices from config.json

Post by enbemokel » 05 Mar 2019 14:49

Hi Piet, I will try this sometimes, thanks for your work.

micky1500
Posts: 75
Joined: 07 Feb 2016 16:29

Re: How I removed old devices from config.json

Post by micky1500 » 05 Mar 2019 18:15

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
(5.83 KiB) Downloaded 26 times
Raspi 3(Jessie), Zwave.me 2.3.8

Post Reply