Use Android device proximity sensor as switch

I just started to join this community and already have some question for which I didn’t find any solution on the internet. I have several old and new Samsung Android cell phones, which I would like to put on wall in rooms and use them as switch.

Is it possible to use or configure device build in proximity sensor (sensor which turn off screen during call) to report state out of call? I can see that this sensor works while I have call, but I don’t see status change out of call.

Do you have some idea how to use proximity sensor as switch?

I would like to move hand in front of device and based on this call some action. Turning light for example

When you install the app on your device you can go into “App Configuration” and from there “Sensors”
The proximity sensor should be in the list, just enable it and it will show up in your HA entities

Depending on the device it wont switch to near until you actually almost touch the screen (ear detection)
Better would be to use:

And use the REST api to get the motion sensor state from the json data.
There are alot of guides around on how exactly everything works. Plus its free so you can check if everything works on your older phones

The proximity sensor is a poll based sensor so it may not work as you would expect. You can try enabling more sensors to get it to update more frequently

If that’s the case and you are willing to spend $4 on the Tasker app, the proximity sensor (not the entity in HA) could trigger the Android phone to send an http request that would give you instant update. There are probably other options to http request for an Action to achieve your goal.

I was only mentioning how the sensor worked, I use tasker but have no use case to have the proximity sensor constantly being monitored

I can see sensor in app but it doesnt change state. It change state only durring a call. I have been reading definitions in HA and also Android.

This Screenshot is taken durring call to fathers phone. I was moved hand in front of display.

I need to somehow simulate that phone is in call or activate proximity sensor to be used always. Even when screen is off.

I will try to do this direction and find some useful guide how to use REST in HA

I have activated all possible sensors but I never get update. Sensor state changing only durring a call. Maybe that is specific to Samsung devices or it’s hardcoded in Android it self.

Keep in mind that most proximity devices report either 5 or 0 and meaning you only have a small area to trigger the sensor. If you say it only happens when your on the phone then try waving your hand closer to the screen. Not all devices report the actual distance. It could be specific to samsung, hard to tell since they dont document it.

See the second note from the anchor link:

Hi, I have configured another device and I have it in HA dashboard. It is reporting state 5 or 0. Which is enough for me. Now problem is that refeshing that information takes long time. I guess that this 15 minutes rule is applied. On picture you can see that HA knew that It’s something close to phone sensor, there why it’s there 0 (close). Otherwise it’s 5 as far.

I have been searching on the interenet how to change that refresh rate for this sensor. Or how to use REST or JSON . But didn’t find anything useful.

Can someboty show me some how to or manual how ?