homeassistant

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

homeassistant implements an API client for Home Assistant API https://developers.home-assistant.io/docs/api/rest/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallResponse

type CallResponse = haschema.CallResponse

type Client

type Client struct {
	*client.Client
}

func New

func New(endPoint, apiKey string, opts ...client.ClientOpt) (*Client, error)

func (*Client) Call

func (c *Client) Call(ctx context.Context, domain, service string, serviceData map[string]any) ([]*haschema.State, error)

Call a service for an entity. The serviceData map is sent as the JSON request body and typically includes "entity_id" plus any service-specific fields. Returns a list of states that changed while the service was being executed.

func (*Client) CallWithResponse

func (c *Client) CallWithResponse(ctx context.Context, domain, service string, serviceData map[string]any) (*CallResponse, error)

CallWithResponse calls a service and returns both changed states and service response data. Use this for services that support returning response data (e.g. weather.get_forecasts).

func (*Client) Config

func (c *Client) Config(ctx context.Context) (*Config, error)

Config returns the current server configuration.

func (*Client) DeleteState

func (c *Client) DeleteState(ctx context.Context, entityId string) error

DeleteState removes an entity from Home Assistant.

func (*Client) Domains

func (c *Client) Domains(ctx context.Context) ([]*Domain, error)

Domains returns all domains and their associated service objects

func (*Client) Events

func (c *Client) Events(ctx context.Context) ([]Event, error)

Events returns all the events and number of listeners

func (*Client) FireEvent

func (c *Client) FireEvent(ctx context.Context, eventType string, eventData map[string]any) (string, error)

FireEvent fires an event with the given type. Optional event data can be passed as a map. Returns a confirmation message.

func (*Client) Health

func (c *Client) Health(ctx context.Context) (string, error)

Health returns "API Running" if the Home Assistant API is reachable

func (*Client) Services

func (c *Client) Services(ctx context.Context, domain string) ([]*Service, error)

Return callable services for a domain

func (*Client) SetState

func (c *Client) SetState(ctx context.Context, entityId, state string, attributes map[string]any) (*schema.State, error)

SetState creates or updates the state of an entity. The state string is required; attributes is optional. Returns the resulting state object. Note: This sets the representation within Home Assistant — it does not communicate with the actual device. Use Call() to actuate a device.

func (*Client) State

func (c *Client) State(ctx context.Context, EntityId string) (*schema.State, error)

State returns a state for a specific entity

func (*Client) States

func (c *Client) States(ctx context.Context) ([]*schema.State, error)

States returns all the entities and their state

func (*Client) Template

func (c *Client) Template(ctx context.Context, template string) (string, error)

Template renders a Home Assistant Jinja2 template and returns the result as plain text. See https://www.home-assistant.io/docs/configuration/templating

type Config

type Config struct {
	Components    []string       `json:"components"`
	ConfigDir     string         `json:"config_dir"`
	Elevation     float64        `json:"elevation"`
	Latitude      float64        `json:"latitude"`
	Longitude     float64        `json:"longitude"`
	LocationName  string         `json:"location_name"`
	TimeZone      string         `json:"time_zone"`
	UnitSystem    map[string]any `json:"unit_system"`
	Version       string         `json:"version"`
	ExternalDirs  []string       `json:"whitelist_external_dirs,omitempty"`
	AllowlistDirs []string       `json:"allowlist_external_dirs,omitempty"`
	AllowlistURLs []string       `json:"allowlist_external_urls,omitempty"`
	Currency      string         `json:"currency,omitempty"`
	Country       string         `json:"country,omitempty"`
	Language      string         `json:"language,omitempty"`
	SafeMode      bool           `json:"safe_mode,omitempty"`
	State         string         `json:"state,omitempty"`
	InternalURL   string         `json:"internal_url,omitempty"`
	ExternalURL   string         `json:"external_url,omitempty"`
	RecoveryMode  bool           `json:"recovery_mode,omitempty"`
}

Config represents the Home Assistant server configuration.

func (Config) String

func (v Config) String() string

type Domain

type Domain = haschema.Domain

type Event

type Event = haschema.Event

type Field

type Field = haschema.Field

type Selector

type Selector = haschema.Selector

type Service

type Service = haschema.Service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL