Samsung Smart Aircon and MRTG

We’ve had 4 Samsung Smart air conditioners for a few years and every once and a while I revisit trying to automate them using scripts and a like. This time I was successfull using perl scripts written/edited by Daniel (CloCkWeRX) and Shannon (freman) to deal with the transmission protocol and token management – I personally would’ve never been able to work it out – so thanks and full credit to them. To start with, you have to discover then register the aircons to get a token for each, to discover them you can use this script get_samsung.pl, which was obtained then slightly modified from here. That script output:
perl get_samsung.pl
Waiting for responses
$VAR1 = {
'modelcode' => 'SAMSUNG_DEVICE',
'mac_addr' => '',
'cache_control' => 'max-age=60',
'decoded_nickname' => 'Office',
'spec_ver' => 'MSpec-1.00',
'notify * http/1.1' => undef,
'server' => 'SSDP,SAMSUNG-AC-BORACAY',
'nickname' => '',
'nts' => 'ssdp:alive',
'service_name' => 'ControlServer-MLib',
'message_type' => 'DEVICEDESCRIPTION',
'location' => 'http://',
'host' => '255.255.255.255:1900'
};
From here you can get the IP address of the aircon and now make a request to register the device and get a token file using this script.
perl samsung.pl <ipaddress> register
Turn off the aircon if it's turned on then pres enter.
Turn the aircon back on again, and you should see a success (I forget the exact words).
From there, I’m interested in polling the current temperature from each over a period of time and graph the results. MRTG will do for the graphing, and it’s pretty easy to setup.
/etc/mrtg.cfg additions
...
Title[Front_Lounge]: Front Lounge Temp
PageTop[Front_Lounge]: <H1>Front Lounge Temp</H1>
Target[Front_Lounge]: `/etc/mrtg/temps.sh <removed ip>`
MaxBytes[Front_Lounge]: 10000
YLegend[Front_Lounge]: Temp c
ShortLegend[Front_Lounge]: c
Options[Front_Lounge]: integer, nopercent, gauge
...
 
Create /etc/mrtg/temps.sh 
ping $1 -c 1 > /dev/nul 
if [ $? = 0 ] 
then 
perl /etc/mrtg/samsung.pl $1 status |grep "Current temperature"|cut -d ":" -f 2- |xargs 
echo 0 
uptime 
echo $1 
else 
echo 0 
echo 0 
uptime 
echo $1 
fi
As long as you have registered the aircon the output of temps.sh should be similar to this:
/etc/mrtg/temps.sh 10.0.0.10
28
0
14:39:33 up 5 days, 19:31,  1 user,  load average: 0.02, 0.03, 0.05
10.0.0.10
It seems to be a little hit and miss. The Android app also doesn’t show all of the devices at all times. After a few hours it appears the temps.sh script is having time out issues – which appears to be an issue with one of the aircons dropping wifi signal. Changes to the script have been added above, now it checks if the aircon is pingable before proceeding, if it’ll output: zero’s for the temp. That will give random drops in the graphs, but if you don’t get random wifi drop outs like me, you wont have that issue.
MRTG Graphing Temperatures

MRTG Graphing Temperatures

Cheers. Sources

Leave a Reply

Your email address will not be published. Required fields are marked *

*