Category Archives: debian

How to monitor your diskhealth with domoticz’s virtual percentage sensors

preface

I was wondering how much I wore down my SSD after a few years of heavy domoticz usage. I really like the graphing functionality of domoticz to keep track of stuff and I have implemented a script that notifies me with Telegram when interesting stuff happens, so I wanted to monitor my disk health with domoticz, thought I’d share.

prerequisites

Install smartmontools

sudo apt-get install smartmontools

2. Create 1 [u]Virtual Sensor of the type ‘Percentage'[/u] (for SSD Health-value) and remember the idx (you need that later on) in Domoticz.

code

Create a script (Let’s call it ssdhealth2domo.sh) with:

#!/bin/bash
#setup
host=xxx.xxx.xxx.xxx
port=xxxx
username=xxx
password=xxx
ssdhealthidx=xxx
# no need to edit
ssdhealth=$(sudo smartctl --all /dev/sda | grep Wear_Leveling_Count | awk '{print $4}')
#output if you run it manually
echo "SSD Health = $ssdhealth%"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command¶m=udevice&idx=$ssdhealthidx&svalue=$ssdhealth"

I ‘grep’ the Wear_Leveling_Count out of the test-results-table because this gives me the best indication of wear-and-tear of my disk (Samsung) after what I have read. Some manufacturers use ‘one of the other’ indicators, so do some reading on what is the best indicator for your type of disk.

Don’t forget to make it executable (I always do … ):

chmod +x ssdhealth2domo.sh

And add the stuff to the crontab:

@daily sudo /usr/sbin/smartctl -t long /dev/sda
@daily /path/to/script/ssdhealth2domo.sh

smartctl now does a daily ‘long’ test on your /dev/sda disk at midnight. Because this is spawned to the background and ‘takes a while’ (in my case about 20 minutes) the second line in crontab will probably send the test-results from ‘yesterday’ to domoticz. But hey, better safe & late than sorry & never right ;)

result

If setup correctly, domoticz will receive your disk-health daily, so when it breaks you might be there in time to replace it without loss of data (no guarantees from me ofcourse :) )

screen-shot-2016-11-29-at-22-51-31

Clean out the trash from your media-folders

Preface

I’m a big fan of movies and series and use a combination of Couchpotato, Sickbeard & Sabnzbd to download. Then, I feed everything to Plex which adds meta-data, makes it look pretty and available on my Apple TV to watch. Works like a charm.
What annoyed me, was that when I deleted a movie with the Plex GUI, it just deletes the media-file (e.g. just the .mkv or whatever) but leaves all the surrounding trash and the folder which contained the file as well.
So I created a few one-liners to ‘find’ the trash, delete it, and finally delete the empty folders.

Also, you must enable, or allow ‘media deletion’ on your plexmediaserver (it’s a setting in ‘Settings -> Server -> Library) but after that I experienced that the tools I use for downloading and the Plex-clients use different permissions (so I ended up with a Plex-client that does not have the right permissions to delete the files.)

screen-shot-2016-10-23-at-10-10-45

Warning: it’s not pretty, this should probably be done in a nice little script and can be done much more clean, but this was a quick hack and I want the syntax to be here for future reference, so don’t bash me for that .

Code

Example to correct the permissions (bad hack!) & find all the garbage-files recursively in the media folders and zap them to oblivion:

@daily sudo chmod -R 777 /media/media
@daily sudo find /media/media -name "*.nzb" -type f -delete
@daily sudo find /media/media -name "*.idx" -type f -delete
etc ..

Then when you cleaned out the folders, you can (at your own risk ofcourse) safely use:

@daily sudo find /media/media -type d -empty -delete

which will ‘find’ things with ‘type d’ (that are directories ;) ) which are ‘-empty’ and deletes ’em.

Result

A nice and clean media library! Hurray!

Automatic subtitle downloader

Preface

I’m a real big fan of Plex and installed plexmediaserver on my Debian box. But there is one thing Plex seems to lack which is automatic subtitle downloads (which I think is pretty weird, because it’s really good at anything else media related (this seems missing guys!).

Anyway, I found the package ‘subliminal’ to be useful. Created a small one-liner that crawls through my media-library and adds the (not of all the time) correct subtitles to my movies and series.

Code

Install the package like so:

sudo apt-get install subliminal

Then add it to cron like so:

@daily subliminal download -l nl en /media/media/TV\ Shows/
@daily subliminal download -l nl en /media/media/Movies/

This makes sure subliminal runs ‘daily’, crawls through both libraries and tries to fetch the Dutch (nl) and English (en) subtitles and saves them next to the files. That way Plex can easily spot them and offer them when available.

Makse sure to change the path’s to your correct media-libraries. I explicitely created two entries for TV Shows and Movies, because I have two other libraries in /media/media/ that don’t need subtitles. Let’s just say that the ‘stories’ or dialogues in these libraries are not thatimportant .

Result

Fresh subtitles every day!

Automatic NPO watchlist downloader (Dutch television)

Preface

I have been waiting (and waiting) for an app for my Apple TV for a long time now, but it seems to never come. I started looking around for alternatives and stumbled upon flexget, which offers a pluggable framework to ‘get’ stuff media related.
Next to that, I found another useful tool, download-npo, which can download episodes from the NPO-website command-line.
Third, someone created a plugin for Flexget (npo_watchlist) which ties these two together.
Because this is used by Dutch people only and then very few of them I guess, there’s not a lot of support available, so I thought I’d share my setup, because it gave me quite some headaches to get up and running, but looking back it was pretty easy if you know how.

1. Install flexget
2. Install download-npo
3. Create an NPO-account
4. Create a config-file
5. Add it to cron

Code

1. Install Flexget
Make sure you have Python running and install it with pip (this makes it easier to upgrade later on)

sudo pip install --upgrade setuptools
sudo pip install flexget

2. Install download-npo

pip install download-npo

3. Navigate to the NPO-website and create an account.

4. Create a config file
Flexget will look at several places for it’s config-file, I put everything in my ~/.flexget folder. The config file is called ‘config.yml’ and for the npo_watchlist plugin to work it needs minimal information, see this link for the setup.

screen-shot-2016-10-23-at-09-13-18

Updating is easy with pip:

sudo pip install --upgrade setuptools
sudo pip install --upgrade flexget
sudo pip install --upgrade download-npo

5. Add it to cron (crontab -e)

@hourly /usr/local/bin/flexget --cron execute

Results

Flexget now downloads the new episodes to my Plex directory where they are automatically added to a library I called “DVR”. Now every show I add to my watch-list or favorite-list in my NPO-account will be downloaded to Plex so I can watch it on my Apple TV .