fritzbox

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 15 Imported by: 0

README

go-fritzbox-api

Go client library for AVM FRITZ!Box routers and smart home devices.

Attribution

Authentication based on Philipp Franke's go-fritzbox.

Installation

go get github.com/ByteSizedMarius/go-fritzbox-api

Quick Start

package main

import (
    "fmt"
    fritzbox "github.com/ByteSizedMarius/go-fritzbox-api"
    "github.com/ByteSizedMarius/go-fritzbox-api/smarthome"
)

func main() {
    client := fritzbox.New("username", "password")
    if err := client.Connect(); err != nil {
        panic(err)
    }
    defer client.Close()

    overview, _ := smarthome.GetOverview(client)
    for _, device := range overview.Devices {
        fmt.Printf("%s (%s)\n", device.Name, device.ProductName)
    }
}

Packages

Package API Stability Description
aha/ AHA HTTP Stable Smart home (DECT devices, thermostats)
smarthome/ REST Stable Full config, JSON-based (FRITZ!OS 8.20+)
unsafe/ data.lua Unstable Router internals, network devices

Scope

Only a subset of device types is implemented for both APIs. Main focus is on HKR (radiator thermostats) - see HKR Documentation for details. Other device types (buttons, temperature sensors, HAN-FUN) have partial support.

See the package READMEs linked above for detailed usage and available functions.

API Landscape

FRITZ!Box has two official smart home APIs:

  • AHA HTTP Interface (/webservices/homeautoswitch.lua): XML-based, available since FRITZ!OS 5.53; Docs
  • Smart Home REST API (/api/v0/smarthome/...): JSON-based, requires FRITZ!OS 8.20+. More comprehensive; OpenAPI spec

Compatibility

Tested with FRITZ!OS 8.21 on the 6690 Cable. Smart home implementations (DECT) are stable across versions and routers. Endpoints in the unsafe/ package may break between firmware versions.

Contributing

Issues, Pull Requests and E-Mails are welcome.

Documentation

Overview

Package fritzbox provides a client for interacting with AVM FRITZ!Box routers.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

Functions

func Pow

func Pow(n, m int) int

Pow returns n^m as int.

func ValueFromJsonPath

func ValueFromJsonPath(body string, pathKeys []string) (v map[string]interface{}, err error)

ValueFromJsonPath extracts a nested value from JSON using a path of keys.

Types

type Client

type Client struct {
	BaseUrl  string
	Username string
	Password string
	// contains filtered or unexported fields
}

Client handles authentication and communication with the FRITZ!Box.

func New

func New(username, password string) *Client

New creates a new client with the given credentials. Call Connect() to authenticate with the FRITZ!Box.

func (*Client) AhaRequest

func (c *Client) AhaRequest(method, path string, data Values) (*http.Response, error)

AhaRequest sends a form-encoded request to the FRITZ!Box. GET: data as query parameters. POST: data as form body.

func (*Client) AhaRequestString

func (c *Client) AhaRequestString(method, path string, data Values) (int, string, error)

AhaRequestString sends a request and returns the response body as a string.

func (*Client) AhaRequestXML

func (c *Client) AhaRequestXML(method, path string, data Values, target any) error

AhaRequestXML sends a request and decodes the XML response into target.

func (*Client) CheckExpiry

func (c *Client) CheckExpiry() error

CheckExpiry reconnects if the session is expired or not connected.

func (*Client) Close

func (c *Client) Close()

Close terminates the session and releases resources.

func (*Client) Connect

func (c *Client) Connect() error

Connect initializes and authenticates the client. If already connected, the existing session is closed first.

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected returns true if the client has an active session.

func (*Client) IsExpired

func (c *Client) IsExpired() bool

IsExpired returns true if the session has expired due to inactivity.

func (*Client) RestDelete

func (c *Client) RestDelete(path string) ([]byte, int, error)

RestDelete sends a DELETE request to the REST API.

func (*Client) RestGet

func (c *Client) RestGet(path string) ([]byte, int, error)

RestGet sends a GET request to the REST API.

func (*Client) RestPost

func (c *Client) RestPost(path string, body any) ([]byte, int, error)

RestPost sends a POST request with a JSON body to the REST API.

func (*Client) RestPut

func (c *Client) RestPut(path string, body any) ([]byte, int, error)

RestPut sends a PUT request with a JSON body to the REST API.

func (*Client) RestRequest

func (c *Client) RestRequest(method, path string, body any) ([]byte, int, error)

RestRequest sends a JSON request to the FRITZ!Box REST API. Body is JSON-marshaled for PUT/POST requests. Pass nil for GET/DELETE.

func (*Client) SID

func (c *Client) SID() string

SID returns the current session ID.

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(client *http.Client)

SetHTTPClient sets a custom HTTP client. Must be called before Connect().

func (*Client) String

func (c *Client) String() string

type Values

type Values map[string]string

Values is a convenience type for building form-encoded request parameters. Used by AhaRequest methods; REST methods use JSON bodies instead.

func (Values) Encode

func (v Values) Encode() string

Encode returns the values as a URL-encoded string.

func (Values) URLValues

func (v Values) URLValues() url.Values

URLValues converts to standard library url.Values.

Directories

Path Synopsis
Package aha is a Go-Wrapper for the AHA HTTP Interface (AVM Home Automation HTTP Interface)
Package aha is a Go-Wrapper for the AHA HTTP Interface (AVM Home Automation HTTP Interface)
Package smarthome provides access to FRITZ!Box Smart Home features via the REST API.
Package smarthome provides access to FRITZ!Box Smart Home features via the REST API.

Jump to

Keyboard shortcuts

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