# Backup Script For Homey-Script

**URL:** <https://community.homey.app/t/backup-script-for-homey-script/159157>\
**Category:** Off-Topic\
**Created:** [September 4, 2026, 10:53am UTC](https://community.homey.app/t/backup-script-for-homey-script/159157 "2026-09-04T10:53:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Nono](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@Mike\_Nono](https://community.homey.app/u/Mike_Nono)\
**Post date:** [September 4, 2026, 10:53am UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/1 "2026-09-04T10:53:53Z")

</div>

Backup script for the homey-script.

Run the API Script in Homey “api-playground”

[https://tools.developer.homey.app/tools/api-playground](https://tools.developer.homey.app/tools/api-playground)

It will save a file to disk called "homeyscript\_backup.json "

Then run the spilt script in same folder, and you will get a new folder named “My\_HomeyScripts” that should have all your homey-script saved

How to run the split script in cli/terminal: “python3 Split\_HomeyScript.py”

## API Script

```auto
(async () => {
    // 1. Fetch the full settings data
    const settings = await Homey.apps.getAppSettings({ id: 'com.athom.homeyscript' });
    
    // 2. Convert the object into a nicely formatted JSON string
    const jsonString = JSON.stringify(settings, null, 2);
    
    // 3. Create a download link inside the browser memory
    const blob = new Blob([jsonString], { type: 'application/json' });
    const url = URL.createObjectURL(blob);
    const link = document.createElement('a');
    
    // 4. Configure the file name and trigger the download
    link.href = url;
    link.download = 'homeyscript_backup.json';
    document.body.appendChild(link);
    link.click();
    
    // 5. Clean up the memory
    document.body.removeChild(link);
    URL.revokeObjectURL(url);
    
    return "Download started! Check your downloads folder.";
})();

```

* * *

## Split Script python

```auto
import json
import os

# 1. Load the JSON file you saved from Homey
json_file_path = "homeyscript_backup.json"
output_folder = "My_HomeyScripts"

if not os.path.exists(json_file_path):
    print(f"Error: Could not find '{json_file_path}' on your desktop. Make sure it is named correctly.")
    exit()

with open(json_file_path, "r", encoding="utf-8") as f:
    data = json.load(f)

# 2. Handle the HomeyScript JSON structure
# Scripts are usually nested under a "scripts" dictionary or directly in the base object
scripts_dict = data.get("scripts", data)

if not isinstance(scripts_dict, dict):
    print("Error: JSON format not recognized. Make sure you copied the whole Object.")
    exit()

# 3. Create a clean output folder
os.makedirs(output_folder, exist_ok=True)

# 4. Loop through and save each individual script
count = 0
for script_id, script_data in scripts_dict.items():
    # Fetch the name and the actual code block
    name = script_data.get("name", script_id)
    code = script_data.get("code", "")
    
    # Clean up file name to ensure it's safe for your OS
    safe_name = "".join(c for c in name if c.isalnum() or c in (" ", "_", "-")).strip()
    file_name = f"{safe_name}.js"
    
    # Save the file into the folder
    file_path = os.path.join(output_folder, file_name)
    with open(file_path, "w", encoding="utf-8", newline="") as script_file:
        script_file.write(code)
    
    print(f"Saved: {file_path}")
    count += 1

print(f"\nExtracted {count} scripts into the '{output_folder}' folder.")

```

* * *

---

<div class="post-metadata">

**Author:** ![SingKT](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/singkt/32/173226_2.png) [@SingKT](https://community.homey.app/u/SingKT)\
**Post date:** [September 4, 2026, 1:57pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/2 "2026-09-04T13:57:45Z")

</div>

Works fine.  
The scripts have after the split extra blank lines.

---

<div class="post-metadata">

**Author:** ![Mike\_Nono](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@Mike\_Nono](https://community.homey.app/u/Mike_Nono)\
**Post date:** [September 4, 2026, 2:08pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/3 "2026-09-04T14:08:44Z")

</div>

Explain please?  
From what I can see it’s the same.

EX:  
This file “example-condition.js” have 24 lines in the backup folder.  
And in the homey-script it have 24 lines

---

<div class="post-metadata">

**Author:** ![SingKT](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/singkt/32/173226_2.png) [@SingKT](https://community.homey.app/u/SingKT)\
**Post date:** [September 4, 2026, 2:17pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/4 "2026-09-04T14:17:50Z")

</div>

Well, all the example scripts have an extra empty line.  
Maybe because I saved them under a new name.  
No, other scripts have extra lines too. Can‘t say yet why

---

<div class="post-metadata">

**Author:** ![SingKT](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/singkt/32/173226_2.png) [@SingKT](https://community.homey.app/u/SingKT)\
**Post date:** [September 5, 2026, 11:52am UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/5 "2026-09-05T11:52:30Z")

</div>

Replace

```auto
with open(file_path, "w", encoding="utf-8") as script_file:
        script_file.write(code)

```

with:

> with open(file\_path, “w”, encoding=“utf-8”, newline=““) as script\_file:script\_file.write(code)

Does the trick. No more extra blank lines.

---

<div class="post-metadata">

**Author:** ![Mike\_Nono](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@Mike\_Nono](https://community.homey.app/u/Mike_Nono)\
**Post date:** [September 5, 2026, 12:09pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/6 "2026-09-05T12:09:30Z")

</div>

Ok thanks, but I can’t replicate the issue you having.

Does anyone else having this issue?

How are you running the api script and how are running the local, in linux/mac/windows or?

EDIT: It most be on Windows? Right. I updated the file

---

<div class="post-metadata">

**Author:** ![SingKT](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/singkt/32/173226_2.png) [@SingKT](https://community.homey.app/u/SingKT)\
**Post date:** [September 5, 2026, 12:22pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/7 "2026-09-05T12:22:34Z")

</div>

On windows via pyzo using still python 3.10.0 for the script.py

---

<div class="post-metadata">

**Author:** ![Mike\_Nono](https://avatars.discourse-cdn.com/v4/letter/m/7feea3/32.png) [@Mike\_Nono](https://community.homey.app/u/Mike_Nono)\
**Post date:** [September 5, 2026, 12:34pm UTC](https://community.homey.app/t/backup-script-for-homey-script/159157/8 "2026-09-05T12:34:31Z")

</div>

Yes.  
Try the updated it has the code you provided. Thanks
