Custom shellscript for when wifi device connects or disconnects?

Hello everybody!

Im currently using another OS than OpenWRT on my router but since i didnt get any help over there, i figured i could ask you folks to see if the OpenWRT is more suitable for my goals.
My hardware (Asus RT-N13U B1) is supported (ralink) and it houses a USB-host port so i can mount a thumb drive in case the builtin storage isnt enough for this.

I would like to have some automatic means of discovering newly connected & disconnected wifi-clients and if said client is on "the VIP-list", a http request is sent to a local server (my Pi) that will execute the commands in question.

In short, i want my philips hue lights to turn ON when my phone connects to my wifi and turn off when my phone (as the last connected device on the "VIP-list") disconnects, turns off the lights.
(that last connected device means that if another device (tablet) is still online, it should NOT turn off the lights, since someone else is at home)

My "VIP-list" is currently only 3 devices, my phone and my kids tablet as well as the wife´s phone and they all are within a specific IP range ( - x.x.x.39) in case this is important, and they have a static ip assigned in my current router config.

My other hardware involved in this endevour is a Raspberry Pi, running raspbian and OpenHAB home automation system, as well as some other services (MQTT and so on), a philips hue bridge and a logitech harmony hub (to control TV & amplifier).

The idea is to rig the Raspberry to accept commands as URL´s, like { http://raspberryServer/functions/everythingOFF.htm } (or ../functions/welcomeHomeLightsON.htm )
and have the router to wget the specified URL when the corresponding trigger is detected ( when my phone connects to wifi, request the WelcomeHomeLightsOn.htm ).

I already have this feature working with a 3rd party service ( but i would much rather have this function in-house, working even if my uplink is down, and not have to constantly share my location with a 3rd party.

So is this even possible?
Does anyone have any hints or suggestions?

I realize that im probably able to get a list of the currently connected wifi clients from my raspberry, connecting to the router via SSH and use the proper commands, but i would much rather have this feature localized on the router, so i can keep it more secure without any m2m backdoors open.

will probably give you the output you need, then you'd have to build a script around it.

1 Like

HomeAssistan has a plug-in to detect presence using wifi clients, you just need to install one component on a OpenWrt router, and another.on the HomeAssistan server. Perhaps OoenHUB has something similar, and you do not need to build it yourself.