Asus router presence detection - How to parse a ; delineated string

I’m on OH4.3.3 with the current openhabian version, rpi 4, java 17. I had previously used apple homekit linked to a couple of virtual items in OH to manage presence detection at home. However with recent homekit changes to user sharing I’m finding that old solution no longer works. In looking at the AsusWRT binding and I can pull a semi colon delineated string of all hosts active on my lan, and all mac addresses.

Can anyone provide me a push in the right direction in terms of parsing those strings. What I’m thinking is to use a rule to parse the string looking for a particular mac or host and return a true/false or on-off to a virtual item that I’ll use to track presence for the device. I then use that item status to trigger other actions.

Thoughts? I’m really pretty weak with scripting so if anyone has a sample parsing script I could pilfer/work from it would be a huge help.

Cheers

Unfortunately Blockly doesn’t have access to “split” nor “includes” so it’ going to be a whole lot of extra work to use that.

In JS it’s actually pretty easy and straight forward though. You don’t even need to parse the String. You just need to test to see if your full string includes what you are looking for.

var fullString = // how ever you get this ; delimited String
var myMac = "11:22:33:44:55"
if(fullString.includes(myMac)) {
    console.info(myMac + " is present!")
}

Got it working like a charm, thanks much. Phones tend to drop off the lan intermittently so this isn’t a perfect presence detection, but it will have to do. But using the asus router binding does let me check for macs on both my primary and my guest network which is slick.

Cheers

FYI - If you’re looking for a reliable and fast Home/Away presence detection for your iPhones - I assume, as you mentioned HomeKit in your original post - you might want to look into the Theengs Gateway Apple iPhone, iPad, Apple Watch AirPods presence implementation.

With openHAB 4.3.3 the BLE Home/Away device tracker should also be auto-discovered.

Thx for the suggestion, I may look into it if my current method has issues.

The asuswrt binding supports a “client” thing which you can create for a given MAC address. This would eliminate the need to parse the connected clients string. I use this and set my phone to have a static MAC address when connected at home. It works well. The only issue I have is that occasionally the asuswrt thing goes offline and doesn’t recover until i disable/re-enable.

Interesting, I wasn’t aware of that, thx. Might be able to simplify my setup.