Tag 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

send stuff to telegram bot command-line globally

preface

As you have seen in the other posts, I like to use a telegram bot for my notifications with domoticz. But I also like to use it to notify me from scripts.

After a while I found myself adding the same long ‘curl etc etc’-commands in every script, so it was time to create a little script that holds everything I need and can be used globally.

prerequisites

You need to have a telegram bot already up and running. Like earlier is found this tutorial to be pretty good.

code

create a new file called ‘tg’ and ‘chmod +x’ it. Then edit it like so:

#!/bin/bash
bot_id="insert your bot id here"
api_key="your api-key here"
chat_id="your chat-id here"
action="sendMessage"
curl -s "https://api.telegram.org/$bot_id:$api_key/$action?chat_id=$chat_id&text=$1"

After that create a symlink to ‘/bin/tg’. Because ‘/bin’ is usually in the ‘search path’ for commands it will be accessible from everywhere.

result

now you can use it ‘globaly’ from scripts or command line:

root@host:/$ tg "blabla bla"

And it will send your text to your Telegram bot:

screen-shot-2016-10-29-at-18-16-11

After updating Plex, Infuse cannot connect anymore

Preface

I sometimes use Infuse on my Apple TV to watch things. But after I upgraded my Plex server, suddenly Infuse was unable to connect to Plex. Took me a while before I found the correct setting responsible for this, so I thought I’d share it here.

Solution

Navigate to “Settings -> Server -> Network” and go here:

screen-shot-2016-10-23-at-10-15-09

Ofcourse, adjust the ‘192.168.0.0’ to your setup.

Result

Now you can connect with Infuse (and probably other affected third-party ‘Plex-clients’ as well) without authentication, which is good. Right?!

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!

push speedtest results to domoticz

Preface

I needed to monitor my internet bandwith because it was flappy.

Decided to push speedtest information to domoticz (easy graphs, easy notifications).

1. install speedtest (apt-get install speedtest-cli)
2. create 3 virtual counters in domoticz (and remember the idx’s)
3. create a script, put in the variables and chmod +x it
4. crontab -e it (I cron it @hourly)

Code

#!/bin/bash
#setup
host=xxx.xxx.xxx.xxx
port=xxxx
username=xxx
password=xxx
pingidx=xxx
downloadidx=xxx
uploadidx=xxx
#
# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"

# Push -> domoticz
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"

Result

screen-shot-2016-10-22-at-19-57-29