domoto

package module
v0.0.0-...-e34503f Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: BSD-2-Clause Imports: 5 Imported by: 0

README

go-domoto

go-domoto is a Golang library for accessing the Domoticz HTTP API.

Usage

Usage is simple:

c := domoto.New("http://localhost:8080","username","password")
res, err := c.AllDevices("")

or

res, err := c.DeviceToggle(1)

A more complete example is an implementation of a CLI here: https://github.com/pawal/domo-cli

Documentation

https://godoc.org/github.com/pawal/go-domoto

Documentation

Overview

Package domoto adds a Golang interface for the Domoticz JSON HTTP API. All API calls are done through the handle returned by New. The Go API implements parts of the Domoticz API documentation: https://www.domoticz.com/wiki/Domoticz_API/JSON_URL%27s

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	BaseURL string
	// contains filtered or unexported fields
}

Config is the configuration for executing calls to the Domoticz JSON HTTP API.

func New

func New(baseURL, user, pass string) *Config

New creates a HTTP handler for calling the Domoticz JSON API. Add the base URL, username and password, these will be used for any calls using the handler.

func (*Config) AllDevices

func (c *Config) AllDevices(filter string) (d Devices, err error)

AllDevices retrieves all devices, optionally with a filter Filter types:

light = Get all lights/switches
weather = Get all weather devices
temp = Get all temperature devices
utility = Get all utility devices

Leave filter with an empty or other string for all devices.

func (*Config) AllScenes

func (c *Config) AllScenes() (s Scenes, err error)

AllScenes returns all scenes and groups

func (*Config) Call

func (c *Config) Call(qp *map[string]string) (resp *resty.Response, err error)

Call Domoticz API input is a map of query parameters for the API

func (*Config) Device

func (c *Config) Device(id int) (d Device, err error)

Device retrieves a device with its id

func (*Config) DeviceSwitch

func (c *Config) DeviceSwitch(id int, cmd string) (res Result, err error)

DeviceSwitch switches on or off a device switch cmd is either "On" or "Off"

func (*Config) DeviceToggle

func (c *Config) DeviceToggle(id int) (res Result, err error)

DeviceToggle toggles a device switch, on or off Result is the same as for a Device switch

func (*Config) SceneDevices

func (c *Config) SceneDevices(id int) (s SceneDevices, err error)

SceneDevices returns all devices in scenes and groups

func (*Config) SceneSwitch

func (c *Config) SceneSwitch(id int, cmd string) (res Result, err error)

SceneSwitch turns a scene or group on/off cmd is either "On" or "Off", scenes can only be turned on

func (*Config) SceneTimers

func (c *Config) SceneTimers(id int) (res SceneTimers, err error)

SceneTimers list all timers for a scene or group

type Device

type Device struct {
	AddjMulti         float64 `json:"AddjMulti,omitempty"`
	AddjMulti2        float64 `json:"AddjMulti2,omitempty"`
	AddjValue         float64 `json:"AddjValue,omitempty"`
	AddjValue2        float64 `json:"AddjValue2,omitempty"`
	BatteryLevel      int     `json:"BatteryLevel,omitempty"`
	CustomImage       int     `json:"CustomImage,omitempty"`
	Data              string  `json:"Data,omitempty"`
	Description       string  `json:"Description,omitempty"`
	Favorite          int     `json:"Favorite,omitempty"`
	HardwareID        int     `json:"HardwareID,omitempty"`
	HardwareName      string  `json:"HardwareName,omitempty"`
	HardwareType      string  `json:"HardwareType,omitempty"`
	HardwareTypeVal   int     `json:"HardwareTypeVal,omitempty"`
	HaveDimmer        bool    `json:"HaveDimmer,omitempty"`
	HaveGroupCmd      bool    `json:"HaveGroupCmd,omitempty"`
	HaveTimeout       bool    `json:"HaveTimeout,omitempty"`
	ID                string  `json:"ID"`
	Image             string  `json:"Image,omitempty"`
	IsSubDevice       bool    `json:"IsSubDevice,omitempty"`
	LastUpdate        string  `json:"LastUpdate,omitempty"`
	Level             int     `json:"Level,omitempty"`
	LevelInt          int     `json:"LevelInt,omitempty"`
	MaxDimLevel       int     `json:"MaxDimLevel,omitempty"`
	Name              string  `json:"Name"`
	Notifications     string  `json:"Notifications,omitempty"`
	PlanID            string  `json:"PlanID,omitempty"`
	PlanIDs           []int   `json:"PlanIDs,omitempty"`
	Protected         bool    `json:"Protected"`
	ShowNotifications bool    `json:"ShowNotifications,omitempty"`
	SignalLevel       string  `json:"-"`
	Status            string  `json:"Status,omitempty"`
	StrParam1         string  `json:"StrParam1,omitempty"`
	StrParam2         string  `json:"StrParam2,omitempty"`
	SubType           string  `json:"SubType,omitempty"`
	SwitchType        string  `json:"SwitchType,omitempty"`
	SwitchTypeVal     int     `json:"SwitchTypeVal,omitempty"`
	Timers            string  `json:"Timers,omitempty"`
	Type              string  `json:"Type"`
	TypeImg           string  `json:"TypeImg,omitempty"`
	Unit              int     `json:"Unit"`
	Used              int     `json:"Used"`
	UsedByCamera      bool    `json:"UsedByCamera,omitempty"`
	XOffset           string  `json:"XOffset,omitempty"`
	YOffset           string  `json:"YOffset,omitempty"`
	Idx               string  `json:"idx"`
}

Device is the struct for a single device

type Devices

type Devices struct {
	ActTime    int      `json:"ActTime"`
	ServerTime string   `json:"ServerTime"`
	Sunrise    string   `json:"Sunrise"`
	Sunset     string   `json:"Sunset"`
	Devices    []Device `json:"result"`
	Status     string   `json:"status"`
	Title      string   `json:"title"`
}

Devices is a struct for the device listings

type Result

type Result struct {
	Message string `json:"message"`
	Status  string `json:"status"`
	Title   string `json:"title"`
}

Result is the result of an action:

{
   "status" : "OK",
   "title" : "SwitchLight"
}

OR

{
   "message" : "WRONG CODE",
   "status" : "ERROR",
   "title" : "SwitchLight"
}

type Scene

type Scene struct {
	Favorite   int    `json:"Favorite"`
	HardwareID int    `json:"HardwareID"`
	LastUpdate string `json:"LastUpdate"`
	Name       string `json:"Name"`
	Status     string `json:"Status"`
	Timers     string `json:"Timers"`
	Type       string `json:"Type"`
	Idx        string `json:"idx"`
}

Scene is the description of a scene

type SceneDevices

type SceneDevices struct {
	Result []struct {
		Command    string `json:"Command"`
		DevID      string `json:"DevID"`
		DevRealIdx string `json:"DevRealIdx"`
		Hue        int    `json:"Hue"`
		ID         string `json:"ID"`
		Level      int    `json:"Level"`
		Name       string `json:"Name"`
		OffDelay   int    `json:"OffDelay"`
		OnDelay    int    `json:"OnDelay"`
		Order      int    `json:"Order"`
		SubType    string `json:"SubType"`
		Type       string `json:"Type"`
	} `json:"result"`
	Status string `json:"status"`
	Title  string `json:"title"`
}

SceneDevices is the list of all devices in a scene/group

type SceneTimer

type SceneTimer struct {
	Active     string `json:"Active"`
	Cmd        int    `json:"Cmd"`
	Date       string `json:"Date"`
	Days       int    `json:"Days"`
	Hue        int    `json:"Hue"`
	Level      int    `json:"Level"`
	Randomness bool   `json:"Randomness"`
	Time       string `json:"Time"`
	Type       int    `json:"Type"`
	Idx        string `json:"idx"`
}

SceneTimer is a timer for a scene

type SceneTimers

type SceneTimers struct {
	Timers []SceneTimer `json:"result"`
	Status string       `json:"status"`
	Title  string       `json:"title"`
}

SceneTimers is a list of all the scene timers

type Scenes

type Scenes struct {
	Scene  []Scene `json:"result"`
	Status string  `json:"status"`
	Title  string  `json:"title"`
}

Scenes is a list of all the scenes

Jump to

Keyboard shortcuts

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