...

Package hkknx

import("hkknx")
Overview
Index
Examples

Overview ▾

Package hkknx provides functionality to create powerful automations for KNX smart homes.

Index ▾

func AtSunrise(offset time.Duration, weekdays ...time.Weekday) <-chan time.Time
func AtSunset(offset time.Duration, weekdays ...time.Weekday) <-chan time.Time
func AtTime(hour, minute, second int, weekdays ...time.Weekday) <-chan time.Time
func DPT1(v bool) dpt.Value
func DPT13(v int32) dpt.Value
func DPT14(v float32) dpt.Value
func DPT14056(v float32) dpt.Value
func DPT5001(v float32) dpt.Value
func DPT5003(v float32) dpt.Value
func DPT5004(v int) dpt.Value
func DPT5010(v int) dpt.Value
func DPT7001(v int) dpt.Value
func DPT7012(v int) dpt.Value
func DPT7013(v int) dpt.Value
func DPT9001(v float32) dpt.Value
func DPT9004(v float32) dpt.Value
func DPT9005(v float32) dpt.Value
func DPT9007(v float32) dpt.Value
func DPT9008(v float32) dpt.Value
func DPT9021(v float32) dpt.Value
func GroupRead(addr string) (buf []byte, err error)
func GroupReadBool(addr string) (b bool, err error)
func GroupReadNotify(addr string) <-chan interface{}
func GroupResponse(v interface{}, addr ...string) (err error)
func GroupWrite(v interface{}, addrs ...string) (err error)
func GroupWriteBoolNotify(addr string) <-chan bool
func GroupWriteNotify(addr string) <-chan []byte
func GroupWriteTelegramNotify(patterns ...string) <-chan Telegram
func ParseBool(buf []byte) bool
func ParseDPT1(buf []byte) bool
func ParseDPT13(buf []byte) int32
func ParseDPT14(buf []byte) float32
func ParseDPT14056(buf []byte) float32
func ParseDPT5001(buf []byte) float32
func ParseDPT5003(buf []byte) float32
func ParseDPT5004(buf []byte) int
func ParseDPT5010(buf []byte) int
func ParseDPT7001(buf []byte) int
func ParseDPT7012(buf []byte) int
func ParseDPT7013(buf []byte) int
func ParseDPT9001(buf []byte) float32
func ParseDPT9004(buf []byte) float32
func ParseDPT9005(buf []byte) float32
func ParseDPT9007(buf []byte) float32
func ParseDPT9008(buf []byte) float32
func ParseDPT9021(buf []byte) float32
func ParseString(buf []byte) string
func Send(notification *Notification, deviceNames ...string) error
func SendNotification(title string, message string, deviceNames ...string) error
type DailyWeather
    func GetDailyWeather() ([]*DailyWeather, error)
    func (w DailyWeather) RainVolume() float64
    func (w DailyWeather) SnowVolume() float64
type DailyWeatherTemp
type Notification
type RainVolume
    func (v RainVolume) String() string
type SnowVolume
    func (v SnowVolume) String() string
type Telegram
type Weather
    func GetCurrentWeather() (*Weather, error)
    func GetHourlyWeather() ([]*Weather, error)
    func (w Weather) RainVolume() float64
    func (w Weather) SnowVolume() float64
type WeekdayTime
    func ParseDPT10001(buf []byte) WeekdayTime

Package files

hkknx.go

func AtSunrise

func AtSunrise(offset time.Duration, weekdays ...time.Weekday) <-chan time.Time

AtSunrise returns a channel, which waits until sunrise + offset and then returns the current time. If weekdays are specified the channel returns the time only on those weekdays. If no weekdays are specified, the channel returns time everyday.

The time when sunrise happens is calculated based on the location (latitude, longitude) specified in the settings. The default location of Linz (Austria) is used, if no location is specified.

Example

This example shows how to wait until 45 minutes before sunrise.

Code:

var ch = hkknx.AtSunrise(-45 * time.Minute)
for {
    <-ch
    println("it's 45 minutes before sunrise")
}

func AtSunset

func AtSunset(offset time.Duration, weekdays ...time.Weekday) <-chan time.Time

AtSunset returns a channel, which waits until sunset + offset and then returns the current time. If weekdays are specified the channel returns the time only on those weekdays. If no weekdays are specified, the channel returns time everyday.

The time when sunrise happens is calculated based on the location (latitude, longitude) specified in the settings. The default location of Linz (Austria) is used, if no location is specified.

Example

This example shows how to wait until 30 minutes after sunset on weekends.

Code:

var ch = hkknx.AtSunset(30*time.Minute, time.Saturday, time.Sunday)
for {
    <-ch
    println("it's 30 minutes after sunset")
}

func AtTime

func AtTime(hour, minute, second int, weekdays ...time.Weekday) <-chan time.Time

AtTime returns a channel, which waits until a specific time of day and then returns the current time. If weekdays are specified the channel returns the time only on those weekdays. If no weekdays are specified, the channel returns time everyday.

Example

This example shows how to wait until 8:15 AM on a Monday, Wednesday and Friday.

Code:

var ch = hkknx.AtTime(8, 15, 0, time.Monday, time.Wednesday, time.Friday)
for {
    <-ch
    println("it's 8:15 AM")
}

func DPT1

func DPT1(v bool) dpt.Value

DPT1 returns the boolean reprentation of v.

func DPT13

func DPT13(v int32) dpt.Value

DPT13 returns the 32-bit integer representation of v.

func DPT14

func DPT14(v float32) dpt.Value

DPT14 returns the 32-bit float representation of v.

func DPT14056

func DPT14056(v float32) dpt.Value

DPT14056 returns the power representation of v in Watt.

func DPT5001

func DPT5001(v float32) dpt.Value

DPT5001 returns the scaling representation of v from 0 to 100% with a resolution of 0.4%.

func DPT5003

func DPT5003(v float32) dpt.Value

DPT5003 returns the angle representation of v from 0 to 360° with a resolution of 1.4%.

func DPT5004

func DPT5004(v int) dpt.Value

DPT5003 returns the percentage representation of v from 0 to 100% with a resolution of 1%.

func DPT5010

func DPT5010(v int) dpt.Value

DPT5010 returns the integer representation of v from 0 to 255 with a resolution of 1.

func DPT7001

func DPT7001(v int) dpt.Value

DPT7001 returns the integer representation of v from 0 to 65,535 pulses with a resolution of 1 pulse.

func DPT7012

func DPT7012(v int) dpt.Value

DPT7012 returns the integer representation of v from 0 to 65,535 mA with a resolution of 1 mA.

func DPT7013

func DPT7013(v int) dpt.Value

DPT7013 returns the integer representation of v from 0 to 65,535 lux with a resolution of 1 lux.

func DPT9001

func DPT9001(v float32) dpt.Value

DPT9001 returns the temperature representation of v from -273°C to 670,760°C with a resolution of 0.01°C.

func DPT9004

func DPT9004(v float32) dpt.Value

DPT9004 returns the lux representation of v from 0 to 670,760 Lux with a resolution of 0.01 Lux.

func DPT9005

func DPT9005(v float32) dpt.Value

DPT9005 returns the wind speed representation of v from 0 to 670,760 m/s with a resolution of 0.01 m/s.

func DPT9007

func DPT9007(v float32) dpt.Value

DPT9007 returns the humidity representation of v from 0 to 670,760% with a resolution of 0.01%.

func DPT9008

func DPT9008(v float32) dpt.Value

DPT9008 returns the air quality representation of v from 0 to 670,760 ppm with a resolution of 0.01 ppm.

func DPT9021

func DPT9021(v float32) dpt.Value

DPT9021 returns the current representation of v from -670,760 to 670,760 mA with a resolution of 0.01 mA.

func GroupRead

func GroupRead(addr string) (buf []byte, err error)

GroupRead reads the bytes from group address addr and returns the byte and an error, if any.

Example

This example demonstrates how to read the value from 0/1/1 and convert it to the datapoint type DPST-5-1 (5.001).

Code:

var buf, err = hkknx.GroupRead("0/1/1")
if err != nil {
    println(err)
    return
}

var val = hkknx.ParseDPT5001(buf)
println(val)

func GroupReadBool

func GroupReadBool(addr string) (b bool, err error)

GroupReadBool reads the bytes from group address addr and returns the boolean value and an error, if any.

func GroupReadNotify

func GroupReadNotify(addr string) <-chan interface{}

GroupReadNotify returns a channel which provides an opaque value as a results of a group read telegram sent to addr.

func GroupResponse

func GroupResponse(v interface{}, addr ...string) (err error)

GroupResponse responds with value v to group addresses addrs and returns an error, if any. A group address response telegram should be sent as a responds to a group read telegram.

Note that GroupResponse is defined as a variadic function and can write v to one or more group addresses at a time. https://gobyexample.com/variadic-functions

Example

This example demonstrates how to respond to a read request by first listing to a group read telegram and then responding with a group response telegram.

Code:

var ch = hkknx.GroupReadNotify("0/2/1")
<-ch
hkknx.GroupResponse(true, "0/2/1")

func GroupWrite

func GroupWrite(v interface{}, addrs ...string) (err error)

GroupWrite writes value v to group addresses addrs and returns an error, if any. Note that GroupWrite is defined as a variadic function and can write v to one or more group addresses at a time. https://gobyexample.com/variadic-functions

Example

This example demonstrates how to write the bit *1* to multiple group addresses.

Code:

var err = hkknx.GroupWrite(true, "0/0/1", "0/0/2")
if err != nil {
    println(err)
}

func GroupWriteBoolNotify

func GroupWriteBoolNotify(addr string) <-chan bool

GroupWriteBoolNotify returns a channel which provides boolean values from a group write telegram sent to addr.

Example

This example demonstrates how to listens for group write telegrams to "0/0/1".

Code:

var ch = hkknx.GroupWriteBoolNotify("0/0/1")
var on = <-ch
println(on)

func GroupWriteNotify

func GroupWriteNotify(addr string) <-chan []byte

GroupWriteNotify returns a channel which provides bytes from a group write telegram sent to addr.

Example

This example demonstrates how to listens for group write telegrams to "0/1/1" and convert the bytes to the datapoint type DPST-5-1 (5.001).

Code:

var ch = hkknx.GroupWriteNotify("0/1/1")
var buf = <-ch
var val = hkknx.ParseDPT5001(buf)
println(val)

func GroupWriteTelegramNotify

func GroupWriteTelegramNotify(patterns ...string) <-chan Telegram

GroupWriteTelegramNotify returns a channel which provides group write telegrams sent to matching group addresses.

A pattern can be a specific group address (ex. "0/1/1") or a range of group addresses ("0/1/1-100").

Note that GroupWriteTelegramNotify is defined as a variadic function and takes one or more group address patterns. https://gobyexample.com/variadic-functions

If no pattern is specified, all group write telegrams are received.

Example (1)

This example demonstrates how to listens for group write telegrams to group address "0/1/1" and "0/1/2".

Code:

var ch = hkknx.GroupWriteTelegramNotify("0/1/1", "0/1/2")
var telegram = <-ch
printf("%s: %v", telegram.Addr, telegram.Bytes)

Example (2)

This example demonstrates how to listens for group write telegrams to group address in a specific range.

Code:

var ch = hkknx.GroupWriteTelegramNotify("0/1/1-100")
var telegram = <-ch
printf("%s: %v", telegram.Addr, telegram.Bytes)

Example (3)

This example demonstrates how to listens for any group write telegram.

Code:

var ch = hkknx.GroupWriteTelegramNotify()
var telegram = <-ch
printf("%s: %v", telegram.Addr, telegram.Bytes)

func ParseBool

func ParseBool(buf []byte) bool

ParseBool returns the boolean value of the bytes in buf.

Example

Code:

var val = hkknx.ParseBool([]byte{0x1})
println(val)

Output:

true

func ParseDPT1

func ParseDPT1(buf []byte) bool

ParseDPT1 returns the boolean value of the bytes in buf.

func ParseDPT13

func ParseDPT13(buf []byte) int32

ParseDPT13 returns the itneger value of the bytes in buf.

Example

Code:

var val = hkknx.ParseDPT13([]byte{0x00, 0x00, 0x01, 0x00})
println(val)
println(hkknx.DPT13(val))

Output:

256
256

func ParseDPT14

func ParseDPT14(buf []byte) float32

ParseDPT14 returns the float value of the bytes in buf.

Example

Code:

var val = hkknx.ParseDPT14([]byte{0x42, 0xEA, 0x0, 0x0})
println(val)
println(hkknx.DPT14(val))

Output:

117
117

func ParseDPT14056

func ParseDPT14056(buf []byte) float32

ParseDPT14056 returns the float value of the bytes in buf. The datapoint type 14.056 represents power values in Watt.

Example

Code:

var val = hkknx.ParseDPT14056([]byte{0x42, 0xEA, 0x0, 0x0})
println(val)
println(hkknx.DPT14056(val))

Output:

117
117 W

func ParseDPT5001

func ParseDPT5001(buf []byte) float32

ParseDPT5001 returns the float value of the bytes in buf. The datapoint type 5.001 represents scaling values from 0 to 100% with a resolution of 0.4%.

Example

Code:

var val = hkknx.ParseDPT5001([]byte{0xFF})
println(val)

Output:

100

func ParseDPT5003

func ParseDPT5003(buf []byte) float32

ParseDPT5003 returns the float value of the bytes in buf. The datapoint type 5.003 represents angles from 0 to 360° with a resolution of 1.4°.

Example

Code:

var val = hkknx.ParseDPT5003([]byte{0xFF})
println(val)

Output:

360

func ParseDPT5004

func ParseDPT5004(buf []byte) int

ParseDPT5004 returns the integer value of the bytes in buf. The datapoint type 5.004 represents percentages from 0 to 100% with a resolution of 1%.

Example

Code:

var val = hkknx.ParseDPT5004([]byte{0xFF})
println(val)

Output:

255

func ParseDPT5010

func ParseDPT5010(buf []byte) int

ParseDPT5010 returns the integer value of the bytes in buf. The datapoint type 5.010 represents integer values from 0 to 255 with a resolution of 1.

Example

Code:

var val = hkknx.ParseDPT5010([]byte{0xFF})
println(val)

Output:

255

func ParseDPT7001

func ParseDPT7001(buf []byte) int

ParseDPT7001 returns the integer value of the bytes in buf. The datapoint type 7.001 represents integer values from 0 to 65,535 pulses with a resolution of 1 mA.

func ParseDPT7012

func ParseDPT7012(buf []byte) int

ParseDPT7012 returns the integer value of the bytes in buf. The datapoint type 7.012 represents integer values from 0 to 65,535 mA with a resolution of 1 mA.

func ParseDPT7013

func ParseDPT7013(buf []byte) int

ParseDPT7013 returns the integer value of the bytes in buf. The datapoint type 7.013 represents integer values from 0 to 65,535 lux with a resolution of 1 lux.

Example

Code:

var val = hkknx.ParseDPT7013([]byte{0xFF, 0xFF})
println(val)

Output:

65535

func ParseDPT9001

func ParseDPT9001(buf []byte) float32

ParseDPT9001 returns the float value of the bytes in buf. The datapoint type 9.001 represents temperature values from -273°C to 670,760°C with a resolution of 0.01°C.

func ParseDPT9004

func ParseDPT9004(buf []byte) float32

ParseDPT9004 returns the float value of the bytes in buf. The datapoint type 9.004 represents lux values from 0 to 670,760 Lux with a resolution of 0.01 Lux.

func ParseDPT9005

func ParseDPT9005(buf []byte) float32

ParseDPT9005 returns the float value of the bytes in buf. The datapoint type 9.005 represents wind speed values from 0 to 670,760 m/s with a resolution of 0.01 m/s.

func ParseDPT9007

func ParseDPT9007(buf []byte) float32

ParseDPT9007 returns the float value of the bytes in buf. The datapoint type 9.007 represents humidity values from 0 to 670,760% with a resolution of 0.01%.

func ParseDPT9008

func ParseDPT9008(buf []byte) float32

ParseDPT9008 returns the float value of the bytes in buf. The datapoint type 9.008 represents air quality values from 0 to 670,760 ppm with a resolution of 0.01 ppm.

func ParseDPT9021

func ParseDPT9021(buf []byte) float32

ParseDPT9021 returns the float value of the bytes in buf. The datapoint type 9.021 represents current values from -670,760 to 670,760 mA with a resolution of 0.01 mA.

func ParseString

func ParseString(buf []byte) string

ParseString returns the string of the bytes in buf.

Example

Code:

var str = hkknx.ParseString([]byte{0x4B, 0x4E, 0x58, 0x20, 0x69, 0x73, 0x20, 0x4F, 0x4B})
println(str)

Output:

KNX is OK

func Send

func Send(notification *Notification, deviceNames ...string) error

Send sends a notification to registered devices. If device names are specified, the notification is only sent to devices, which contain any specified term in their names. Sending a notification requires an internet connection.

func SendNotification

func SendNotification(title string, message string, deviceNames ...string) error

SendNotification sends a notification to registered devices. If device names are specified, the notification is only sent to devices, which contain any specified term in their names. Sending a notification requires an internet connection.

Example

Code:

// Send notification to all registered devices
var err = hkknx.SendNotification("Alarm Triggered", "The alarm was triggered because motion was detected.")
if err != nil {
    println(err)
}

// Send notification to devices, which contain the term "Matthias" in the name
err = hkknx.SendNotification("Front Door", "The doorbell rang.", "Matthias")
if err != nil {
    println(err)
}

type DailyWeather

DailyWeather represents the daily weather.

type DailyWeather struct {
    // Date is the day of the weather information.
    Date time.Time
    // Temp is the temperature information for a day.
    Temp DailyWeatherTemp
    // Pressure is the atmospheric in Hectopascal (hPa).
    Pressure int
    // Humidity is the humidity in %.
    Humidity int
    // Clouds is the cloudiness in %.
    Clouds int
    // WindSpeed is the wind speed in meter per second.
    WindSpeed float64
    // WindGust ist the wind gust in meter per second; added in 2.6.0
    WindGust float64
    // WindDegree is the wind direction in degrees.
    WindDegree int
    // Rain is the rain volume for a day in mm or l/m².
    // This property is nil, if rain information is not available.
    Rain *RainVolume
    // Snow is the snow volume for a day in mm or l/m²..
    // This property is nil, if snow information is not available.
    Snow *SnowVolume
}

func GetDailyWeather

func GetDailyWeather() ([]*DailyWeather, error)

GetDailyWeather returns the daily weather forcast and an error, if any. The weather is downloaded based on the location (latitude, longitude) specified in the settings.

func (DailyWeather) RainVolume

func (w DailyWeather) RainVolume() float64

RainVolume returns the rain volume in mm (l/m²) – or 0, if no rain information is available.

func (DailyWeather) SnowVolume

func (w DailyWeather) SnowVolume() float64

SnowVolume returns the rain volume in mm (l/m²) – or 0, if no snow information is available.

type DailyWeatherTemp

DailyWeatherTemp represents the temperature information for a day.

type DailyWeatherTemp struct {
    // Day is the average temperature.
    Day float64
    // Min is the minimum temperature.
    Min float64
    // Min is the maximum temperature.
    Max float64
    // Night is the night temperature.
    Night float64
    // Night is the evening temperature.
    Evening float64
    // Night is the morning temperature.
    Morning float64
}

type Notification

Notification represents a push notification.

type Notification struct {
    // Title of the notification
    Title string
    // Message of the notification
    Message string
    // Image of the notification
    Image []byte
}

type RainVolume

type RainVolume struct {
    Volume float64
}

func (RainVolume) String

func (v RainVolume) String() string

type SnowVolume

type SnowVolume struct {
    Volume float64
}

func (SnowVolume) String

func (v SnowVolume) String() string

type Telegram

Telegram represents a knx telegram.

type Telegram struct {
    // Addr is the telegram address.
    Addr knx.Addr
    // Bytes is the telegram payload.
    Bytes []byte
}

type Weather

Weather represents the weather.

type Weather struct {
    // Date is the date and time of the weather information.
    Date time.Time
    // Temp is the temperature in Celsius degree.
    Temp float64
    // Pressure is the atmospheric in Hectopascal (hPa).
    Pressure int
    // Humidity is the humidity in %.
    Humidity int
    // Clouds is the cloudiness in %.
    Clouds int
    // WindSpeed is the wind speed in meter per second.
    WindSpeed float64
    // WindGust ist the wind gust in meter per second; added in 2.6.0
    WindGust float64
    // WindDegree is the wind direction in degrees.
    WindDegree int
    // Rain is the rain volume for an hour in mm (l/m²).
    // This property is nil, if rain information is not available.
    Rain *RainVolume
    // Snow is the snow volume for an hour in mm (l/m²).
    // This property is nil, if snow information is not available.
    Snow *SnowVolume
}

func GetCurrentWeather

func GetCurrentWeather() (*Weather, error)

GetCurrentWeather returns the current weather and an error, if any. The weather is downloaded based on the location (latitude, longitude) specified in the settings.

Example

This example demonstrates how to print the current temperature.

Code:

var weather, err = hkknx.GetCurrentWeather()
if err != nil {
    println(err)
    return
}

printf("%.2f °C\n", weather.Temp)

func GetHourlyWeather

func GetHourlyWeather() ([]*Weather, error)

GetHourlyWeather returns the hourly weather forcast and an error, if any. The weather is downloaded based on the location (latitude, longitude) specified in the settings.

func (Weather) RainVolume

func (w Weather) RainVolume() float64

RainVolume returns the rain volume in mm (l/m²) – or 0, if no rain information is available.

func (Weather) SnowVolume

func (w Weather) SnowVolume() float64

SnowVolume returns the rain volume in mm (l/m²) – or 0, if no snow information is available.

type WeekdayTime

WeekdayTime represents time on a weekday like 8:15 AM on Monday.

type WeekdayTime struct {
    Weekday time.Weekday
    Hour    int
    Minute  int
    Second  int
}

func ParseDPT10001

func ParseDPT10001(buf []byte) WeekdayTime

ParseDPT10001 returns the weekday time of the bytes in buf.