Documentation
¶
Index ¶
- Variables
- func BoolToService(entityId string, desiredState bool) string
- func HistoryEndTimestamp(value time.Time) rsty.RestyOption
- func HistoryEntityFilter(entityIds ...string) rsty.RestyOption
- func HistoryMinimalResponse() rsty.RestyOption
- func HistoryNoAttributes() rsty.RestyOption
- func HistorySignificantOnly() rsty.RestyOption
- func HistoryStartTimestamp(value time.Time) rsty.RestyOption
- func ParseDuration(d string) (time.Duration, error)
- func StateToBool(state string) bool
- type AuthMessage
- type CallServiceInput
- type Event
- type EventData
- type HassMessage
- type HistoryEntry
- type HistoryResponse
- type RestClient
- func (c *RestClient) CallService(entityId string, service string, extras ...map[string]any) error
- func (c *RestClient) CallServiceManual(domain string, entityId string, service string, extras ...map[string]any) error
- func (c *RestClient) CallServices(inputs ...*CallServiceInput) error
- func (c *RestClient) GetHistory(opts ...rsty.RestyOption) (HistoryResponse, error)
- func (c *RestClient) GetState(entityId string) (StateData, error)
- func (c *RestClient) GetThermostatState(entityId string) (output ThermostatState, err error)
- func (c *RestClient) SetThermostatFanMode(entityId string, mode ThermostatFanMode) error
- func (c *RestClient) SetThermostatState(entityId string, desiredState ThermostatState) error
- type Result
- type ResultContext
- type StateData
- type SubscribeEventsMessage
- type Sun
- type ThermostatFanMode
- type ThermostatMode
- type ThermostatState
Constants ¶
This section is empty.
Variables ¶
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
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
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
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 ¶
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 HistoryEndTimestamp ¶ added in v0.30.0
func HistoryEndTimestamp(value time.Time) rsty.RestyOption
End time of history results. If not set, API defaults to 1 day after start
func HistoryEntityFilter ¶ added in v0.30.0
func HistoryEntityFilter(entityIds ...string) rsty.RestyOption
func HistoryMinimalResponse ¶ added in v0.30.0
func HistoryMinimalResponse() rsty.RestyOption
func HistoryNoAttributes ¶ added in v0.30.0
func HistoryNoAttributes() rsty.RestyOption
func HistorySignificantOnly ¶ added in v0.30.0
func HistorySignificantOnly() rsty.RestyOption
func HistoryStartTimestamp ¶ added in v0.30.0
func HistoryStartTimestamp(value time.Time) rsty.RestyOption
Start time of history results. If not set, API defaults to 1 day before now
func ParseDuration ¶
Parse a Home Assistant duration in HH:MM:SS format
func StateToBool ¶
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 CallServiceInput ¶
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"` }
func (EventData) GetDeviceFriendlyName ¶ added in v0.28.0
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 HistoryEntry ¶ added in v0.30.0
type HistoryResponse ¶ added in v0.30.0
type HistoryResponse [][]HistoryEntry
func (HistoryResponse) GetOnDuration ¶ added in v0.30.0
func (r HistoryResponse) GetOnDuration(onState, offState string) (time.Duration, error)
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
func NewRestClient ¶
func NewRestClient(baseUrl, token string) *RestClient
func (*RestClient) CallService ¶
func (*RestClient) CallServiceManual ¶
func (*RestClient) CallServices ¶
func (c *RestClient) CallServices(inputs ...*CallServiceInput) error
func (*RestClient) GetHistory ¶ added in v0.30.0
func (c *RestClient) GetHistory(opts ...rsty.RestyOption) (HistoryResponse, 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"` }
func (StateData) GetFriendlyName ¶ added in v0.28.0
func (StateData) GetLastChanged ¶ added in v0.30.0
func (StateData) GetStringAttribute ¶ added in v0.28.0
type SubscribeEventsMessage ¶
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 (Sun) DirectnessToWindow ¶ added in v0.27.0
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 }