bkbilly / lnxlink

🖥 Effortlessly manage your Linux machine using MQTT.

Home Page:https://bkbilly.gitbook.io/lnxlink

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Monitor drive connectivity

Daniel-dev22 opened this issue · comments

commented

Describe the solution you'd like

Is it possible to monitor to when drives disconnect/reconnect?

By checking all the drives that are connected periodically?

Additional context

I have a USB HDD and I want to know when it's disconnected and then reconnected but I haven't found a way to do this so that I can run an automation in home assistant on each event. The issue is right now it appears it checks filesystems and the filesystem would remain mounted even if the drive is disconnected and therefore the drive still shows up in the mqtt reports from this component, it doesn't get removed until it's unmounted.

I never thought of external drives, so I programmed it to send the discovery info when the service starts.
I will keep this feature in mind for a future release.

commented

I never thought of external drives, so I programmed it to send the discovery info when the service starts.
I will keep this feature in mind for a future release.

No problem. This program has come a long way since I last used it. All the way back in July-August 2022.

Yeah I have a nuc so I can't have 2.5 inch drives internally instead I'm using a 2.5inch drive connected to a hub over USB 3.0 and it's possible I unintentionally disconnect the drive which will cause a container to error out but I need a way of detecting when it's reconnected so I can simply restart the container rather than me doing it manually. It's rare that it happens but one less thing to remember if I can automate it.

The information about the connected devices is sent to the mqtt broker, so if you want you can create an automation that checks if your disk exists in the json. If it doesn't exists, it means that it is disconnected.
Currently I can't help you more, but I am sure that if you ask the home assistant community you can find all the information you need to create this automation.

Once I find the time, I will try to implement it, so that's easier for everyone.

commented

information about the connected devices is sent to the mqtt broker

Which topic is this sent under?

This is the topic it is sent:
<prefix>/<clientId>/monitor_controls/disk/usage

The json looks like this:

{
   "dev_sda4":{
      "total":109222.3,
      "used":62851.2,
      "free":40777.8,
      "percent":60.7
   },
   "dev_sda1":{
      "total":96.0,
      "used":35.0,
      "free":61.0,
      "percent":36.4
   }
}

If I disconnect/unmount the dev/sda4 it will send this:

{
   "dev_sda1":{
      "total":96.0,
      "used":35.0,
      "free":61.0,
      "percent":36.4
   }
}

Hope this helps for now.

Another solution you could do is create an automation that sends a bash command and watches for the result under the topic <prefix>/<clientid>/command_result/bash/bash_command.

commented

Another solution you could do is create an automation that sends a bash command and watches for the result under the topic <prefix>/<clientid>/command_result/bash/bash_command.

Both are great ideas thank you. I can figure out the rest and potentially use both options for redundancy.

I've made some changes and now it should show if the disk is connected or not.
You'll have to install LNXlink as a developer to test it.
I haven't tested it yet.

commented

I've made some changes and now it should show if the disk is connected or not.
You'll have to install LNXlink as a developer to test it.
I haven't tested it yet.

Awesome, I hope to test this over the weekend.

I've tested it and there is an issue with the disconnection of drives on home assistant logs, but it won't affect the frontend.