Skip to content

luryus/light-operator

Repository files navigation

💡💡 Light-operator 💡💡

"Let there be light". And there was light.

Clearly, even the Bible recognized the importance of managing lights declaratively. Why not do that in our homes, too?

Light-operator allows managing smart lights with Kubernetes custom resources. This guarantees unparalleled scalability and reliability for switching lights on and off. You just need to run and maintain a Kubernetes cluster and define a few lines of YAML, and you have complete declarative control over your bulbs! Why would anyone use physical light switches or talk to a voice assistant anymore?

With light-operator, you can finally solve configuration drift issues with your lights! Light-operator continuously monitors your light status and reconciles them to achieve the declared state. No more other family members sabotaging your carefully crafted lighting configuration!

Features

  • Light states defined as Kubernetes custom resources
  • Continuous reconciliation: light-operator will try to keep lights in the declared state
  • Switch lights on
  • Switch lights off
  • Control brightness and color

Get started

  1. Have SmartThings-compatible light bulbs installed and integrated to your SmartThings account
  2. Generate a SmartThings API token here: https://account.smartthings.com/tokens. Make sure to add all the devices scopes (list all devices, see all devices, manage all devices & control all devices).
  3. Install light-operator with Helm:
    helm install my-light-operator oci://ghcr.io/luryus/charts/light-operator --set-string "smarthome.smartthings.apiToken=<your api token>"
    
  4. Define the state of your bulb in a YAML file:
    apiVersion: light-operator.lkoskela.com/v1alpha1
    kind: Light
    metadata:
      name: living-room-ceiling-1
    spec:
      # Grab the device ID from the SmartThings CLI (run `smartthings devices`)
      deviceId: <your device id>
      state: 'SwitchedOn'
      brightness: 80
  5. Apply the definition: kubectl apply -f light.yaml
  6. See the bulb light up!

light-operator will now continuously monitor the light. If any changes are made to its state, it will be reconciled to match the definition. You can try this by turning the light off via the SmartThings app - in a moment, light-operator will turn it back on!

Light Configuration Reference

Here are all the options available to configure a light. Usable features depend on the capabilities of each light.

apiVersion: light-operator.lkoskela.com/v1alpha1
kind: Light
metadata:
  name: living-room-ceiling-1
spec:
  # Device ID: This is generated by SmartThings and identifies the device
  deviceId:
  # Is the light on (SwitchedOn) or (SwitchedOff)
  state: 'SwitchedOn'

  # The brightness level of the bulb (0-100)
  brightness: 80

  color:
    # Either colorTemperature or hueSaturation must be specified

    # Light color temperature, 1-60000 K
    colorTemperature: 2700

    # Color hue+saturation
    hueSaturation:
      # Hue 0-100
      hue: 30
      # Saturation 0-100
      saturation: 60

FAQ

Does it really work?

It does! (But tested only with a single device)

It's dark. Can I provision new lights in my ceiling with this?

Unfortunately, light-operator does not currently support crafting physical light bulbs (PRs welcome)

Does it support blue-green deployments?

Sure!*

blue-green

*With compatible RGB bulbs

Why is only SmartThings supported?

It was the easiest way to control the single smart bulb I have (the cheapest non-shady looking one I could find). Support for other smart home platforms can be added (PRs welcome)

Why?

This felt like a fun little project to do and play around with kube-rs.

Can I use this in production?

I wouldn't