0x00 Intro

Adding presence "detection" to domoticz throu the Mikrotik DHCPD
This is based on the script from rodaman from Domoticz forum.

0x01 The Script

# DHCP Leases to Domoticz
# On-Lease Script

# Phones MAC
:global fMAC "AA:AA:AA:AA:AA:AA";
:global sMAC "BB:BB:BB:BB:BB:BB";

# Globals
:global leaseBound
:global leaseServerName
:global leaseActMAC
:global leaseActIP

#
# Script
#
# Insert on Bound

:if ($leaseBound =1) do={
 :if ([$leaseActMAC] = $fMAC)  do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=240&switchcmd=On" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }
 :if ([$leaseActMAC] = $sMAC)  do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=241&switchcmd=On" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }
}

:if ($leaseBound =0) do={
 :if ([$leaseActMAC] = $fMAC) do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=240&switchcmd=Off" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }

 :if ([$leaseActMAC] = $sMAC) do={
    /tool fetch mode=http url="http://192.168.1.111:8181/json.htm?type=command&param=switchlight&idx=241&switchcmd=Off" dst-path=http_response.txt;
    # display the contents of the file with the server's response
    :local httpResponse [/file get http_response.txt contents];
    :log info "HTTP server response: $httpResponse";
    }
}

0x02 Adding to domoticz

As you probably expect, we need to create a dummy device for every device's presence.
You go to Setup > Hardware > Create Virtual Sensor (dummy device)

Presinstance Phone

As sensor type you need to select Switch.
After that you just need to see what IDs the new device(s) you just created have.
You can to that by checking in Setup > Devices.

0x02 Editing the script

Before we add the script to our Mikrotik router, we need to make few small changes.
We already have the new IDs that we'll be using generated in Domoticz.
So we need to edit:

0x03 End result

End result is something like this:

Presinstance