Category Archives: domoticz

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

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!

use a Foscam ipcam as motion & sound detector

Preface

I wanted virtual motion and sound detectors in Domoticz to be able to script with.

Created a script which reads out the motion and sound flags (my cam has motion and sound detection capabilities on board and offers them trough the web-interface).

  1. no external packages needed;
  2. note: usually the default port on foscams is 88!
  3. chmod +x the hell out of it before use (I keep forgetting that)
  4. schedule it every minute (logic is in the script)

Code

#!/bin/bash
# Script to use the sound detection features of your Foscam (e.g. C1) and use these as virtual sensors in Domoticz
# Schedule this every minute with crontab -e, for example: */1 * * * * /path/to/script/foscam.sh
# variables to change so your setup
#
FOSCAMIP="xxx.xxx.xxx.xxx"
FOSCAM_PORT="xx"
FOSCAM_USER="xxx"
FOSCAM_PASS="xxx"
#
DOMO_IP="xxx.xxx.xxx.xxx"
DOMO_PORT="xxx"
DOMO_USER="xxx"
DOMO_PASS="xxx"
#
FOSCAM_SOUND_IDX="xxx"
FOSCAM_MOTION_IDX="xxx"
#
# no need to edit after this point ...
# foscam sound detection loop is 5s by default. 5s * 12 = 1 minute (for cron can only schedule every minute)
for i in {1..12}
do
# if cam is pingable continue, else don't do anything.
if ping -c 1 $FOSCAMIP &> /dev/null
then
curl "http://$FOSCAMIP:$FOSCAM_PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=$FOSCAM_USER&pwd=$FOSCAM_PASS" > Foscam.txt
# check motionDetectAlarm and soundAlarm flags
FOSCAMSound=`grep -oP '(?<=).*(?=<\/soundAlarm>)' Foscam.txt`
FOSCAMMotion=`grep -oP '(?<=).*(?=<\/motionDetectAlarm>)' Foscam.txt`
#check for sounddetection & flip FOSCAM_SOUND_IDX switch if so
if [ $FOSCAMSound = "2" ];
then
curl -s -i -H "Accept: application/json" "http://$DOMO_USER:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$FOSCAM_SOUND_IDX&switchcmd=On&level=0"
fi
#check for motiondetection & flip FOSCAM_MOTION_IDXswitch if so
if [ $FOSCAMMotion = "2" ];
then
curl -s -i -H "Accept: application/json" "http://$DOMO_USER:$DOMO_PASS@$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=switchlight&idx=$FOSCAM_MOTION_IDX&switchcmd=On&level=0"
fi
fi
# sleep 5s and go back to loop (12x for 1 minute)
sleep 5
done

Result

screen-shot-2016-10-22-at-18-34-06

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