„Domoticz - MikroTik presence management” változatai közötti eltérés

Innen: IT documentation
23. sor: 23. sor:


== MikroTik ==
== MikroTik ==
The MikroTik router can trigger a script when DHCP leases change, so enough that the current script run at this event, although may occur in communication between MikroTik-Domoticz occur an error, so it is worth the script running by scheluded too. Recommended schelude: the DHCP lease time.
The MikroTik router can trigger a script when DHCP leases change, so enough that the current script run at this event, although may occur in communication between MikroTik-Domoticz an error, so it is worth the script running by scheluded too. Recommended schelude: the DHCP lease time.


Put the datas of the users into the below script logically like mac address of mobile device and the domoticz user variable belonging to user and the domoticz api URL.
Put the datas of the users into the below script logically like mac address of mobile device and the domoticz user variable belonging to user and the domoticz api URL.

A lap 2022. január 3., 14:45-kori változata


Summary

In this method the base of presence will be a mobile device of the user. If the device connected to the home network then we consider that the user is at home.

A MikroTik router script is watching that the mac address of the device is present in the network and report this to the Domoticz Home Automation System. A Domoticz Lua script manages the arrives and the leaves and related events.

Features

  • Multiple users usage.
  • Turn on specified light(s) after sunset when somebody arrives.
  • Turn off specified light(s) and set the heating to tempering mode when these is nobody at home.
  • Set the heating to normal mode (preveous temperature values per thermostat) when somebody arrives.

Prerequisites

  • Have to know the mac address of the mobile device(s)
  • Have to create a dummy "thermostat setpoint" device in the Domoticz, this is going to control the temperature of absence.
  • Have to create an integer user variable, what is going to store that the system is presence (1) vagy absence (0) mode.
  • Have to create two integer user variable per user, these are going to store that thes user is present or not, and the preveous state, that the change can be perceptible.
  • Have to create an integer user variable per thermostat, in what the temperature value of presence mode will be stored.

MikroTik

The MikroTik router can trigger a script when DHCP leases change, so enough that the current script run at this event, although may occur in communication between MikroTik-Domoticz an error, so it is worth the script running by scheluded too. Recommended schelude: the DHCP lease time.

Put the datas of the users into the below script logically like mac address of mobile device and the domoticz user variable belonging to user and the domoticz api URL.

After save the script as "Domoticz_Presence", the script policy is enought if it is read only (read, policy, test)

## Parameters

:local DomoticzURL "http://192.168.1.10:8080/json.htm"
:local items {
{
   pres="USER1_PRESENCE";
   mac="AA:BB:CC:DD:EE:FF";
};
{
   pres="USER2_PRESENCE";
   mac="00:11:22:33:44:55";
};
}

## Assistant variables

:local searchMac

## Logic

:foreach item in=$items do={

   :set searchMac [/ip dhcp-server lease find mac-address=($item->"mac") ]

   if ([:len $searchMac]>0) do={

      /tool fetch mode=http url=$DomoticzURL http-data="type=command&param=updateuservariable&vname=$($item->"pres")&vtype=INTEGER&vvalue=1" output=none

   } else={

      /tool fetch mode=http url=$DomoticzURL http-data="type=command&param=updateuservariable&vname=$($item->"pres")&vtype=INTEGER&vvalue=0" output=none

   }

}