Use at own risk!
Only works for standard Flows (advanced flows not supported yet)
Hi,
So I just go a new house and wanted to make my Zigbee network a bit better by removing an re-adding my devices so I get a stable network.
But the issue with this is you have to fix all your flows. (Ofcourse https://homey.app/a/com.athom.flowchecker/Flow-Checker/ can indicate the broken flows)
I made a small script which can help with fixing the flows.
So what do you need:
- Device ID you would like to update - You can get this via the webAPI playground:
Homey.devices.getDevices();
- Write down the Device ID
- Remove the Device
- Re-add the Device
- Get the Device ID of the new paired device: - You can get this via the webAPI playground:
Homey.devices.getDevices();
- Run this script in the WebAPI playground: (multiple devices possible)
const oldIds = ['e63c7964-2e67-4347-b2e0-d17a9e4df7e9'];
const newIds = ['221b7559-aeb9-4fbb-a053-acc859dcde6c'];
const main = async function () {
const flows = await Homey.flow.getFlows();
Object.values(flows).forEach(async (f) => {
if (f.trigger && f.trigger.uri) {
const trigger = f.trigger;
const replaceTrigger = trigger.uri.replace('homey:device:', '');
if(oldIds.includes(replaceTrigger)) {
const index = oldIds.findIndex(o => o.includes(replaceTrigger));
trigger.uri = trigger.uri.replace(oldIds[index], newIds[index]);
await Homey.flow.updateFlow({ id: f.id, flow: { id: f.id, trigger: trigger } });
}
}
f.actions.forEach(async (a, i) => {
const replaceAction = a.uri.replace('homey:device:', '');
if(oldIds.includes(replaceAction)) {
const actions = f.actions;
const index = oldIds.findIndex(o => o.includes(replaceAction));
actions[i].uri = actions[i].uri.replace(oldIds[index], newIds[index]);
await Homey.flow.updateFlow({ id: f.id, flow: { id: f.id, actions: actions } });
}
});
f.conditions.forEach(async (a, i) => {
const replaceCondition = a.uri.replace('homey:device:', '');
if(oldIds.includes(replaceCondition)) {
const conditions = f.conditions;
const index = oldIds.findIndex(o => o.includes(replaceCondition));
conditions[i].uri = conditions[i].uri.replace(oldIds[index], newIds[index]);
await Homey.flow.updateFlow({ id: f.id, flow: { id: f.id, conditions: conditions } });
}
});
});
};
main();