lutron

package module
v0.0.0-...-6d4d7b0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

README

golang package to communicate with Lutron's RadioRA2 devices.

Start a conenction with the main repeater, selecting a user id dedicated to this application:

conn, err := lutron.Dial("192.168.1.5", "lutron", "integration")

To dim specific lights:

// fade switch "8" to 25% over 2 seconds
a := conn.Dimmer(8).Fade(25, 2*time.Second)

// fade switch "11" to 33% over 0.50 seconds
b := conn.Dimmer(11).Fade(33, 500*time.Millisecond)

// wait for prior fades to complete
<- a
<- b

Virtually press a button on a keypad, selecting its scene, and wait for the command to be acknowledged:

k := conn.Keypad(4)
<- k.Button(1).Press()

Listen to a keypad button, e.g. for custom behavior:

k := conn.Keypad(4)
fivePressed := k.Button(5).Monitor()
for {
  select {
  case <-fivePressed:
    k.Button(5).SetLed(lutron.LedOff)
    musicPlayer.Stop()
  }
}

Documentation

Overview

Package lutron interfaces with Lutron RadioRA2 home automation.

Applications can monitor lighting levels, monitor keypad LEDs, respond to keypad presses, and manage unprogrammed LEDs.

Index

Constants

View Source
const (
	ButtonPress   = 3
	ButtonRelease = 4

	// Valid states for an LED on a keypad.
	LedOff         = 0
	LedOn          = 1
	LedNormalFlash = 2 // 1 flash every second.
	LedRapidFlash  = 3 // 10 flashes every second.
	LedUndefined   = 255

	// IDs of buttons on a Pico remote "keypad".
	PicoButtonOn     = 2
	PicoButtonPreset = 3
	PicoButtonOff    = 4
	PicoButtonRaise  = 5
	PicoButtonLower  = 6
)
View Source
const (
	DefaultFade = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	Conn *Conn
	// contains filtered or unexported fields
}

Any RadioRA2 compatible device.

func (*Component) Execute

func (d *Component) Execute(rest string)

Sends a command of the form "#<command>,<id>,<rest>" to the repeater.

func (*Component) Id

func (d *Component) Id() int

Integration id used to address the device through the main repeater. Ids are assigned by the RadioRA2 software and must be looked up on the integration report.

func (*Component) Query

func (d *Component) Query(rest string)

Sends a query of the form "?<command>,<id>,<rest>" to the repeater. The repeater will reply in the future with "~<command>,<id>,...".

type Conn

type Conn struct {
	Trace bool
	// contains filtered or unexported fields
}

func Dial

func Dial(addr, user, pass string) (*Conn, error)

func (*Conn) AddDimmerMonitor

func (c *Conn) AddDimmerMonitor(m chan LevelChange)

Adds a channel to receive updates when any dimmer is adjusted. The current level of every known dimmer will be sent on the channel.

Monitoring all dimmers is useful for logging lighting usage over time. Specific dimmer monitoring simplifies reacting to lighting changes with other automated actions. To monitor only specific dimmers use:

m := c.Dimmer(id).Monitor()

or

c.Dimmer(id).AddMonitor(m)

func (*Conn) Dimmer

func (c *Conn) Dimmer(id int) *Dimmer

Get a reference to a Maestro style dimmer, switch or hybrid keypad. The integration id must be obtained from the RadioRA2 software.

func (*Conn) HybridKeypad

func (c *Conn) HybridKeypad(id int) *HybridKeypad

Get a reference to a hybrid keypad. This is a union of the Dimmer and Keypad objects on the same integration id. Callers may either use the HybridKeypad object, or access the Dimmer and Keypad directly. The integration id must be obtained from the RadioRA2 software.

func (*Conn) Keypad

func (c *Conn) Keypad(id int) *Keypad

Get a reference to a seeTouch keypad, hybrid keypad, or Pico remote. The integration id must be obtained from the RadioRA2 software.

func (*Conn) Switch

func (c *Conn) Switch(id int) *Switch

Get a reference to a Maestro style switch. This is a lightweight simplified API wrapper around the same numbered Dimmer object. The integration id must be obtained from the RadioRA2 software.

type Dimmer

type Dimmer struct {
	Component
	// contains filtered or unexported fields
}

Maestro style dimmer (RRD-6CL, RRD-6NA, RRD-10ND, ...).

Switches (RRD-8ANS) are also supported, but may be better accessed using the simplified Switch wrapper type.

func (*Dimmer) AddMonitor

func (d *Dimmer) AddMonitor(c chan LevelChange)

Adds a channel to receive updates when the dimmer is adjusted.

func (*Dimmer) DefaultFade

func (d *Dimmer) DefaultFade() time.Duration

Get the duration used to adjust the lighting level.

func (*Dimmer) Fade

func (d *Dimmer) Fade(level uint8, fade time.Duration) chan uint8

Set the level (0-100) over the fade duration, sending the new level on the returned channel when the main repeater has acknowledged it.

func (*Dimmer) Level

func (d *Dimmer) Level() chan uint8

Get the level of the dimmer and send it once on the returned channel. If the dimmer's level has not yet been observed it will be queried and the value will be sent after the main repeater has replied.

func (*Dimmer) Monitor

func (d *Dimmer) Monitor() chan LevelChange

Creates a new channel receiving updates when the dimmer is adjusted.

func (*Dimmer) Off

func (d *Dimmer) Off() chan uint8

Fade the dimmer to off (0%), sending the new level when acknowledged.

func (*Dimmer) On

func (d *Dimmer) On() chan uint8

Raise the dimmer to on (100%), sending the new level when acknowledged.

func (*Dimmer) ReadLevel

func (d *Dimmer) ReadLevel() chan uint8

Get the level of the dimmer directly from the main repeater and send it once on the returned channel. ReadLevel() takes longer than Level() as the read must be performed remotely on the main repeater.

func (*Dimmer) SetDefaultFade

func (d *Dimmer) SetDefaultFade(fade time.Duration)

Set the duration for adjusting the lighting level.

func (*Dimmer) SetLevel

func (d *Dimmer) SetLevel(level uint8) chan uint8

Set the level (0-100), sending the new level on the returned channel when the main repeater has acknowledged it.

type HybridKeypad

type HybridKeypad struct {
	*Dimmer
	*Keypad
}

Hybrid keypads contain both a dimmer and a keypad. The dimmer controls the lighting load wired into the back of the hybrid keypad component, while the keys on the face can be programmed for any purpose.

type Keypad

type Keypad struct {
	Component
	// contains filtered or unexported fields
}

func (*Keypad) Button

func (k *Keypad) Button(button uint8) *KeypadButton

Create a reference to a button on the keypad. Buttons are numbered 1-N. See integration guide for mapping, e.g. 1B keypads use only button 4.

type KeypadButton

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

func (*KeypadButton) Monitor

func (b *KeypadButton) Monitor() chan uint8

Creates a new channel receiving ButtonPress each time the button is pressed. ButtonRelease events are not sent.

func (*KeypadButton) MonitorButton

func (b *KeypadButton) MonitorButton() chan uint8

Creates a new channel receiving ButtonPress followed by ButtonRelease each time the button is pressed. The common usage is to monitor only ButtonPress with Monitor() as most callers do not need to observe ButtonRelease.

func (*KeypadButton) MonitorLed

func (b *KeypadButton) MonitorLed(events ...uint8) chan uint8

Creates a new channel receiving LED state change events. Monitoring LEDs can be a useful way to react when a specific scene is selected or lights in a room are turned on or turned off. If no events are selected LedOff and LedOn will be selected by default.

func (*KeypadButton) Press

func (b *KeypadButton) Press() chan uint8

Press the button on the keypad by sending ButtonPress immediately followed by ButtonRelease. The returned channel is signaled once with ButtonRelease when the repeater has acknowledged the action.

If the application is monitoring the button the monitoring channel(s) will also be signaled as the repeater acknowledges the action.

func (*KeypadButton) SetLed

func (b *KeypadButton) SetLed(state uint8) chan uint8

Set the state of a button's LED to LedOn, LedOff, LedNormalFlash or LedRapidFlash. LED states can only be set if the button is unconfigured in the RadioRA2 software.

type LedGroup

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

Collection of keypad buttons that should behave like radio buttons. At most one button in the group should have LedOn state.

func NewLedGroup

func NewLedGroup(buttons ...*KeypadButton) *LedGroup

Create a "radio group" of keypad buttons. Select() can be used to set LedOn for one button and LedOff for the others in the group.

func (*LedGroup) Select

func (g *LedGroup) Select(sel *KeypadButton) *PendingLedUpdates

"Select" one button from a group of buttons by turning on the selected button's LED and turning off all other LEDs in the group. A wait object is returned to allow the caller to wait for the updates to process.

Selecting nil will turn off all LEDs in the group.

type LevelChange

type LevelChange struct {
	// Dimmer (or switch) whose lighting load has changed.
	Dimmer *Dimmer

	// New level, 0 (off) to 100 (fully on).
	Level uint8
}

type PendingLedUpdates

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

Partial results after selecting an LED in a group.

func (*PendingLedUpdates) Wait

func (u *PendingLedUpdates) Wait()

Wait for LED updates to be acknowledged by the main repeater.

type Switch

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

Maestro style switch (RRD-8ANS). Switches are modeled as dimmers that have only two levels, 0 (off) and 100 (on). The switch type is a lightweight wrapper around the dimmer to simplify its API.

Maestro style dimmers (RRD-6CL, RRD-6NA, RRD-10ND, ...) are also supported by this type, but are limited to "instant full on" and "instant full off". To access the dimming controls, use Dimmer.

func (*Switch) AddMonitor

func (s *Switch) AddMonitor(c chan LevelChange)

Adds a channel to receive updates when the dimmer is adjusted. For a switch any non-zero level means "on", while 0 means "off".

func (*Switch) IsOn

func (s *Switch) IsOn() chan uint8

Get the status of the switch and send it once on the returned channel. If the switch's level has not yet been observed it will be queried and the value will be sent after the main repeater has replied. For a switch any non-zero level means "on", while 0 means "off".

func (*Switch) Monitor

func (s *Switch) Monitor() chan LevelChange

Creates a new channel receiving updates when the switch is adjusted. For a switch any non-zero level means "on", while 0 means "off".

func (*Switch) Off

func (s *Switch) Off() chan uint8

Turn off the switched load, sending a value when acknowledged.

func (*Switch) On

func (s *Switch) On() chan uint8

Turn on the switched load, sending a value when acknowledged.

func (*Switch) ReadIsOn

func (s *Switch) ReadIsOn() chan uint8

Get the status of the switch directly from the main repeater and send it once on the returned channel. ReadIsOn() takes longer than IsOn() as the read must be performed remotely on the main repeater. For a switch any non-zero level means "on", while 0 means "off".

Jump to

Keyboard shortcuts

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