homeassistant

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 8 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

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

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

func (*RestClient) GetState

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

func (*RestClient) GetThermostatState

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

func (*RestClient) SetThermostatFanMode

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

func (*RestClient) SetThermostatState

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 Sun added in v0.26.0

type Sun struct {
	AboveHorizon bool
	Rising       bool // True if the Sun is currently rising, after solar midnight and before solar noon

	NextRising      time.Time // Date and time of the next sun rising
	NextRisingToday bool

	NextSetting      time.Time // Date and time of the next sun setting
	NextSettingToday bool

	NextDawn      time.Time // Date and time of the next dawn
	NextDawnToday bool

	NextDusk      time.Time // Date and time of the next dusk
	NextDuskToday bool

	NextNoon      time.Time // Date and time of the next solar noon
	NextNoonToday bool

	NextMidnight      time.Time // Date and time of the next solar midnight
	NextMidnightToday bool

	Elevation float64 // The angle between the sun and the horizon
	Azimuth   float64 // The angle is shown clockwise from north
}

func NewSun added in v0.26.1

func NewSun(sunState StateData) (Sun, error)

func (Sun) DirectnessToWindow added in v0.27.0

func (s Sun) DirectnessToWindow(windowAzimuth float64) float64

How direct is the sun compared to a window with a certain azimuth. I don't know how to find the true angle because I took trig 20+ years ago, so we'll just use the greater between elevation and azimuth.

  • If the sun is straight on (elevation 0, sun azimuth equal to window azimuth), return 1.0
  • If the sun is at a 90 degree angle, return 0.0
  • In-between will return a value between 0.0 and 1.0
  • If the sun is below the horizon or the azimuth difference is greater than 90 degrees, return -1.0

type ThermostatFanMode

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

type ThermostatMode

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

type ThermostatState

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