Domoticz presence detection
Want to add your smartphone,tv, receiver or other device in Domoticz? Use the check_device_online.py script!
As soon as my Smartphones connects to my home wifi, the status in Domoticz will switch from Off to On, in my case from “Uit” to “Aan” (dutch) 🙂
I also use this script to retrieve the status of my Onkyo home theater receiver, and added a OFF script, now it’s possible to shutdown the Onkyo player from inside Domoticz!
First logon on your raspberry pi and browse to this folder
and use this command to download the script
Make the script executable:
sudo chmod +x check_device_online.py
Open the script
and change the following lines according to your Domoticz setup:
domoticzserver="192.168.1.76:8080" domoticzusername = "username" domoticzpassword = "password" domoticzpasscode = "passcode"
Change the server ip yo your own Domoticz server, and if you use a username and password, fill it in between the “”.
sudo apt-get update sudo apt-get upgrade sudo apt-get install python
Pyton already installed? Perfect!
Open Domoticz and add a Virtual Dummy switch.
Setup -> Hardware
Now go to the Switched tab, and click on the ‘Manual Light/Switch’ button in the upper left corner.
Your new switch is now visible in the Domoticz switch menu.
We need to know the IDX number of the new switch:
Setup-> Devices. And look for your new button. In my case the IDX number is 45.
The script needs 4 parameters to run:
The IP-address of the device you want to check (In my case ‘192.168.1.15’)
The ID of the virtual switch (In my case ’45’)
The interval (seconds) on which to check if a device is present or not (In my case ’10’, for 10 seconds)
The ‘cool-down’ period (seconds). If a device does not respond within this period, the virtual switch is turned off. (In my case ‘120’, for 120 seconds, or 2 minutes)
python check_device_online.py 192.168.1.15 45 10 120
Your console output will be something like this:
19:43:21- script started. 19:43:21- according to domoticz, 192.168.1.15 is online 19:43:22- 192.168.1.15 offline, waiting for it to come back
Exit the script with Control + C
The best way is to create a cronjob for the script:
sudo crontab -e
And add your line on the bottom:
*/10 * * * * /home/pi/domoticz/scripts/check_device_online.py 192.168.1.15 45 10 120
Save & exit with
If you don’t want to use Cron, and just want to run the script from the command line. Use the program “screen”
Screen makes it possible to close a open SSH session, and it will remains open when it’s closed. It’s one of my own most used Linux programs.
Script credits: Chopperob, sadly his website not working atm.
All this info is also available at the Domoticz wiki page, but not with the fancy screenshots.
And the most important reason, my website is online, often the source website is offline after a while when i need some of the information again.