# Home Assistant

Source: https://sl0ptiminer.com/wiki/home-assistant/

Your rig can appear in Home Assistant as a device with its state, hashrate, power, temperature and shares. If you allow it, Home Assistant can also pause mining and resume it. One command sets it up; until then it is off.

It works on Linux, macOS and HiveOS, through the MQTT broker your Home Assistant uses. Home Assistant cannot change the pool, the wallet or the fee, and nothing of this goes to us: [privacy](https://sl0ptiminer.com/privacy/).

## What you need

- Home Assistant with an MQTT broker. No broker yet? Add the MQTT integration under Settings → Devices & services → Add integration; Home Assistant can install the Mosquitto broker for you there.
- A login for the miner. Safest is one that opens only the broker: add a user name and password under `logins` in the Mosquitto broker's configuration. A Home Assistant user works too, but its password also opens Home Assistant. The names `homeassistant` and `addons` are taken.

## 1. Run the setup

In the miner's folder, run:

```
./sloptiminer ha
```

It asks a few questions and tests the connection. With a broker that has no TLS, it looks like this:

```
Home Assistant link · this rig sends its status to your MQTT broker and can be paused from Home Assistant.

Broker address [homeassistant.local]:
MQTT user name: rig-miner
Password (not shown):
Testing homeassistant.local ... TLS on port 8883: not answering ·
Without TLS, others on your network can read the login.
  1  try without TLS
  2  stop here (nothing is saved)
Choose [1]:
Testing homeassistant.local ... port 1883 without TLS: connected, login accepted.
Without TLS, Home Assistant can watch and pause this rig; resume it here on the rig (press p, or run sloptiminer control hold off).

What may Home Assistant do?
  1  watch only
  2  watch and pause
  3  watch, pause and resume   (not recommended without TLS)
Choose [2]:
Name in Home Assistant [the worker name of your pool login; type one if your login has none]:

Saved. Start (or restart) the miner as usual; the rig appears in Home Assistant under
Settings → Devices & services → MQTT within a minute.
```

Without TLS, others on your network can read the miner's login and pause the rig with it. [Turn on TLS](#tls) to prevent that.

The login is saved in a folder only you can open, and your start command stays as it was. If a test fails, nothing is saved.

**On HiveOS,** start the miner once from the flight sheet first: that prepares the folder the setup needs. Then open the rig's shell (Hive shell or SSH) and run the setup there:

```
/hive/miners/custom/sl0ptiminer/bin/sloptiminer ha
```

Then restart the miner from the Hive dashboard, or run `miner restart`. Nothing goes into the flight sheet. A paused rig shows 0 hashrate in Hive: if you turned on the Hive hashrate watchdog, it restarts the miner, and a restart ends a pause from Home Assistant. On a diskless rig (PXE boot), the setup is lost at every reboot; run it again after each boot, and the rig shows up as a new device.

**Several rigs:** run the setup on each rig; over SSH, use `ssh -t` so it can ask its questions. One broker login can serve all rigs, but do not copy the saved settings between rigs: they would share one device in Home Assistant and cut each other off.

## 2. Find the rig in Home Assistant

Restart the miner as you usually start it. Within a minute the rig appears under Settings → Devices & services → MQTT, with the name you chose (the worker name of your pool login if you left it empty). It shows:

- **State**, **Paused** and **Uptime**
- a rate (in H/s), power and temperature for the processor and each card, named like `cpu01 rate` and `gpu_01 temperature`
- **Accepted shares** and **Rejected shares**, without fee shares, and **Fee window active**
- the miner's version, its update notice and **Update required**; you install updates as before

While the miner is stopped, these show as unavailable.

## What Home Assistant may do

- **Watch only:** Home Assistant shows the rig and nothing more.
- **Watch and pause:** a **Pause mining** button pauses mining. Resume on the rig itself: press `p` on the mining screen or run `./sloptiminer control hold off`. While paused, the screen says `paused by Home Assistant · p or sloptiminer control hold off resumes`.
- **Watch, pause and resume:** a **Mining allowed** switch pauses and resumes, and **CPU thread limit** sets the thread count, up to the number the miner started with. Turn mining back on with the same switch: `p` on the rig does not end a pause from Home Assistant, it adds a pause of its own.

A restart of the miner ends a pause from Home Assistant. Without TLS, the third choice needs a typed `yes`, unless the broker is at `localhost`; anything else keeps watch and pause. In an automation, pause the rig by pressing **Pause mining** or by turning off **Mining allowed**.

With the third choice, the setup also asks what the rig does if Home Assistant cannot be reached, which means the broker is out of reach for 30 seconds. **Keep mining** is the default. With **pause**, the rig stays paused after such a loss, and after every start, until Home Assistant turns mining on again; without Home Assistant, run `./sloptiminer control off`, then `./sloptiminer control hold off`.

## Turn on TLS (recommended)

TLS encrypts the connection and proves that the broker is yours. Without it, others on your network can read the login and pause the rig, and with the third choice also resume it or raise the thread count.

The Mosquitto broker takes encrypted connections on port 8883 when its `certfile` and `keyfile` options name a certificate and its key in Home Assistant's `ssl` folder, by default `fullchain.pem` and `privkey.pem`.

- **With Let's Encrypt:** it writes `fullchain.pem` and `privkey.pem` to that folder; restart the Mosquitto broker to use them. Give the setup the domain name the certificate is for: an IP address or `homeassistant.local` fails the certificate check.
- **With your own CA:** put the broker's certificate and key in that folder and name them under `certfile` and `keyfile`. When the setup asks for the broker's CA certificate, give it your CA's certificate.

Then run `./sloptiminer ha` again.

## Pause on the rig

These work without the broker:

```
./sloptiminer control status
./sloptiminer control hold on
./sloptiminer control hold off
./sloptiminer control off
```

`hold on` pauses mining and `hold off` ends that pause; `p` on the mining screen does the same. The hold stays after a restart. `control off` turns Home Assistant off for this rig and pauses mining; a running miner also removes the rig from Home Assistant. `control hold off` then lets it mine again, and `./sloptiminer ha` turns Home Assistant on again.

## Change, test or turn off

```
./sloptiminer ha
./sloptiminer ha test
./sloptiminer ha off
```

Running the setup again, also while the miner runs, shows the saved values as defaults; leave the password empty to keep it. `ha test` tests the saved connection. `ha off` turns Home Assistant off and keeps the saved setup for later; the rig stays listed in Home Assistant until you delete it there. Restart the miner after each change.

## When it does not connect

The setup's test says what failed, and nothing is saved:

- **not answering:** the broker cannot be reached at that address and port.
- **TLS certificate not trusted:** give the path of the broker's CA certificate when the setup asks. Leaving it empty goes on without TLS, where others on your network can read the login.
- **this CA certificate does not match the broker's certificate** or **that file holds no usable CA certificate:** give the certificate of the CA that signed the broker's certificate.
- **the broker's certificate is for another name:** use the name in the certificate as the broker address, [as above](#tls).
- **login refused:** check the user name and the password.
- **this user may not use the `sloptiminer` topics** or **the Home Assistant topic:** allow `sloptiminer/#` and `homeassistant/#` for this user in the broker's access list.
- **the broker refused what the miner needs:** the broker must take MQTT 5, QoS 1 and retained messages, as the Mosquitto broker does.

Fix that and run the setup again.

While mining, the screen and the log say what failed:

| The miner says | What to do |
|---|---|
| MQTT connection unavailable; retrying with bounded backoff. | The broker cannot be reached. Check the network, then `./sloptiminer ha test`. |
| MQTT login rejected; check local credentials and broker permissions. | Run the setup again with the right name and password. |
| MQTT TLS failed; check the local clock and certificate configuration. | Check that the machine's clock is right. If the broker's certificate changed, run the setup again. |
| MQTT local files unavailable; check local configuration and file permissions. | The saved login or CA file cannot be read. Run `./sloptiminer ha` again. |

Two notes, where mining goes on without Home Assistant, have their own entries: [no worker name](https://sl0ptiminer.com/wiki/troubleshooting/#ha-name) and [saved settings could not be used](https://sl0ptiminer.com/wiki/troubleshooting/#ha-saved).

[All options](https://sl0ptiminer.com/wiki/options/#mqtt) has the same settings as command-line options, for scripts and special setups.
