Mikrotik script for phones/devices presence.

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

Post Reply
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Mikrotik script for phones/devices presence.

Post by rodaman »

Hi,
I have just written script for Mikrotik dhcp server lease which send json/url command to Domoticz . Interested anybody? :?:
kniazio
Posts: 200
Joined: Thursday 06 October 2016 8:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7243
Contact:

Re: Mikrotik script for phones/devices presence.

Post by kniazio »

Show this script
rodaman
Posts: 23
Joined: Tuesday 29 November 2016 16:17
Target OS: -
Domoticz version:

Re: Mikrotik script for phones/devices presence.

Post by rodaman »

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: 2
Joined: Thursday 24 May 2018 15:53
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by dio45rus »

Thanx! Simple and very useful!
seansco
Posts: 19
Joined: Tuesday 01 March 2016 20:51
Target OS: Linux
Domoticz version:
Contact:

Re: Mikrotik script for phones/devices presence.

Post by seansco »

nice!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest