Hi all
After a hard and funny work i have mi XPENology DSM 5.1 (HP 54NL) working with Domoticz. I'm sysadmin and have some skill in development.
Material i use: kankunit smartplugs wifi (x4 relay.cgi hacked), 3x FIBARO x2 1.5 relay and Controller Aeon Labs Z-Stick S2
Version: domoticz_bromolow-5.1_2.0.2276-6.spk (openzw and usb drivers included) from this post
https://dl.dropboxusercontent.com/u/180 ... 2276-6.spk
Debian-Chroot from Synocommunity for sh scripting and cron tasks
I want to give back to the community the knowledge I have gained researching on the internet
Codes are not mine, i only repair and debug code to make it work on synologys
Install debian-chroot
- In DSM 5.1
- Add synocommunity source in packages center
- Setup --> Packages source, add
Synocommunity --
http://packages.synocommunity.com/
In General TAB enable "Any editor"
- Apply
- Go to community packages and install debian-chroot
- Enable Debian-chroot
SSHd synology NAS and enter in CHROOT session
Code: Select all
/var/packages/debian-chroot/scripts/start-stop-status chroot
Error code is normal.
(select en_US.UTF-8)
this repair error code
Install packages: I need in the next example
Enable crontab from debian-chroot- AND cron job to retrieve snmp info from QNAP NAS every 5 minutes (you can put any .sh you want, and install any package you can need with "aptitude install")
Exit CHROOT session. CTRL + D or exit
In synology, create shell script in /usr/local/rc.d (when synology starts always execute scripts in this dir with start parameter).
nano /usr/local/rc.d/crontabchroot.sh
Code: Select all
#!/bin/sh
# starts the chroot cron service on startup and stops it
# on reboot/shutdown
case "$1" in
start)
chroot /volume1/@appstore/debian-chroot/var/chroottarget /etc/init.d/cron start
;;
stop)
chroot /volume1/@appstore/debian-chroot/var/chroottarget /etc/init.d/cron stop
;;
*)
echo "Usage: $0 [start|stop]"
;;
esac
Code: Select all
chmod +x /usr/local/rc.d/crontabchroot.sh
Code: Select all
nano /volume1/@appstore/debian-chroot/var/chroottarget/etc/crontab
Add
Check every 5 minutes
Code: Select all
nano /volume1/@appstore/debian-chroot/var/chroottarget/usr/bin/qnap.sh
Code: Select all
#!/bin/bash
# Settings
NASIP="192.168.1.xxx" # NAS IP Address
PASSWORD="public" # SNMP Password
DOMO_IP="192.168.1.xxx" # Domoticz IP Address
DOMO_PORT="8084" # Domoticz Port
NAS_IDX="23" # Virtual switch NAS STATUS
CPU_TEMP_IDX="24" # Virtual temerature sensor IDX NAS CPU
HD1_TEMP_IDX="25" # Virtual temerature sensor IDX HD1
# Check if NAS in online
PINGTIME=`ping -c 1 -q $NASIP | awk -F"/" '{print $5}' | xargs`
echo $PINGTIME
if expr "$PINGTIME" '>' 0
then
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "On" > /dev/null
if [ $? -eq 0 ] ; then
# NAS already ON
echo "NAS already ON"
# Temprature CPU
CPUtemp=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.6.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"
# Temperature HD1
HDtemp1=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.11.1.3.1 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$HD1_TEMP_IDX&nvalue=0&svalue=$HDtemp1"
else
# NAS ON
echo "NAS ON"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$NAS_IDX&switchcmd=On"
# Temprature CPU
CPUtemp=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.6.0 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$CPU_TEMP_IDX&nvalue=0&svalue=$CPUtemp"
# Temperature HD1
HDtemp1=`snmpget -v 2c -c $PASSWORD -O qv $NASIP 1.3.6.1.4.1.24681.1.2.11.1.3.1 | cut -c 2-3`
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$HD1_TEMP_IDX&nvalue=0&svalue=$HDtemp1"
fi
else
curl -s "http://$DOMO_IP:$DOMO_PORT/json.htm?type=devices&rid=$NAS_IDX" | grep "Status" | grep "Off" > /dev/null
# NAS uitgeschakeld
if [ $? -eq 0 ] ; then
echo "NAS already OFF"
exit
else
echo "NAS OFF"
# Send data
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=switchlight&idx=$NAS_IDX&switchcmd=Off"
fi
fi
Code: Select all
chmod +x /volume1/@appstore/debian-chroot/var/chroottarget/usr/bin/qnap.sh
Enable qnap SNMP explained here:
http://www.domoticz.com/wiki/NAS_Monitoring.
- And create dummy switch and sensors
My qnap have only one HD. If you want to monitoring any other HD or remaining HD size go to
http://www.domoticz.com/wiki/NAS_Monitoring and view code
I Notice Remaining HD size code from wiki has bugged:
This part.....
Code: Select all
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$HD_REMAIN_IDX&nvalue=0&svalue=$size"
Returns: "1.68 TB" in my case, space betwen "8" and "T" makes url returns 404 response. TRim variable after pull data to Domoticz server solve problem. (i dont know how to).
Above info is valid to any sh cron job you want to launch
----------------------------------------------------------------------------------
Another objective achieved
Shutdown Windows computer (windows 7) from domoticz: chroot not needed
- SSHd Synology NAS
Code: Select all
nano /volume1/@appstore/domoticz/scripts/shutdown_PC.sh
Code: Select all
#!/bin/sh
#Shutdown Computer
# IP of computer and admin user needed
net rpc -S 192.168.1.xx -U USER%PWD shutdown -t 1 -f
(-f parameter force shutdown)
Code: Select all
chmod +x /volume1/@appstore/domoticz/scripts/shutdown_PC.sh
To no disable windows UAC you can insert reg info to accept RPC commands
In windows create reg file. enablerpcshutdown.reg
Code: Select all
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system]
"LocalAccountTokenFilterPolicy"=dword:00000001
- Execute to add to registry,
Enable remote registry service
- Execute CMD witch admin rights (search cmd in start button, right button in cmd.exe execute with admin rights)
Code: Select all
sc config RemoteRegistry start= auto
sc start RemoteRegistry
- reboot windows
In Domoticz create virtual switch
Switch type: push off button
Assign to off action:
"script://volume1/@appstore/domoticz/scripts/shutdown_PC.sh"
Save
Profit
I hope this can be useful to others and for me to remembers the steps to reproduce
Im noob on Domoticz (4 days) but, i'm very satisffied with my advances: blockly events to auto off some lights after time, Floorplan with image, Scenes (to lights off). I use OpenVPN to manage Domoticz from outside
. hahaha My Wife hate's me, 4 days with no time for her. But now i sure my children do not left any light on when we leave our house.
Next target LUA scripting.
Thanks to community and developers