joshuar-go-hass-agent/docs/mqtt.md

4.1 KiB

Control via MQTT

If Home Assistant is connected to MQTT, you can also configure Go Hass Agent to connect to MQTT, which will then allow you to run some commands from Home Assistant to control the device running the agent.

[!NOTE]
Control via MQTT is not enabled by default.

[!IMPORTANT]
Go Hass Agent requires the MQTT broker is configured with persistence enabled to support retained messages. See your broker's documentation for configuring persistence.

To configure the agent to connect to MQTT:

  1. Right-click on the Go Hass Agent tray icon.
  2. Select Settings->App.
  3. Toggle Use MQTT and then enter the details for your MQTT server (not your Home Assistant server).
  4. Click Save.
  5. Restart Go Hass Agent.

After the above steps, Go Hass Agent will appear as a device under the MQTT integration in your Home Assistant.

Open your Home Assistant instance and show the MQTT integration.

[!NOTE] Go Hass Agent will appear in two places in your Home Assistant. Firstly, under the Mobile App integration, which will show all the sensors that Go Hass Agent is reporting. Secondly, under the MQTT integration, which will show the controls for Go Hass Agent. Unfortunately, due to limitations with the Home Assistant architecture, these cannot be combined in a single place.

Available Controls

The following table shows the controls that are available. You can add these controls to dashboards in Home Assistant or use them in automations with a service call.

Control What it does
Lock Screen Locks the session for the user running Go Hass Agent
Unlock Screen Unlocks the session for the user running Go Hass Agent
Lock Screensaver Lock the “screensaver” of the session for the user running Go Hass Agent
Suspend Will (instantly) suspend (the system state is saved to RAM and the CPU is turned off) the device running Go Hass Agent
Hibernate Will (instantly) hibernate (the system state is saved to disk and the machine is powered down) the device running Go Hass Agent
Power Off Will (instantly) power off the device running Go Hass Agent
Reboot Will (instantly) reboot the device running Go Hass Agent
Volume Control Adjust the volume on the default audio output device
Volume Mute Mute/Unmute the default audio output device

Security

There is a significant discrepancy in permissions between the device running Go Hass Agent and Home Assistant.

Go Hass Agent runs under a user account on a device. So the above controls will only work where that user has permissions to run the underlying actions on that device. Home Assistant does not currently offer any fine-grained access control for controls like the above. So any Home Assistant user will be able to run any of the controls. This means that a Home Assistant user not associated with the device user running the agent can use the exposed controls to issue potentially disruptive actions on a device that another user is accessing.

Arbitrary D-BUS commands

The agent subscribes to the MQTT topic gohassagent/dbus on the configured MQTT broker and listens for JSON messages of the below format, which will be accordingly dispatched to the systems d-bus.

{
  "bus": "session",
  "path": "/org/cinnamon/ScreenSaver",
  "method": "org.cinnamon.ScreenSaver.Lock",
  "destination": "org.cinnamon.ScreenSaver",
  "args": [
    ""
  ]
}

This can be used to trigger arbitrary d-bus commands on the system where the agent runs on, by using any MQTT client such as Home Assistants mqtt.publish service.

Implementation Details

Linux

Controls rely on distribution/system support for systemd-logind and a working D-Bus connection.