Mikrotik script for phones/devices presence.

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.
Post Reply
rodaman
Posts: 11
Joined: Tuesday 29 November 2016 17:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Mikrotik script for phones/devices presence.

Post by rodaman » Thursday 29 March 2018 17:07

Hi,
I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody? :?:

kniazio
Posts: 78
Joined: Thursday 06 October 2016 8:14
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by kniazio » Thursday 29 March 2018 17:52

Show this script

rodaman
Posts: 11
Joined: Tuesday 29 November 2016 17:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by rodaman » Friday 30 March 2018 8:27

Here is the script. I am very new of Mikrotik scripting so it is very simple but working. You have to put the script in DHCP Server/DHCP section in Mikrotik router. Change MAC adresses and Domoticz IP:Port and IDX's of devices. Router send command "Off" after expires time (10 min. default).

Code: Select all

# *. by RouterOS
#
# DHCP Leases to Domoticz
# On-Lease Script
#

# Phones MAC
:global RomekMAC "AA:AA:AA:AA:AA:AA";
:global GosiaMAC "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] = $RomekMAC)  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] = $GosiaMAC)  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] = $RomekMAC) 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] = $GosiaMAC) 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";
    }	
}

dio45rus
Posts: 5
Joined: Thursday 24 May 2018 15:53
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by dio45rus » Friday 25 May 2018 9:03

Thanx! Simple and very useful!

seansco
Posts: 19
Joined: Tuesday 01 March 2016 21:51
Target OS: Linux
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by seansco » Tuesday 25 September 2018 20:08

nice!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest