[Android Apps and Games] c00ller:
I spent a long time thinking of and testing a set of "Smart Vibrate" rules, and thought I'd like to share them here. The motivation is to vibrate when an SMS is received or on an incoming phone call ONLY when the phone is in my pocket, and NOT when it is lying on my desk. This action should also be ignored when the phone is already in Vibrate mode or in Silent mode. There is one more constraint that will be mentioned below. I experimented different triggers such as Sensor.Accelerometer=="Face up", Sensor.Proximity=="Far", Screen==off, etc. and below are my final rules that seem to work most efficiently.

[Vibrate on incoming call] // Self explanatory

[Call State Trigger]: All incoming phone calls

[Vibrate Action]: Vibrates for 0.8 seconds
​

[Vibrate on incoming SMS] // Self explanatory

[Any SMS Trigger]: Triggers on any SMS received

[Vibrate Action]: Vibrates for 0.3 seconds​

[Enable vibrate rules] // Enable vibrate rules only when ring mode is Normal and phone is in pocket

[[Composite AND Trigger]]: [Sound mode is set to Normal (No vibrate)

AND Sensor [CM3602 PROXIMITY SENSOR] is in [NEAR] state with upto 5% deviation from this state for 1.0 second(s)

AND Device' screen is turned off]

[[Composite Action]]: Enable rule [Vibrate on incoming call];

Enable rule [Vibrate on incoming SMS]​

[Disable vibrate rules] // Disable vibrates rules when ring mode is Vibrate or Silent or when phone is not in the pocket

[[Composite OR Trigger]]: [Sound mode is set to Vibrate

OR Sound mode is set to Silent (No vibrate)

OR Sensor [CM3602 PROXIMITY SENSOR] is in [FAR] state with upto 5% deviation from this state for 1.0 second(s)]

[[Composite Action]]: Disable rule [Vibrate on incoming call];

Disable rule [Vibrate on incoming SMS]​

Now ideally this would be all that we need. Ideally the conditions for [Enable vibrate rules] will only be true when the phone is placed in our pocket. However, the conditions will also be met when Sound mode is set to Normal and you put the phone up to your face during a phone call! So, two more rules are necessary to disable [Enable vibrate rules] when those conditions are met and re-enable when a phone call is finished.

[Phone disables [Enable vibrate rules]] // Self-explanatory

[[Composite OR Trigger]]: [All incoming phone calls

OR Application Activated (Dialer One) // Dialer One is a third-party dialer app I like

OR Application Activated (Contacts)] // Contacts.apk is the AOSP app contains the contacts, dialer, and in-call apps

[Enable/Disable Rule Action]: Disable rule [Enable vibrate rules]​

[End call re-enables [Enable vibrate rules]] // Self-explanatory

[Call State Trigger]: All ending phone calls

[Enable/Disable Rule Action]: Enable rule [Enable vibrate rules]​

And that's all there is to it! If there are any other extraneous cases I haven't thought of, please let me know.

Some thoughts I had during this process:

-At first I was fiddling with the various sensor triggers and many times couldn't help but think, "How convenient and powerful it would be to have a NOT argument!"

For example, NOT(Sensor.Accelerometer=="Face up"))

-For the [Vibrate Action] interface, users should be notified that only increments of 0.1 seconds are supported and otherwise are rounded up to the next tenth of a second. From what I've seen in other apps, the Android system allows vibrate durations in increments of milliseconds, so why can't we do the same here?