I created an Arduino IDE Hubitat Tile presence device using an Adafruit Huzzah32, which includes both Wifi and Bluetooth Low Energy on the board. The device also requires using the ST_Anything Parent Device code and knowing the MAC address of the Tile. (You can use the BLE_scan example code to get the Tile MAC address.) You can easily modify the code to allow the Huzzah to using search for additional Tiles.
//******************************************************************************************
// File: ST_Anything_TilePresence_ESP32WiFi.ino
// Authors: Scott Miller adapted from code by Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
// Summary: This Arduino Sketch, along with the ST_Anything library and the revised SmartThings
// library, demonstrates the ability of an Adafruit Huzzah32 to
// implement a Tile presence sensor for integration into SmartThings/Hubitat.
// The ST_Anything library takes care of all of the work to schedule device updates
// as well as all communications with the Adafruint Huzzah32's WiFi.
//
// ST_Anything_TilePresence_ESP32WiFi implements the following ST Capability
// - 1 x Presence device (reading digital input set by BLE scans)
// The Arduino example app BLEScan can be used to discover the MAC address of your Tile, which has a serviceUID "feed".
//
// Change History:
//
// Date Who What
// ---- --- ----
// 2019-10-12 Dan Ogorchock Original Creation
// 2020-02-10 Scott Miller Modified for sensing Tiles using Bluetooth Low Energy
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP32WiFi
//******************************************************************************************
#include <SmartThingsESP32WiFi.h>
//******************************************************************************************
// ST_Anything Library
//******************************************************************************************
#include <Constants.h> //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h> //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h> //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input
#include <PollingSensor.h> //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h> //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications
#include <IS_Presence.h> //Implements a Presence Sensor (IS) to monitor the status of a digital input pin
//******************************************************************************************
// ESP32_BLE Library
//******************************************************************************************
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 5; //In seconds
std::string TILE_MAC_ADDRESS_1 = "c1:62:85:c0:84:5d"; // <---You must edit this line with the MAC address of your device
BLEScan* pBLEScan;
//****************************************************************************************************************************
//NodeMCU-32s ESP32 Pin Definitions (just for reference from ..hardware\espressif\esp32\variants\nodemcu-32s\pins_arduino.h)
//****************************************************************************************************************************
//#define LED_BUILTIN 2
//#define BUILTIN_LED 2
//
//#define A0 = 36;
//#define A3 = 39;
//#define A4 = 32;
//#define A5 = 33;
//#define A6 = 34;
//#define A7 = 35;
//#define A10 = 4;
//#define A11 = 0;
//#define A12 = 2;
//#define A13 = 15;
//#define A14 = 13;
//#define A15 = 12;
//#define A16 = 14;
//#define A17 = 27;
//#define A18 = 25;
//#define A19 = 26;
//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
//"RESERVED" pins for ESP32 - best to avoid
//#define PIN_0_RESERVED 0 //reserved ESP32 boot/program upload
//#define PIN_1_RESERVED 1 //reserved ESP32 for TX0
//#define PIN_3_RESERVED 3 //reserved ESP32 for RX0
//#define PIN_6_RESERVED 6 //reserved ESP32 for flash
//#define PIN_7_RESERVED 7 //reserved ESP32 for flash
//#define PIN_8_RESERVED 8 //reserved ESP32 for flash
//#define PIN_9_RESERVED 9 //reserved ESP32 for flash
//#define PIN_10_RESERVED 10 //reserved ESP32 for flash
//#define PIN_11_RESERVED 11 //reserved ESP32 for flash
//Digital Pins
#define PIN_PRESENCE_1 13 //SmartThings Capabilty "Presence Sensor""
#define PIN_PRESENCE_OUT1 14 //Jumper output to PIN_PRESENCE_1 input
//******************************************************************************************
//ESP32 WiFi Information
//******************************************************************************************
String str_ssid = ""; // <---You must edit this line!
String str_password = ""; // <---You must edit this line!
IPAddress ip(10, 0, 1, 29); // Device IP Address // <---You must edit this line!
IPAddress gateway(10, 0, 1, 1); //router gateway // <---You must edit this line!
IPAddress subnet(255, 255, 255, 0); //LAN subnet mask // <---You must edit this line!
IPAddress dnsserver(8,8,8,8); //DNS server // <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on
// Hubitat Hub Information
IPAddress hubIp(10, 0, 1, 15); // hubitat hub ip // <---You must edit this line!
const unsigned int hubPort = 39501; // hubitat hub port
bool isPresent1 = false;
int ble1NotFoundCount = 0;
int numLoops = 0;
//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine. This is a sniffer to monitor
// data being sent to ST. This allows a user to act on data changes locally within the
// Arduino sktech.
//******************************************************************************************
//void callback(const String &msg)
//{
// Serial.print(F("ST_Anything Callback: Sniffed data = "));
// Serial.println(msg);
//TODO: Add local logic here to take action when a device's value/state is changed
//Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
//st::receiveSmartString("Put your command here!"); //use same strings that the Device Handler would send
//}
//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
//Set and initialize pins to read result of BLE scan
pinMode(PIN_PRESENCE_1,INPUT);
pinMode(PIN_PRESENCE_OUT1,OUTPUT);
digitalWrite(PIN_PRESENCE_OUT1,HIGH); //Initialize to notpresent
//******************************************************************************************
//Setup Bluetooth Low Energy scan
//Begin scanning for BLE devices
Serial.begin(115200);
BLEDevice::init("BLEScanner");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
//******************************************************************************************
//Declare each Device that is attached to the Arduino
// Notes: - For details on each device's constructor arguments below, please refer to the
// corresponding header (.h) and program (.cpp) files.
// - The name assigned to each device (1st argument below) must match the Groovy
// Device Handler names.
// - The new Composite Device Handler is comprised of a Parent DH and various Child
// DH's. The names used below MUST not be changed for the Automatic Creation of
// child devices to work properly. Simply increment the number by +1 for each duplicate
// device (e.g. presence1, presence2, presence3, etc...) You can rename the Child Devices
// in the ST Phone Application or change the Hubitat Device Label
//******************************************************************************************
//Interrupt Sensors
static st::IS_Presence sensor1(F("presence1"), PIN_PRESENCE_1, LOW, true, 1);
//*****************************************************************************
// Configure debug print output from each main class
//*****************************************************************************
st::Everything::debug=true;
st::Device::debug=true;
st::PollingSensor::debug=true;
st::InterruptSensor::debug=true;
//*****************************************************************************
//Initialize the "Everything" Class
//*****************************************************************************
//Create the SmartThings ESP32WiFi Communications Object
//STATIC IP Assignment - Recommended
st::Everything::SmartThing = new st::SmartThingsESP32WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);
//DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
//st::Everything::SmartThing = new st::SmartThingsESP32WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);
//Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
st::Everything::init();
//*****************************************************************************
//Add each sensor to the "Everything" Class
//*****************************************************************************
st::Everything::addSensor(&sensor1);
//*****************************************************************************
//Initialize each of the devices which were added to the Everything Class
//*****************************************************************************
st::Everything::initDevices();
}
//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop() {
BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
Serial.print("Devices found: ");
Serial.println(foundDevices.getCount());
int i;
bool ble1Found = false;
for (i=0; i < foundDevices.getCount(); i++) {
BLEAdvertisedDevice advertisedDevice = foundDevices.getDevice(i);
if (advertisedDevice.getAddress().toString() == TILE_MAC_ADDRESS_1) {
ble1Found= true;
Serial.printf("BLE1 Advertised Device: %s \n", advertisedDevice.toString().c_str());
ble1NotFoundCount = 0;
if(!isPresent1) {
isPresent1 = true;
Serial.printf("BLE1 found; isPresent1 is true.\n");
digitalWrite(PIN_PRESENCE_OUT1, LOW);
}
}
}
if(!ble1Found) {
ble1NotFoundCount++;
if(ble1NotFoundCount >= 5 ) {
isPresent1 = false;
Serial.printf("BLE1 not found; isPresent1 is false.\n");
digitalWrite(PIN_PRESENCE_OUT1, HIGH);
ble1NotFoundCount = 0;
}
}
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
//*****************************************************************************
//Execute the Everything run method which takes care of "Everything"
//*****************************************************************************
if (numLoops >= 5) {
st::Everything::run();
numLoops = 0;
} else {
numLoops++;
}
delay(2000);
}