homeassistant

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Domains = struct {
	Light         string
	Switch        string
	Lock          string
	Cover         string
	Homeassistant string
	Group         string
}{
	Light:         "light",
	Switch:        "switch",
	Lock:          "lock",
	Cover:         "cover",
	Homeassistant: "homeassistant",
	Group:         "group",
}

Home Assistant device domains

View Source
var ExtraProps = struct {
	Transition            string
	Brightness            string
	BrightnessPercent     string
	BrightnessPercentStep string
	HvacMode              string
	FanMode               string
	Temperature           string
	TargetTempHigh        string
	TargetTempLow         string
	Duration              string
	Value                 string
	Position              string
}{
	Transition:            "transition",
	Brightness:            "brightness",
	BrightnessPercent:     "brightness_pct",
	BrightnessPercentStep: "brightness_step_pct",
	HvacMode:              "hvac_mode",
	FanMode:               "fan_mode",
	Temperature:           "temperature",
	TargetTempHigh:        "target_temp_high",
	TargetTempLow:         "target_temp_low",
	Duration:              "duration",
	Value:                 "value",
	Position:              "position",
}

Extra props that can be sent when calling a Home Assistant service

View Source
var MessageType = struct {
	AuthRequired    string
	AuthOk          string
	AuthInvalid     string
	Result          string
	Event           string
	ZhaEvent        string
	ZwaveEvent      string
	SubscribeEvents string
	StateChanged    string
	TagScanned      string
	TimerStarted    string
	TimerFinished   string
}{
	AuthRequired:    "auth_required",
	AuthOk:          "auth_ok",
	AuthInvalid:     "auth_invalid",
	Result:          "result",
	Event:           "event",
	ZhaEvent:        "zha_event",
	ZwaveEvent:      "zwave_js_value_notification",
	SubscribeEvents: "subscribe_events",
	StateChanged:    "state_changed",
	TagScanned:      "tag_scanned",
	TimerStarted:    "timer.started",
	TimerFinished:   "timer.finished",
}

Message types that can be returned from Home Assistants websocket API

View Source
var Services = struct {
	TurnOn           string
	TurnOff          string
	Toggle           string
	Reload           string
	Lock             string
	Unlock           string
	OpenCover        string
	CloseCover       string
	StopCover        string
	SelectOption     string
	SetHvacMode      string
	SetFanMode       string
	SetTemperature   string
	SetValue         string
	Start            string
	Change           string
	Cancel           string
	SetCoverPosition string
}{
	TurnOn:           "turn_on",
	TurnOff:          "turn_off",
	Toggle:           "toggle",
	Reload:           "reload",
	Lock:             "lock",
	Unlock:           "unlock",
	OpenCover:        "open_cover",
	CloseCover:       "close_cover",
	StopCover:        "stop_cover",
	SelectOption:     "select_option",
	SetHvacMode:      "set_hvac_mode",
	SetFanMode:       "set_fan_mode",
	SetTemperature:   "set_temperature",
	SetValue:         "set_value",
	Start:            "start",
	Change:           "change",
	Cancel:           "cancel",
	SetCoverPosition: "set_cover_position",
}

Home Assistant services

Functions

func BoolToService

func BoolToService(entityId string, desiredState bool) string

BoolToService converts a boolean into the appropriate service string

For locks: true becomes "unlock" and false becomes "lock"
For covers: true becomes "open_cover" and false becomes "close_cover"
For all others: true becomes "turn_on" and false becomes "turn_off"

func ParseDuration

func ParseDuration(d string) (time.Duration, error)

Parse a Home Assistant duration in HH:MM:SS format

func StateToBool

func StateToBool(state string) bool

StateToBool converts a state string into a boolean

States that return true: "on", "home", "open", "opening", "unlocked", "playing", "active", "good",
	"walking", "charging", "alive", "heat", "heat_cool", "cool", "above_horizon", numbers > 0
All others return false

Types

type AuthMessage

type AuthMessage struct {
	Type        string `json:"type"`
	AccessToken string `json:"access_token,omitempty"`
}

type CallServiceInput added in v0.14.0

type CallServiceInput struct {
	EntityID string
	Service  string
	Extras   map[string]any
}

type Event

type Event struct {
	Data      EventData `json:"data,omitempty"`
	EventType string    `json:"event_type,omitempty"`
	TimeFired string    `json:"time_fired,omitempty"`
	Origin    string    `json:"origin,omitempty"`
}

type EventData

type EventData struct {
	EntityId string    `json:"entity_id,omitempty"`
	NewState StateData `json:"new_state,omitempty"`
	OldState StateData `json:"old_state,omitempty"`

	// ZHA
	DeviceIeee string      `json:"device_ieee,omitempty"`
	DeviceId   string      `json:"device_id,omitempty"`
	Command    string      `json:"command,omitempty"`
	Args       interface{} `json:"args,omitempty"`
	Params     interface{} `json:"params,omitempty"`

	// NFC
	TagId string `json:"tag_id,omitempty"`

	// ZwaveJS Scene
	Domain           string `json:"domain,omitempty"`
	NodeID           int    `json:"node_id,omitempty"`
	Endpoint         int    `json:"endpoint,omitempty"`
	CommandClass     int    `json:"command_class,omitempty"`
	CommandClassName string `json:"command_class_name,omitempty"`
	Label            string `json:"label,omitempty"`
	Property         string `json:"property,omitempty"`
	PropertyName     string `json:"property_name,omitempty"`
	PropertyKey      string `json:"property_key,omitempty"`
	PropertyKeyName  string `json:"property_key_name,omitempty"`
	Value            string `json:"value,omitempty"`
	ValueRaw         int    `json:"value_raw,omitempty"`
}

type HassMessage

type HassMessage struct {
	Type        string `json:"type"`
	Version     string `json:"ha_version,omitempty"`
	AccessToken string `json:"access_token,omitempty"`
	Message     string `json:"message,omitempty"`
	Success     bool   `json:"success,omitempty"`
	Result      Result `json:"result,omitempty"`
	EventType   string `json:"event_type,omitempty"`
	Event       Event  `json:"event,omitempty"`
	Id          int    `json:"id,omitempty"`
}

type RestClient

type RestClient struct {
	// contains filtered or unexported fields
}

func NewRestClient

func NewRestClient(baseUrl, token string) *RestClient

func (*RestClient) CallService

func (c *RestClient) CallService(entityId string, service string, extras ...map[string]any) error

func (*RestClient) CallServiceManual

func (c *RestClient) CallServiceManual(domain string, entityId string, service string, extras ...map[string]any) error

func (*RestClient) CallServices added in v0.14.0

func (c *RestClient) CallServices(inputs ...*CallServiceInput) error

func (*RestClient) GetState

func (c *RestClient) GetState(entityId string) (StateData, error)

func (*RestClient) GetThermostatState added in v0.17.0

func (c *RestClient) GetThermostatState(entityId string) (output ThermostatState, err error)

func (*RestClient) SetThermostatFanMode added in v0.17.0

func (c *RestClient) SetThermostatFanMode(entityId string, mode ThermostatFanMode) error

func (*RestClient) SetThermostatState added in v0.17.0

func (c *RestClient) SetThermostatState(entityId string, desiredState ThermostatState) error

type Result

type Result struct {
	Context ResultContext `json:"context,omitempty"`
}

type ResultContext

type ResultContext struct {
	Id string `json:"id,omitempty"`
}

type StateData

type StateData struct {
	LastChanged string                 `json:"last_changed,omitempty"`
	LastUpdated string                 `json:"last_updated,omitempty"`
	State       string                 `json:"state,omitempty"`
	Attributes  map[string]interface{} `json:"attributes,omitempty"`
	Context     interface{}            `json:"context,omitempty"`
}

type SubscribeEventsMessage

type SubscribeEventsMessage struct {
	Type      string `json:"type"`
	EventType string `json:"event_type"`
	Id        int    `json:"id"`
}

type ThermostatFanMode added in v0.17.0

type ThermostatFanMode string
const ThermostatFanModeAuto ThermostatFanMode = "Auto low"
const ThermostatFanModeLow ThermostatFanMode = "Low"

type ThermostatMode added in v0.17.0

type ThermostatMode string
const ThermostatModeCool ThermostatMode = "cool"
const ThermostatModeHeat ThermostatMode = "heat"
const ThermostatModeHeatCool ThermostatMode = "heat_cool"
const ThermostatModeOff ThermostatMode = "off"

type ThermostatState added in v0.17.0

type ThermostatState struct {
	Mode           ThermostatMode
	FanMode        ThermostatFanMode
	TargetTempHigh float64
	TargetTempLow  float64
}

Jump to

Keyboard shortcuts

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