This tutorial is in addition to the very useful tutorial already in the Domoticz Wiki pages: https://www.domoticz.com/wiki/Presence_detection
Please read that first and do the steps until you reach the installation instructions for the script. From that point on I will explain how to get the script running on DSM/Synology systems.
My system: Domoticz (Jumbotroll package) on an HP Microserver Gen8 G1610T running DSM 5.1. I have the entire thing behind a VPN as an extra layer of security, but the steps should be the same for any Synology/DSM system.
1. Install Domoticz
You’ve probably already done this. I have the package installed by Jumbotroll (http://www.jadahl.com/). His work makes our lives very easy and he regularly updates his packages.
2. Install Python
The heroes of SynoCommunity have an easy to install Python package available. For instructions on how to install their packages go to: https://synocommunity.com/
Make sure to install Python, not Python3 or pyLoad. Just Python.
This is the easy part, the rest isn’t very hard, but it can easily become confusing if you’ve never done it before.
3. SSH
You will need to use SSH to get into the system files of your server/NAS. If you’re like me and you’ve never used SSH you’re in for some work. See, SSH is a command line type of system. So no easy clicking icons and stuff. It’s all keyboard when you’re using SSH. This is a handy site to keep open while doing this: http://sshcommands.co.uk/
I’m a Mac user so I’ve used Terminal to do everything, but PuTTY or WinSCP seem to be recommended on Windows. Linux users will probably know how to SSH, so no need to explain to them

You will be using the following commands:
cd - this will allow you to navigate folders
dir - this command will show you all the contents of a folder
mkdir - with this command you will make a folder in the folder you’re in at that point
vi - this command calls on the Vi editor. Lots of tutorials mention Nano or VIM, but Vi is already installed on your device and I have no idea how to install new programs through SSH. Doesn’t matter much though, the end result is the same.
4. So let’s turn on SSH on your Synology
Login to your NAS/server and open your control panel. Below you will see the option called ‘terminal’. Open it. There you can enable SSH. The standard port is 22. That’s fine, you can leave it at that. Then click save.
Make sure your firewalls allow you to access port 22.
5. SSH to your Synology
Open Terminal, PuTTY or WinSCP. You will see a black screen with the curser flashing. Type the following: ssh root@<ipadresstoyoursynology>
Press enter. You will now be asked to type your password. Note that while you enter it, the screen doesn’t show it. Just fill in your root password and press enter. Sometimes you will be promted with a message that this is the first time your IP is logging in. Just accept this.
Now you’ve SSH’d to your Synology and you can move around and do stuff. There’s a lot you’re now able to do (like screwing up your entire system). You can find this stuff out for yourself, but for now we’ll keep to making the presence check script work.
6. Create the location for the script
If you installed Domoticz through the package of Jumbotroll it’ll be place in /volume1/@appstore. You can check this by typing in the following: cd /volume1/@appstore
After the command press enter. The curser will jump to a new blank line and it’ll seem like nothing changed. On this line type the following: dir
When you press enter you’ll see a list of folders and files pop up. The command ‘dir’ shows you the contents of the folder you are currently in. You will see a folder called ‘domoticz’.
On Pi systems the scripts folder is located inside the domoticz folder. Often domoticz/scripts/python. However I’ve found that when you update the Domoticz folder it’ll delete the scripts folder. That means you would have to do this each time you update Domoticz. So I’ve decided not to install the scripts inside the Domoticz folder, but I’ve created a folder called ‘domoticzscripts’ in the @appstore folder.
You can do this by doing the following:
First make sure you are in the @appstore folder. You can do this with the following command: cd /volume1/@appstore
Give the ‘dir’ command to make sure you are inside the @appstore folder.
When you’re sure you’re in the right folder type the following: mkdir domoticzscripts and press enter. I’ve called my folder domoticzscripts, but you can name it anything you want.
Give the 'dir' command again to verify that your folder is now indeed there.
Go into this folder with the following command cd /volume1/@appstore/domoticzscripts and press enter.
You can give the dir command again to verify you are indeed in the right folder (the folder will be empty).
7. Creating the script
Now we'll be making the actual script. We'll be using VI. VI is an editor, but it works very differently than Word or Notepad for example. You have two modes. One is a command mode where you tell VI what you want it to do, and there is an editor mode. The commands you will be needing are as following:
ESC button - Enter command mode
I - Enter editor mode
x - remove character (backspace sort of)
set noautoindent - When you paste something in VI it'll automatically add a space to each line, this will cause problems with the script, so you want to turn it off
set autoindent - turn auto indent back on after you're done
:wq - Save and close file
:quit! - Close file without saving
Now go to Chopperrob's page and copy the script: https://www.chopperrob.nl/domoticz/5-re ... o-domoticz
Make sure to not copy the numbers. You only want the script.
When you've done this go back to Terminal/PuTTY/WinSCP and make sure you are in the domoticzscripts folder (cd /volume1/@appstore/domoticzscripts to make sure if you aren't). Then type: vi check_device_online.py
VI wil now open a new file called 'check_device_online.py'. You will see a blank page with some ~ on the left.
Now press the ESC button and type set noautoindent and press enter. It'll seem like nothing has changed, but you have now turned auto indent off. Now press the 'i' button on your keyboard. Again it'll look like nothing happened, but you are now in editor mode. Now right-click with your mouse on the top line and select paste. You will see that the script by Chopperrob is now pasted into VI. However it contains the wrong IP adress and possibly the wrong login details. We need to fix this. So use the arrow keys on your keyboard to move to the top of the window. There you will see on line 19, 20 en 21 that you need to fill in the details for your Domoticz server. If you're not sure what these are you can check them in your package center. Just click Domoticz and you can see the ip adress and port. To remove the old IP adress you can press the esc button to enter command mode and then press the x button to remove the details that are already present. To enter your own details again you'll have to press the letter 'i' on your keyboard allowing you to type.
If you have login details for Domoticz fill these in too. Otherwise just leave them blank, meaning there is nothing between the two quotation marks.
Once you've done that press the esc button and type :wq: and press enter.
You will be back in the domoticzscripts folder. If you put in the dir command you can see the folder contents and you will see your new script.
8. Testing the script
Now that you've done all this work you will want to make sure it works. You can do this by typing in python check_device_online.py <ipadress of device you want to check> <idx of your virtual switch> 10 30 and press enter. If everything works you will see a message that either your device is present or not. You can see the script work if you toggle the wifi on your device for example. If everything is working as it should you will also see the dummy switch in Domoticz switch between on and off. You will have to wait ten seconds for it to see it come back and 30 for it to go off again.
The hard work is done now and you can close Terminal/PuTTY/WinSCP.
9. Making sure the script keeps running and starts running automatically
In the original Wiki you have to set up a Cron job through SSH. Synology allows you to write Cron jobs through Task Scheduler. To do this login to your NAS and go to the control panel and click the task scheduler (it's under the Sytem tab). In this window click 'create' and select 'User-defined script'. This will open a window where you can do the following:
Task - This is the taskname, you can name this whatever.
User - This selects the user to run the script. Set this to 'root'
User-defined script - This contains everything you want Cron to start. You need to give in the full path to Python + the full path to your script + your arguments (ip adress, idx, intervals). If you have python installed on volume 1 and just the SynoPackage through package installer, your path to Python will likely be this '/usr/local/python/bin/python'. You separate the paths and arguments by spaces. So it should look like this:
/usr/local/python/bin/python /volume1/@appstore/<name_of_folder_you_made/check_device_online.py <ip_adress_of_device_you_want_to_check> <IDX> <Interval> <time-out>
This is what my task looks like:
/usr/local/python/bin/python /volume1/@appstore/domoticzscripts/check_device_online.py 192.168.1.1 6 10 120
Under schedule you can fill in how often you want the script to start. The original Wiki recommends to start it every ten minutes. Then just click save.
You can create the same task multiple times with different IP adresses if you want to check more than one device.
10. Wrapping up
After you're done I recommend restarting your NAS/server to see if everything starts running as it should when it comes back online. Just check it by turning off the wifi of the device you want to check, make sure your dummy switch is turned off in Domoticz also. Then restart the NAS/server and let it boot up along with Domoticz. Once everything is up and running turn on the wifi again on your device, wait a few seconds and see if the dummy switch turns on in Domoticz. If it does you're all set. If not, you've done something wrong. Just let me know and I'll see if I can help.
Good luck!