Skip to content

Latest commit

 

History

History
203 lines (190 loc) · 7.94 KB

Quickstart.md

File metadata and controls

203 lines (190 loc) · 7.94 KB

Quickstart

Pre-Installation

Config.json

The config file can be used to set up database access, networking and debug mode. This file is located at data/config/config.json (relative to the binary / repo root).

Docker

Because all parameters of the config.json are configurable via environment variables, a cleaner way to configure Smarthome with Docker would be through the use of docker-compose.yml.

⇒ When running Smarthome via Docker, you might want to skip to the setup.json section below.

Example Contents

{
    "server": {
        "production": false,
        "port": 8082
    },
    "database": {
        "username": "smarthome",
        "password": "password",
        "database": "smarthome",
        "hostname": "localhost",
        "port": 3313
    }
}

Setup.json

Introduction

Most parts of the server's configuration can be set up using the setup.json file, which would be located at data/config/setup.json (relative from the binary / repo root).
If present, this file is scanned and evaluated at startup. After the setup file has been evaluated, it is moved to data/config/setup.json.old, regardless of whether the setup has completed successfully or with errors.

If you want to import a setup.json file into a server which is already set-up, you will be able to do so using the web interface. In case the setup runner encounters conflicting data, for example if a user is already present, the setup is aborted and an error is returned. In some cases, for example if the setup.json is located at data/config/setup.json and scanned at startup, Smarthome's startup is aborted and the setup file is moved to data/conflict/setup.json.old.

Note: The setup.json file is meant to be executed only once (or only on factory-state systems) due to the risk of conflicting data. Due to this, the file is moved to another location after it has been evaluated.

Evaluation

The following table is meant to provide an overview of how the setup.json file integrates into the startup procedure.

Process On failure
0. Server starts Aborting startup
1. Attempting to read setup.json Ignoring setup and continuing startup
1.1. Parsing JSON contents Aborting startup
1.2. Database operations based on contents Aborting startup

Writing your own file

Note: In most cases, the contents of are generated by another program.

⇒ Most of the time, the setup.json file is obtained through a Smarthome configuration export.
For more information on this feature, read the server configuration manual.

When writing your own contents manually, you can always omit empty fields (IDs excluded).
⇒ The setup runner does not mind missing values but treats unknown values as errors. This can result in a significantly smaller setup.json (if written by hand).

Example Contents

{
    "users": [
        {
            "user": {
                "username": "admin",
                "forename": "Admin",
                "surname": "User",
                "primaryColorDark": "#88FF70",
                "primaryColorLight": "#2E7D32",
                "password": "$2a$10$snIDJ3dITPWc4hY8OQstv.nYzzA5mfzYMX.IgwlmtCcMzlKrKHC9m",
                "schedulerEnabled": true,
                "darkTheme": true
            },
            "homescripts": [
                {
                    "data": {
                        "id": "test",
                        "name": "Test script",
                        "description": "This script is entirely for testing",
                        "quickActionsEnabled": true,
                        "schedulerEnabled": true,
                        "code": "if !checkArg('message') {\n  panic('No `message` argument specified!')\n}\n\nnotify(\n  \"Message\",\n  getArg('message'),\n  1,\n)",
                        "mdIcon": "science"
                    },
                    "arguments": [
                        {
                            "argKey": "message",
                            "prompt": "What message should be sent to you?",
                            "mdIcon": "add_alert",
                            "inputType": "string",
                            "display": "type_default"
                        }
                    ],
                    "automations": [
                        {
                            "name": "Test Automation",
                            "description": "This automation executes a script which will fail due to missing arguments.",
                            "cronExpression": "42 4 * * 0,1,3,2,4,5",
                            "enabled": true,
                            "timingMode": "normal"
                        }
                    ]
                }
            ],
            "reminders": [
                {
                    "name": "Important task",
                    "description": "This is the description for an important task",
                    "priority": 4,
                    "createdDate": "2022-07-22T21:35:08Z",
                    "dueDate": "2022-08-02T00:00:00Z",
                    "userWasNotified": false,
                    "userWasNotifiedAt": "1969-11-29T23:00:00Z"
                }
            ],
            "permissions": [
                "*"
            ],
            "switchPermissions": [],
            "cameraPermissions": []
        },
        {
            "user": {
                "username": "guest",
                "forename": "Guest",
                "surname": "User",
                "primaryColorDark": "#7094ff",
                "primaryColorLight": "#0055ff",
                "password": "$2a$10$uL6VipftLMmabF8BlQPtZObZGK7YlDfDtkoXSwvJKFX5CtJ83ecYK",
                "schedulerEnabled": true,
                "darkTheme": true
            },
            "homescripts": [],
            "reminders": [],
            "permissions": [
                "setPower",
                "reminder"
            ],
            "switchPermissions": [
                "lvr_big_lamp",
                "lvr_desk_lamp"
            ],
            "cameraPermissions": [
                "lvr_main_door"
            ]
        }
    ],
    "rooms": [
        {
            "data": {
                "id": "living_room",
                "name": "Living Room",
                "description": ""
            },
            "switches": [
                {
                    "id": "lvr_big_lamp",
                    "name": "Big Lamp",
                    "powerOn": false,
                    "watts": 42
                },
                {
                    "id": "lvr_desk_lamp",
                    "name": "Desk Lamp",
                    "powerOn": false,
                    "watts": 24
                }
            ],
            "cameras": [
                {
                    "id": "lvr_main_door",
                    "name": "Living Room Main Door",
                    "url": "http://example.com/1.png"
                }
            ]
        }
    ],
    "hardwareNodes": [
        {
            "name": "Living Room Node",
            "enabled": true,
            "url": "http://example.com/1.png",
            "token": "secret_t0ken"
        }
    ],
    "serverConfiguration": {
        "automationEnabled": true,
        "lockDownMode": false,
        "latitude": 3.14159265,
        "longitude": 3.14159265
    }
}

A Word on complexity

Because the contents above may seem very complex and confusing at first, it is to be mentioned that they originate from a Smarthome configuration export. However, if an easy setup is desired, using the web interface is recommended.

Installation

Getting Started Via Docker

The quickest way to get started with Smarthome is by using Docker.

To get started, continue reading here