Grenton CoreSwift

Grenton Core for Swift

Control a Grenton smart home from Swift on macOS and iOS: lights, shutters, thermostats, scenes and sensors, over the local network, the way the myGrenton app does.

Local, no cloud

Talks to the CLU controllers directly on your network, with their own encryption.

Every device

Switches, dimmers, RGB lights, shutters, thermostats, scenes, sensors, cameras, schedules and TV remotes.

Always current

CLUs push every change, so state stays up to date without polling.

Conformance-tested

Implements the Grenton Core specification and passes its conformance suite.

Installation

Add the package to Package.swift (macOS 13+, iOS 16+):

dependencies: [
    .package(url: "https://github.com/osieckiAdam/grenton-core-swift.git", from: "0.14.0"),
],
targets: [
    .target(name: "MyApp", dependencies: [
        .product(name: "GrentonKit", package: "grenton-core-swift"),
    ]),
]

Download the interface once, then start from the saved copy and list your lights:

import Foundation
import GrentonKit

// Once: Object Manager shows the address and the PIN in "Send to mobile devices".
// The store keeps the archive, and the key inside it, in a protected file.
let store = try InterfaceStore()
if try store.load() == nil {
    let archive = try await ProvisioningClient(host: "192.168.1.50").fetchInterfaceArchive(pin: "149 853")
    try store.save(archive)
}

// Every start: from the saved archive, no PIN and no Object Manager.
let system = try store.system()
await system.start()

for light in system.entities.compactMap(\.switchable) {
    print(light.name, light.isOn == true ? "on" : "off")
}

The project file saved in Object Manager (.omp) is an alternative to the download. The code above, and loading from a project file, are explained step by step in Using the library โ†’