A Home Assistant, native app for desktop/laptop devices.
Go to file
Joshua Rich 8f32f7c18c
Merge pull request #68 from joshuar/release-please--branches--main
chore(main): release 6.1.0
2023-12-21 09:00:07 +10:00
.devcontainer build(devcontainer): add D-Bus system bus in container environment 2023-12-17 11:32:00 +10:00
.github ci(github): disable D-Bus tests for now 2023-12-18 09:17:29 +10:00
.vscode build(vscode): remove unnecessary settings file 2023-12-20 10:20:44 +10:00
assets chore(init): move systemd init to canonical location 2023-10-08 22:39:15 +00:00
build/package build(docker): add docker build GitHub action 2023-11-14 09:00:47 +10:00
cmd refactor(agent,tracker): separate agent and tracker configuration and setup 2023-12-20 12:12:05 +10:00
docs docs(scripts): fix script path 2023-12-13 11:30:43 +10:00
init chore(init): move systemd init to canonical location 2023-10-08 22:39:15 +00:00
internal test(tracker): fix tests to pass 2023-12-20 14:21:41 +10:00
pkg/dbushelpers test(dbushelpers): test more functions 2023-12-16 13:28:00 +10:00
.gitignore build(git): catch additional temp build file 2023-12-18 09:53:33 +10:00
.golangci.yaml refactor(linux): reduce networkConnectionSensor code complexity 2023-12-19 11:23:16 +10:00
.goreleaser.yaml ci(goreleaser): implement artifact signing with cosign 2023-10-21 14:59:03 +10:00
CHANGELOG.md chore(main): release 6.1.0 2023-12-20 04:05:49 +00:00
LICENSE Add licensing. 2023-04-10 09:45:12 +10:00
README.md docs(README): add more suggested usage cases, fix headless description 2023-11-27 17:45:29 +10:00
cosign.key ci(goreleaser): implement artifact signing with cosign 2023-10-21 14:59:03 +10:00
cosign.pub ci(goreleaser): implement artifact signing with cosign 2023-10-21 14:59:03 +10:00
go.mod build(go): clean up go.mod 2023-12-13 11:38:10 +10:00
go.sum build(go): clean up go.mod 2023-12-13 11:38:10 +10:00
main.go refactor(main): use init to check correct permissions 2023-10-01 05:49:31 +00:00

README.md

Go Hass Agent

MIT GitHub last commit Go Report Card Go Reference Release

A Home Assistant, native app integration for desktop/laptop devices.

🎉 Features

This app will add some sensors to a Home Assistant instance:

  • Device location.
  • Current active application and list of running applications.
  • Battery status (for example, laptop battery and any peripherals).
  • Network status (for example, network connection status, internal and external IP addresses and Wi-Fi details where relevant).
  • Memory and swap usage (total/free/used).
  • Disk usage.
  • Load Averages.
  • Uptime.
  • Power profile.
  • Screen lock.
  • Problems detected by ABRT.
  • User-specified script output.

A full list of sensors can be found in the docs.

The code can be extended to add additional sensors. See the development docs for details.

🤔 Use-cases

As examples of some of the things that can be done with the data published by this app:

  • Change your lighting depending on:
    • What active/running apps are on your laptop/desktop. For example, you could set your lights dim or activate a scene when you are gaming.
    • Whether your screen is locked or the device is shutdown/suspended.
  • With your laptop plugged into a smart plug that is also controlled by Home Assistant, turn the smart plug on/off based on the battery charge. This can force a full charge/discharge cycle of the battery, extending its life over leaving it constantly charged.
  • Like on mobile devices, create automations based on the location of your laptop running this app.
  • Monitor network the data transfer amount from the device, useful where network data might be capped.
  • Monitor CPU load, disk usage and any temperature sensors emitted from the device.
  • Receive notifications from Home Assistant on your desktop/laptop. Potentially based on or utilising any of the data above.

See also the FAQ.

🤝 Compatibility

Currently, only Linux is supported. Though the code is designed to be extensible to other operating systems. See development information in the docs for details on how to extend for other operating systems.

⬇️ Installation

Head over to the releases page and download the appropriate package for your operating system and/or distribution:

  • For Fedora, use the .rpm.
  • For Ubuntu, use the .deb.
  • For Debian, use the .tar.xz.
  • For Arch, use the .tar.zst.

For other distributions not listed above, you can try the binary, or build it yourself from source (see development docs). Note that while Go is known for statically compiled binaries that "run anywhere", the Fyne UI toolkit used by Go Hass Agent makes use of shared libraries that may need to be installed as well.

Package signatures can be verified with cosign. To verify a package, you'll need the cosign.pub public key and the .sig file (downloaded from releases) that matches the package you want to verify. To verify a package, a command similar to the following for the rpm package can be used:

cosign verify-blob --key cosign.pub --signature go-hass-agent-*.rpm.sig go-hass-agent-*.rpm

🖱️ Usage

Go Hass Agent runs as a tray icon by default. It is operating system, distribution and desktop-environment agnostic and should manifest itself in any tray of any desktop environment.

First-run

On first-run, Go Hass Agent will display a window where you will need to enter some details, so it can register itself with a Home Assistant instance to be able to report sensors and receive notifications.

Registration Window

You will need:

  • A long-lived access token. You can generate one on your account profile page.
  • The web address (URL) on which a Home Assistant instance can be found.
    • Go Hass Agent will try to auto-detect this for you, and you can select it in the Auto-discovered servers list. Otherwise, you will need to select Use Custom Server?, and enter the details manually in Manual Server Entry.

When you have entered all the details, click Submit and the agent should start running and reporting sensors to the Home Assistant instance.

Running “Headless”

Go Hass Agent will automatically detect if there is no GUI available and run in a “headless” mode with no UI. Registration will need to be completed manually as a first step in such environments.

You can register Go Hass Agent on the command-line with by running:

go-hass-agent --terminal register --token _TOKEN_ --server _URL_

You will need to provide a long-lived token _TOKEN_ and the URL of your Home Assistant instance, _URL_.

Once registered, running Go Hass Agent again with no options should start tracking and sending sensor data to Home Assistant.

If desired, headless mode can be forced, even in graphical environments, by specifying the --terminal command-line option.

Running in a container

There is rough support for running Go Hass Agent within a container. A Dockerfile that you can use to build an image can be found here.

You can build an image with a command like the following (using Podman):

cat Dockerfile | podman build --build-arg version='x.x.x' --network host --tag go-hass-agent -

The --build-arg version=x.x.x is required and the version should correspond to a release. Once the image is built, first register the agent with Home Assistant:

podman run --rm --hostname hass-container --volume /proc:/host/proc:ro --volume /sys:/host/sys:ro --volume /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro --volume /run/user/1000/bus:/run/user/1000/bus:ro --volume ~/go-hass-agent:/home/go-hass-agent:U --network host --userns keep-id go-hass-agent register --server some.server:port --token longlivedtoken

Once registered, run the agent with:

podman run --rm --hostname hass-container --volume /proc:/host/proc:ro --volume /sys:/host/sys:ro --volume /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket:ro --volume /run/user/1000/bus:/run/user/1000/bus:ro --volume ~/go-hass-agent:/home/go-hass-agent:U --network host --userns keep-id go-hass-agent

You can change ~/go-hass-agent to whatever volume you want to use to store the agent config and registry. The D-Bus volumes are optional, not specifying them will mean sensors that rely on a D-Bus connection will not show up.

Regular Usage

When running, Go Hass Agent will appear as a device under the Mobile App integration in your Home Assistant instance. It should also report a list of sensors/entities you can use in any automations, scripts, dashboards and other parts of Home Assistant.

🧑‍🤝‍🧑 Contributing

Development

I would welcome your contribution! If you find any improvement or issue you want to fix, feel free to send a pull request!

Some documentation for development can be found in the docs. There is information for developing Go Hass Agent for different operating systems as well as adding additional sensors. This might help anyone to look to contribute, extend or fork this tool.

Translations

While this application does not have many points where text is displayed to the end user (logging aside), translation is supported through the language and message packages that are part of golang.org/x/text.

I would welcome pull requests for translations!

🙌 Acknowledgements

The app icon is taken from the Home Assistant project.

License

MIT