Beta. The CRDs are v1, but until 1.0 a change that cannot be additive is named in the changelog. What that means.
The other direction, and optional. Started with --ha-url and --ha-token-file, the operator holds a connection to Home Assistant's WebSocket API and mirrors the devices you select into the cluster. Without those flags nothing of this runs. Its kinds are kubeassistant.taumatix.dev/v1, in beta like the bindings (Beta and stability).
config/mirror is the install with mirroring on: config/default plus the two flags and the token, mounted read-only from the Secret kubeassistant-homeassistant. Create a long-lived access token in Home Assistant under your profile, Security, then:
kubectl -n kubeassistant create secret generic kubeassistant-homeassistant \
--from-file=token=./homeassistant-token
kubectl apply --server-side -k https://github.com/taumatix/kubeassistant//config/mirror?ref=v0.1.0
The pods do not start without that Secret. Point --ha-url at your Home Assistant in an overlay, as for the broker (Install); the default is http://homeassistant.homeassistant.svc:8123. Only the leader holds the connection.
Mirror devices
A HomeAssistantMirror creates one HomeAssistantDevice per selected device in its namespace:
apiVersion: kubeassistant.taumatix.dev/v1
kind: HomeAssistantMirror
metadata: {name: kitchen, namespace: home}
spec:
selector: # every list that is set must match; {} selects every device
areas: [kitchen] # area ids
integrations: [hue] # integration domains
labels: [kubernetes] # Home Assistant label ids
deviceIDs: [] # device registry ids
control: true # let the devices be operated; also needs --ha-control
$ kubectl get hadevice -n home
NAME NAME AREA CONNECTED
kitchen-lights-179b1471 Kitchen Lights Kitchen True
The status carries the device's registry details and every enabled entity with its state and attributes (a string as is, anything else as JSON). Access tokens are left out and token= in a URL is redacted, so a camera's stream does not leak to whoever can read the object. State changes are written at most once per --ha-sync-interval (default 5s) per device, and only when something changed.
A device Home Assistant removes, or that stops matching, is deleted, but only on the strength of a registry read over a live connection: an outage deletes nothing. Deleting the mirror deletes its devices. Home Assistant is never modified by any of this.
Commands
Writing spec.entities operates the device:
spec:
entities:
light.kitchen_lights: {state: "on", data: {brightness: "128"}}
cover.garage_door: {state: closed}
cover.hall_window: {service: set_cover_position, data: {position: "30"}}
state maps to the domain's service: on/off to turn_on/turn_off, a number, text or select value to set_value/select_option, a climate's mode to set_hvac_mode, a cover's or valve's open/closed, a lock's locked/unlocked, and so on. service names any service outright. Each data value is read as JSON when it parses, so "128" is a number and "[255, 0, 0]" a list.
A command is sent once, when its entry changes, not reconciled. Turning the light off with the wall switch afterwards does not make the operator turn it back on. status.commands records what was sent (light.turn_on) or why not, including Home Assistant's own refusal. To send the same entry again, change it or remove and re-add it. A command that finds no connection waits for one.
Write a state into an object
A HomeAssistantEntityBinding writes entity states into an object you already have, the reverse of a DeviceBinding:
apiVersion: kubeassistant.taumatix.dev/v1
kind: HomeAssistantEntityBinding
metadata: {name: weather, namespace: home}
spec:
target: {apiVersion: v1, kind: ConfigMap, name: weather}
fields:
- {entityID: sensor.outside_temperature, path: .data.temperature}
- {entityID: sensor.outside_temperature, attribute: unit_of_measurement, path: .data.unit}
Values are written as a JSON merge patch of the fields that changed, with field manager home-assistant-mirror, converted to the type the target kind's schema declares: 15.6 is a number in a number field and "15.6" in a ConfigMap. Where the schema says nothing, the value the field holds decides, and an absent field gets the string. A path the schema does not declare is refused, as for a command. unavailable and unknown are not written: the field keeps its last value. .status paths and Secret targets are refused. The operator needs get and patch on the target, as for a binding (config/samples/target_rbac.yaml grants one ConfigMap).
Security
Creating a HomeAssistantMirror reads every device the token can see. With --ha-control and control: true, write access to homeassistantdevices in a namespace operates those devices, locks and garage doors included. Grant it as you would the keys. Control is off unless both are set.