fritzbox

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 15 Imported by: 0

README

go-fritzbox-api

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

Attribution

Installation

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

Quick Start

package main

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

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

    thermostats, _ := smart.GetAllThermostats(client)
    for _, t := range thermostats {
        fmt.Printf("%s: %.1f°C\n", t.Name, t.CurrentTemp)
    }
}

Or run the example CLI directly:

go run github.com/ByteSizedMarius/go-fritzbox-api/v2/smart/examples/thermostat@latest -user=admin -pass=secret

See smart/README.md for the full API, examples, and thermostat concepts.

Packages

Package API Description
smart/ REST Wrapper for rest/ with nicer API for selected functionality
rest/ REST JSON API, generated types (FRITZ!OS 8.20+)
unsafe/ data.lua Router internals (unstable)
aha/ AHA HTTP (Legacy) XML API for DECT devices

Scope

Currently supported device types:

  • Thermostats - full support (state, config, schedules, holidays)
  • Buttons - partial support
  • Window detectors - state and thermostat linking
  • Temperature sensors - read-only

If you own any of the missing devices and would like to help with implementation, please let me know!

API Landscape

FRITZ!Box has two official smart home APIs:

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

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.

Breaking changes are possible in v2.X, but will always be released with a new tag.

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 rest provides access to FRITZ!Box Smart Home features via the REST API.
Package rest provides access to FRITZ!Box Smart Home features via the REST API.
Package smart provides high-level helpers for the rest package.
Package smart provides high-level helpers for the rest package.

Jump to

Keyboard shortcuts

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