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

Automatic domain checker & notifier

Preface

I have been chasing a couple of domain names I want to register for a while now, and these are either registered by someone else, or taken by a broker who wants to have big money for them. Every once in a while I’m checking them (when I think of it) but this will probably leave me empty handed so I thought of an idea to do this automagically and send me a message whenever they are available. Created a little script, added it to cron and tested the notifications.

Code

#!/bin/bash
domain=$1
test=$(whois $domain)
if [ "$test" = "$domain is free" ];
then /usr/bin/curl -s "https://api.telegram.org/your_bot_id:your_api_key/sendMessage?chat_id=your_chat_idtext= $domain = free"
fi

Ofcourse you can plugin your own notification system or add ‘your_bot_id’, ‘your_api_key’ and your_chat_id in this script.

Add it to the crontab:

@daily /path/to/script/whois2tg.sh thisisfree.nl

Result

It will only send a message when the domain is ‘free’ like so:

screen-shot-2016-10-26-at-19-07-26

Small but handy, thought it was worth sharing …

Telegram & domoticz hand in hand

Preface

I have been a Telegram-fan since the beginning. It’s snappy, pluggable, and allows for alot more customization then WhatsApp or other more ‘closed’ instant messengers. And ever since Facebook ‘owns’ Whatsapp it’s supposed to be ‘more private’ (but who knows). Next to that is has IM-clients for every platform, which is useful.

The ‘Telegram Bot’ functionality is especially fun and I have been using it since it was available for sending ‘push notifications’ to my iPhone. It can be added as a custom notifier to domoticz quite easily, but I always forget how to, so here’s my post on how I did it (for future reference).

First, setup a Telegram-bot. very nice guide here. Also pay attention on how to use it with ‘wget’ or ‘curl’. Very useful in scripting, I use that alot as well.

Code

Add all the relevant stuff here (under Setup -> Settings -> Notifications):

screen-shot-2016-10-25-at-19-33-40

After that you can use it on everything that has the ‘Notifications’ button:

screen-shot-2016-10-25-at-19-36-17

Add a notification with a ‘relevant’ threshold:

screen-shot-2016-10-25-at-19-39-30

You can use the ‘$name’ & ‘$value’ to send the name of the current device and the current value in the message itself. Oh and I like the pretty Apple emoticons too much, I know …

Result

screen-shot-2016-10-25-at-19-43-42

Oooh pretty! Thanks Jarvis!

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?!