KEMBAR78
GitHub - mbg/home-assistant-client: Haskell client for the Home Assistant REST API
Skip to content

mbg/home-assistant-client

Repository files navigation

home-assistant-client: Haskell client for the Home Assistant API

GitHub Haskell Stackage Nightly Hackage

A Haskell library for the Home Assistant API, allowing you to write Haskell applications which interact with Home Assistant.

A ha-client program that exposes the library functions as CLI commands is also provided.

Library usage

The Home Assistant API offers fairly general endpoints, for which the HomeAssistant.Client module provides client computations. All API endpoints require authorisation with a long-lived token. For example, to retrieve a list available services from Home Assistant:

import Network.HTTP.Client

defaultAddress :: String
defaultAddress = "http://homeassistant.local:8123/"

main :: IO ()
main = do
    -- `token` should be the long-lived token
    httpManager <- defaultManagerSettings
    address <- parseBaseUrl defaultAddress

    let env = mkHomeAssistantEnv token httpManager address
    result <- runClientM services env
    print result

CLI usage

You can download the ha-client program from the releases list.

You must set an environment variable named HA_TOKEN to your long-lived token. The CLI also inspects the HA_ADDRESS environment variable to determine the address of the Home Assistant server. This is optional and will default to http://homeassistant.local:8123/ if no value is set.

The ha-client CLI can be invoked with --help to retrieve usage information. All sub-commands also support the --help flag to retrieve command-specific help.

Build provenance

For releases, build provenance attestations are created that allow you to verify the authenticity of a ha-client binary. All available attestations can be viewed here.

To verify the origin of a ha-client binary, you can run gh attestation verify --owner mbg ha-client. This assumes that you have the GitHub CLI installed. For more information about verifying build provenance attestations, read the relevant GitHub documentation.

About

Haskell client for the Home Assistant REST API

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors 2

  •  
  •