Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Enter an "Event Name", for example, "{tag is _in_range}" and select "Create trigger". This will take you back to:

...

Now, do the same steps again to create a second applet, but for the second one, enter another "Event Name", for example, "{tag is NOT _not_in_range}".


Once you have two applets created → check the web request URL that was generated for you. Go to the link and click on the "Documentation" button:

...

You can copy the script below. Copy the script below into a "notepad" and copy it again into the script "Source:" field.

### User parameters
:local addressRegex "DC:2C:6E:91:D6:F3"
:local urlNotInRange "https://maker.ifttt.com/trigger/{tag_not_in_range}/json/with/key/-xxxx"
:local urlInRange "https://maker.ifttt.com/trigger/{tag_in_range}/json/with/key/-xxxx"
:local missingInterval 60000

###Time
:global EpochTime do={
:local ds [/system clock get date];
:local months;
:if (((###Time
:global EpochTime do={
   :local ds [/system clock get date];
   :local months;
   :if ((([:pick $ds 9 11]-1)/4) != (([:pick $ds 9 11]-1)/4) != (([:pick $ds 9 11])/4)) do={
      :set months {"an"=0;"eb"=31;"ar"=60;"pr"=91;"ay"=121;"un"=152;"ul"=182;"ug"=213;"ep"=244;"ct"=274;"ov"=305;"ec"=335};
   } else={
      :set months {"an"=0;"eb"=31;"ar"=59;"pr"=90;"ay"=120;"un"=151;"ul"=181;"ug"=212;"ep"=243;"ct"=273;"ov"=304;"dec"=334};
   }
   :set ds (([:pick $ds 9 11]*365)+(([:pick $ds 9 11]-1)/4)+($months->[:pick $ds 1 3])+[:pick $ds 4 6]);
   :local ts [/system clock get time];
   :set ts (([:pick $ts 0 2]*60*60)+([:pick $ts 3 5]*60)+[:pick $ts 6 8]);
   :return ($ds*24*60*60 + $ts + 946684800 - [/system clock get gmt-offset]);
}

:local Epomili
:set Epomili ([$EpochTime]."000")

###Bluetooth
:local addressRegex "DC:2C:6E:91:D6:F3"adver
:local adver2
:local ts
:local adverclockmin

:set adver [/iot bluetooth scanners advertisements print detail as-value where address ~ $addressRegex]
:global set adver2
:set adver2 ($adver->0)
:global ts
:set ts ($adver2 -> "epoch")
:global clockmin
:set clockmin ($Epomili-60000$missingInterval)

:global counterIN
:global counterOUT

:if ($ts<=$clockmin) do={
                     :set $counterIN 0;
                     :if ($counterOUT=0 or $counterOUT=null) do={
                                                         :set $counterOUT 0;
                                                         /tool fetch http-method=get output=user url="https://maker.ifttt.com/trigger/{The_tag_is_NOT_in_range}/json/with/key/-xxxxx";
                                                         :set counterOUT ($counterOUT+1);
                                                         :log info "IFTTT notification - the tag is OUT OF range!"} else={
                                                                                                                  :log info "Tag is OUT of range! Notification was already sent before!"}} else={
                                                                                                                                                                           :set $counterOUT 0;
                                                                                                                                                                           :if ($counterIN=0 or $counterIN=null) do={
                                                                                                                                                                                                                                    :set $counterIN 0;
                                                                                                                                                                                                                                    /tool fetch http-method=get output=user url="https://maker.ifttt.com/trigger/{The_tag_IS_within_range}/json/with/key/-xxxxx";
                                                                                                                                                                                                                                    :set $counterIN ($counterIN+1);
                                                                                                                                                                                                                                    :set $counterOUT 0;
/tool fetch http-method=get output=user url=$urlNotInRange;
:set counterOUT ($counterOUT+1);
:log info "IFTTT notification - the tag is OUT OF range!"
} else={
:log info "Tag is OUT of range! Notification was already sent before!"
}
} else={
:set $counterOUT 0;
:if ($counterIN=0 or $counterIN=null) do={
:set $counterIN 0;
/tool fetch http-method=get output=user url=$urlInRange;
:set $counterIN ($counterIN+1);
:log info "IFTTT notification - tag IS WITHIN range!"
} else={
:log info "Tag is WITHIN the range! Notification was already sent before!"
}
}


There are 3 lines that need to be taken into accounttaken into account (in the ### User parameters part of the script).

1) MAC address line:

:local addressRegex "DC:2C:6E:91:D6:F3"

...

2) Not in range notification URL line:

 /tool fetch http-method=get output=user url=:local urlNotInRange "https://maker.ifttt.com/trigger/{The_tag_isnot_NOT_in_range}/json/with/key/-xxxxxxxxx";

the line, where you need to input the URL that was generated for you by the IFTTT service. The URL should look like this → https://maker.ifttt.com/trigger/{event}/json/with/key/-xxxxx". Change the {event} part of the URL to the "Event Name" that was chosen in the IFTTT portal when creating an applet and change the -xxxxx part of the URL to the key that was generated for you by the IFTTT portal.

3) In range notification URL line:

/tool fetch http-method=get output=user url=:local urlInRange "https://maker.ifttt.com/trigger/{The_tag_IS_withinin_range}/json/with/key/-xxxxxxxxx";

the line, where you need to input the URL that was generated for you by the IFTTT service. The URL should look like this → https://maker.ifttt.com/trigger/{event}/json/with/key/-xxxxx". Change the {event} part of the URL to the second "Event Name" that was chosen in the IFTTT portal when creating your second applet and change the -xxxxx part of the URL to the key that was generated for you by the IFTTT portal.

...