Skip to content

Commit 0ca26e3

Browse files
authored
Merge pull request #112 from sirkirby/fix/migration-utility
Update migration utility and documentation for v4.0.0
2 parents cc1a7c8 + 5451319 commit 0ca26e3

3 files changed

Lines changed: 322 additions & 41 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,5 @@ coverage.xml
214214
unifi/
215215
aiounifi/
216216

217-
changelog.md
217+
changelog.md
218+
test_automations*

README.md

Lines changed: 124 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,19 +314,139 @@ data:
314314

315315
#### Option 1: Automated Migration (Recommended)
316316

317-
Use the migration utility script to automatically convert your automations:
317+
Use the migration utility script to automatically convert your automations. The utility offers multiple workflows depending on your comfort level:
318+
319+
##### Copy-and-Migrate Workflow (Safest - Recommended for Most Users)
320+
321+
This workflow is perfect if you need to download your automations file from Home Assistant. The easiest method is using the Visual Studio Code add-on:
322+
323+
**Step-by-step using VS Code Add-on:**
324+
325+
1. **Download your automations.yaml**:
326+
- Install the [Visual Studio Code add-on](https://community.home-assistant.io/t/home-assistant-community-add-on-visual-studio-code/107863) from Home Assistant Community Add-ons
327+
- Open VS Code in your browser and navigate to `/config/automations.yaml`
328+
- Right-click the file and select "Download"
329+
330+
2. **Run the migration**:
331+
332+
```bash
333+
python migrate_triggers.py --copy-migrate automations.yaml
334+
```
335+
336+
3. **Review the migrated file** to ensure it looks correct
337+
338+
4. **Upload the migrated file**:
339+
- In VS Code, navigate to the `/config/` folder
340+
- Drag and drop the migrated file to replace your existing `automations.yaml`
341+
- Or right-click in the folder and select "Upload Files"
342+
343+
5. **Restart Home Assistant**
344+
345+
**Alternative command-line approach:**
346+
347+
```bash
348+
# 1. Download your automations.yaml from Home Assistant to your computer
349+
# 2. Run the copy-migrate command (creates backup and migrated copies)
350+
python migrate_triggers.py --copy-migrate automations.yaml
351+
352+
# 3. Review the migrated file
353+
# 4. Upload the migrated file to replace your automations.yaml in Home Assistant
354+
# 5. Restart Home Assistant
355+
```
356+
357+
##### Traditional Workflow (For Direct File Access)
358+
359+
If you have direct access to your Home Assistant files:
318360

319361
```bash
320362
# 1. Scan for legacy triggers
321-
python scripts/migrate_triggers.py --scan /config/automations.yaml
363+
python migrate_triggers.py --scan /config/automations.yaml
322364
323365
# 2. Preview migration (dry-run)
324-
python scripts/migrate_triggers.py --migrate /config/automations.yaml --dry-run
366+
python migrate_triggers.py --migrate /config/automations.yaml --dry-run
325367
326368
# 3. Apply migration (creates backup automatically)
327-
python scripts/migrate_triggers.py --migrate /config/automations.yaml --apply
369+
python migrate_triggers.py --migrate /config/automations.yaml --apply
370+
```
371+
372+
##### Getting the Migration Utility
373+
374+
Since the migration utility is not included in the integration itself (it's only needed once), you have a few options:
375+
376+
1. **Download from GitHub** (Recommended):
377+
- Go to the [UniFi Network Rules repository](https://github.com/sirkirby/unifi-network-rules)
378+
- Download `scripts/migrate_triggers.py` to your computer
379+
- Ensure you have Python 3 and PyYAML installed (`pip install pyyaml`)
380+
381+
2. **Clone the repository**:
382+
383+
```bash
384+
git clone https://github.com/sirkirby/unifi-network-rules.git
385+
cd unifi-network-rules
386+
python scripts/migrate_triggers.py --help
387+
```
388+
389+
##### Downloading Your Automations File from Home Assistant
390+
391+
If you don't have direct access to your Home Assistant files, you can download them through the web interface:
392+
393+
1. **Using Visual Studio Code Add-on** (Recommended):
394+
- Install the ["Visual Studio Code" add-on](https://community.home-assistant.io/t/home-assistant-community-add-on-visual-studio-code/107863) from the Home Assistant Community Add-ons
395+
- Start the add-on and click "OPEN WEB UI"
396+
- Navigate to `/config/automations.yaml` in the file explorer
397+
- Right-click the file and select "Download" to save it to your computer
398+
- After migration, simply drag the migrated file back into the `/config/` folder in VS Code
399+
400+
2. **Using File Editor Add-on**:
401+
- Install the "File Editor" add-on from the Add-on Store
402+
- Navigate to `/config/automations.yaml`
403+
- Copy the content and save it to a local file
404+
405+
3. **Using Studio Code Server Add-on**:
406+
- Install the "Studio Code Server" add-on
407+
- Open the file browser and navigate to `/config/automations.yaml`
408+
- Download the file to your computer
409+
410+
4. **Using SSH/SCP** (Advanced):
411+
412+
```bash
413+
scp homeassistant@your-ha-ip:/config/automations.yaml ./automations.yaml
414+
```
415+
416+
**After migration, upload the migrated file back:**
417+
418+
- **VS Code Add-on**: Drag and drop the migrated file into the `/config/` folder, or right-click and select "Upload Files"
419+
- **File Editor Add-on**: Copy and paste the migrated content into the editor
420+
- **SSH/SCP**: Use `scp` to upload the migrated file back to your Home Assistant system
421+
422+
##### Migration Utility Troubleshooting
423+
424+
**Python/PyYAML not installed:**
425+
426+
```bash
427+
# Install Python 3 (if needed)
428+
# On Windows: Download from python.org
429+
# On macOS: brew install python
430+
# On Linux: apt-get install python3 python3-pip
431+
432+
# Install PyYAML
433+
pip install pyyaml
434+
# or
435+
pip3 install pyyaml
328436
```
329437

438+
**"No legacy triggers found" but you have v3.x automations:**
439+
440+
- Ensure you're running the utility on the correct automations.yaml file
441+
- Check that your automations use `platform: unifi_network_rules` (not just any triggers)
442+
- Verify your automations use legacy trigger types: `rule_enabled`, `rule_disabled`, `rule_changed`, `rule_deleted`, or `device_changed`
443+
444+
**Need help?**
445+
446+
- Use `python migrate_triggers.py --help` for command line options
447+
- Use `python migrate_triggers.py --scan your_file.yaml` to see what would be migrated
448+
- [Open a discussion](https://github.com/sirkirby/unifi-network-rules/discussions) if you need assistance
449+
330450
#### Option 2: Manual Migration
331451

332452
Update your automation triggers manually using the examples below.

0 commit comments

Comments
 (0)