Overview
Package camera is Home Assistant's camera domain: its types and its MQTT discovery config.
Entity controls one camera entity over HTTP or MQTT. Device serves one over MQTT.
snapshot, play_stream and record need required parameters and have no method yet.
Home Assistant documents the domain here:
Integration: https://www.home-assistant.io/integrations/camera/
MQTT discovery: https://www.home-assistant.io/integrations/camera.mqtt/
Entity model (developers): https://contributors.home-assistant.io/core/entities/camera/
Control
// client is an *api.Client or a connected *mqtt.Client
target := camera.Get(client, "my_camera")
state, err := target.State(ctx)
err = target.DisableMotionDetection(ctx)Serve
// mqttClient is a connected *mqtt.Client
device, err := camera.NewDevice(ctx, mqttClient, "my-camera",
camera.WithName("My camera"),
)
Commands
What each Entity method does on each transport. MQTT publishes to the topic the entity's discovery config names in that option.
| Method | Over HTTP, calls | Over MQTT, publishes to |
|---|---|---|
DisableMotionDetection |
camera.disable_motion_detection |
not available |
EnableMotionDetection |
camera.enable_motion_detection |
not available |
TurnOff |
camera.turn_off |
not available |
TurnOn |
camera.turn_on |
not available |
Services without a method
Call these with the REST or WebSocket client.
| Service | Why |
|---|---|
camera.play_stream | needs required parameters; not offered yet |
camera.record | needs required parameters; not offered yet |
camera.snapshot | needs required parameters; not offered yet |
Control
type Entity struct
Entity controls one camera entity over HTTP (api.Client) or MQTT (mqtt.Client). State and Subscribe come from the embedded Handle.
Embeds entity.Handle[Attributes], whose methods it has too.
func Get(transport entity.Transport, id string) *Entity
Get returns the camera entity with the given id: an entity id over HTTP (the "camera." prefix may be omitted), a discovery object path or unique id over MQTT. It does no I/O.
func List(ctx context.Context, transport entity.Transport) ([]*Entity, error)
List returns every camera entity the transport can see: all of Home Assistant's over HTTP, the discovered ones over MQTT.
func (e *Entity) DisableMotionDetection(ctx context.Context) error
DisableMotionDetection calls camera.disable_motion_detection. It has no MQTT equivalent. Core describes the service: Disables the motion detection of a camera.
func (e *Entity) EnableMotionDetection(ctx context.Context) error
EnableMotionDetection calls camera.enable_motion_detection. It has no MQTT equivalent. Core describes the service: Enables the motion detection of a camera.
func (e *Entity) TurnOff(ctx context.Context) error
TurnOff calls camera.turn_off. It has no MQTT equivalent. Core describes the service: Turns off a camera.
func (e *Entity) TurnOn(ctx context.Context) error
TurnOn calls camera.turn_on. It has no MQTT equivalent. Core describes the service: Turns on a camera.
type State = entity.State[Attributes]
State is a snapshot of one camera entity.
Serve over MQTT
type Device struct
Device is one camera entity served by this process over MQTT. Close, Delete and ReportAvailability come from the embedded mqtt.Device.
Embeds *mqtt.Device, whose methods it has too.
func NewDevice(ctx context.Context, client *mqtt.Client, objectID string, options ...DeviceOption) (*Device, error)
NewDevice announces a camera entity through MQTT discovery and returns the device serving it. objectID may carry one "node_id/" prefix. Command, state and availability topics default to <topic root>/camera/<objectID>/... and the options can override them. The client must be connected.
func (d *Device) Config() Config
Config returns the discovery config announced to Home Assistant.
type DeviceOption func(config *Config)
DeviceOption customizes the discovery config of a device before it is announced. Options run before the default topics are derived, so a topic they set is kept.
func WithConfig(fn func(config *Config)) DeviceOption
WithConfig applies fn to the discovery config for adjustments not covered by the other options.
func WithDeviceDetails(details ha.MQTTDeviceDetails) DeviceOption
WithDeviceDetails ties the entity to a device in the Home Assistant device registry.
func WithName(name string) DeviceOption
WithName sets the friendly name announced to Home Assistant.
State and values
type Attributes struct
Attributes are the state attributes of a camera entity, under the names Home Assistant publishes them with.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
AccessToken | string | access_token | Access token. |
Brand | *string | brand | Brand. |
Model | *string | model_name | Model. |
MotionDetectionEnabled | bool | motion_detection | Motion detection. |
SupportedFeatures | Feature | supported_features | A set of Feature flags. |
type Capabilities struct
Capabilities is core's CameraCapabilities.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
FrontendStreamTypes | []StreamType | frontend_stream_types | |
TwoWayAudio | bool | two_way_audio |
type EntityCapabilities struct
EntityCapabilities is core's CameraEntityCapabilities.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
TwoWayAudio | bool | two_way_audio |
Feature
type Feature uint64
Feature is a set of camera supported features, with the values of core's CameraEntityFeature: the supported_features attribute decodes into it.
| Constant | Value |
|---|---|
FeatureUnknown | 0 |
FeatureOnOff | 1 << 0 |
FeatureStream | 1 << 1 |
func FeatureFromString(s string) Feature
FeatureFromString returns the Feature spelled s, by its value or by the name of core's member, and FeatureUnknown for anything else.
type RTCConfiguration struct
RTCConfiguration is core's RTCConfiguration.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
IceServers | []RTCIceServer | ice_servers |
type RTCIceServer struct
RTCIceServer is core's RTCIceServer.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
Credential | *string | credential | |
Urls | any | urls | |
Username | *string | username |
StateValue
type StateValue string
StateValue is core's CameraState.
| Constant | Value |
|---|---|
StateValueUnknown | "Unknown" |
StateValueRecording | "recording" |
StateValueStreaming | "streaming" |
StateValueIdle | "idle" |
func StateValueFromString(s string) StateValue
StateValueFromString returns the StateValue spelled s, by its value or by the name of core's member, and StateValueUnknown for anything else.
func (v *StateValue) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling StateValueFromString accepts.
StreamType
type StreamType string
StreamType is core's StreamType.
| Constant | Value |
|---|---|
StreamTypeUnknown | "Unknown" |
StreamTypeHls | "hls" |
StreamTypeWebRtc | "web_rtc" |
func StreamTypeFromString(s string) StreamType
StreamTypeFromString returns the StreamType spelled s, by its value or by the name of core's member, and StreamTypeUnknown for anything else.
func (v *StreamType) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling StreamTypeFromString accepts.
type WebRTCClientConfiguration struct
WebRTCClientConfiguration is core's WebRTCClientConfiguration.
See: https://www.home-assistant.io/integrations/camera/
| Field | Type | Wire key | Description |
|---|---|---|---|
Configuration | RTCConfiguration | configuration | |
DataChannel | *string | data_channel |
MQTT discovery config
type Config struct
Config is the MQTT discovery config of camera.
See: https://www.home-assistant.io/integrations/camera.mqtt/
| Field | Type | Wire key | Description |
|---|---|---|---|
Availability | []ha.MQTTAvailability | availability | |
AvailabilityMode | *string | availability_mode | Allowed: "all", "any", "latest". Default: "latest" |
AvailabilityTemplate | *ha.Template | availability_template | |
AvailabilityTopic | *string | availability_topic | Topic to receive the availability payload on. NewDevice defaults it to <base>/availability. |
DefaultEntityId | *string | default_entity_id | |
Device | *ha.MQTTDeviceDetails | device | |
EnabledByDefault | *bool | enabled_by_default | Default: true |
Encoding | *string | encoding | Default: "utf-8" |
EntityCategory | *string | entity_category | Allowed: "config", "diagnostic". |
EntityPicture | *string | entity_picture | An URL to a picture to be assigned. |
Group | []string | group | |
Icon | *ha.Icon | icon | |
ImageEncoding | *string | image_encoding | Select the encoding of the received image data. Allowed: "b64". |
JsonAttributesTemplate | *ha.Template | json_attributes_template | |
JsonAttributesTopic | *string | json_attributes_topic | The library does not use it: extra attributes in a JSON document, which is not offered yet. |
MessageExpiryInterval | *map[string]any | message_expiry_interval | Retention time interval for published message. |
Name | *string | name | |
Origin | *ha.DeviceOrigin | origin | |
PayloadAvailable | *string | payload_available | The payload that indicates the device is available (defaults to 'online'). Default: "online" |
PayloadNotAvailable | *string | payload_not_available | The payload that indicates the device is not available (defaults to 'offline'). Default: "offline" |
Qos | *int | qos | Default: 0 |
Topic | string | topic | Required. NewDevice defaults it to <base>/image. The library does not use it: carries image bytes, which have no state representation. |
UniqueId | *string | unique_id | |
VisibleByDefault | *bool | visible_by_default | Default: true |
func (*Config) IsMQTTDiscoverySchema()
IsMQTTDiscoverySchema marks Config as a discovery payload (ha.MQTTDiscoverySchema).