Backup script for the homey-script.
Run the API Script in Homey “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
(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
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.")