Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

You'll need to download BlueToothCL.exe from http://www.nirsoft.net/utils/bluetoothcl.html and I placed in "C:\Windows\System32\" for easy access via CLI.

Here is my PowerShell Script:

$Date = Get-Date 
Write-Output "Start Script At $Date"
function Test-BTMacSearch {
        param (
            [String]
            $MAC,
            [int]
            $TIMEOUT
        )
        IF (!$TIMEOUT) {$TIMEOUT = 15}
        $searchresults = BlueToothCL -timeout $TIMEOUT | Select-String -Pattern $MAC
        IF ($searchresults -ne $null) {return $TRUE} ELSE {return $FALSE}
}
$MAC = "##:##..."
$TIMEOUT = "10"
$WebHookURL= "https://freesoftwareservers.com/api/webhook/webhook_id"
$BeaconMacFound = $False
WHILE ($BeaconMacFound -ne $TRUE) {
$BeaconMacFound = Test-BTMacSearch -MAC $MAC -TIMEOUT $TIMEOUT
#Write-Output "BeaconMacFound = $BeaconMacFound"
 If ($BeaconMacFound -eq $True) {
  $Date = Get-Date 
  Write-Output "BeaconMacFound True Statement Running at $Date"
  Invoke-WebRequest -Uri $WebHookURL -Method POST
  sleep 1800 #Sleep 30 Minutes
  $BeaconMacFound = $False #NeverEnding Loop $BeaconMacFound will always = $False at start of While Loop
 }
}

Notes:

  • This is meant to be run at windows startup and just continue running forever. I will setup via simply putting a shortcut to the script in my startup folder but you can use "Task Scheduler" or whatever...  See Start PowerShell Script via Task Scheduler - Windows 10
  • I set sleep to 30 minutes so it doesn't trigger over and over, it's for tracing a beacon in my car so it should only post when I'm home
  • I have to figure out best way to not have it trigger when I'm turning on vehicle outside, perhaps time of day, or condition of me not being already home
  • Will not be useful for triggering "away" as it's not usually visible, for that I use PING to lock my door and GPS to do a full "shutdown" of the house.
  • I simply added a "WebHook ID" to my existing home automation and it worked!
  • Use BluetoothCL.exe once to get proper format of string for MAC address, you could use other params, but I just decided to use MAC

Sources:

https://superuser.com/questions/1071723/get-mac-address-of-detected-bluetooth-devices
https://superuser.com/questions/1589008/watching-for-bluetooth-beacons-has-been-disabled-by-the-user-windows-10/1589045#1589045
https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger

https://community.home-assistant.io/t/windows-10-ibeacon-scanning-to-send-alert-to-ha/230598

  • No labels