Help requested - Presence detection with vibration sensor

I have a spare Xiaomi vibration sensor which I’ve put into the back cushion of my couch. I’d like to somehow set it up that the “tilt” or “vibration” action translates into the system knowing I am sitting in the couch, so that when it is dark (using sun elevation), the lamp in the living room automatically turns on.

This is working OK so far, I just check for both states as a trigger and sun state as condition. The hard part is how to know when to turn off the lamp.

The sensor obviously does not continuously report vibrations or tilts as I’m not constantly moving in the couch. This means using the fact the sensor reports nothing is not possible as the lamp might turn off when I’m sitting (remarkably) still.

Currently I just turn it off after 5 min, which is far from optimal.

I was thinking of the number of reported vibrations/tilts to use as a counter and the condition to turn off the lamp would be the counter going to zero.


Let’s say the first vibration gives counter = 5, every 5 minutes the counter decreases by 1, if another tilt or vibration happens, that means counter +1.

Is there a better way for this? Perhaps the gaussian binary sensor? Any ideas how to set that up with this usecase if that would be possible?

How about this:

Create an automation that turns off the light if the vibration sensor is in an off state for at least 15 minutes. Put in a condition to check if the light is currently on in order to prevent the automation from needlessly sending a turn-off command.

If you know you can sit perfectly still for more than 15 minutes, adjust the time accordingly.

- alias: 'couch monitor'
    platform: state
    entity_id: sensor.couch
    to: 'off'
    for: '00:15:00'
    condition: state
    entity_id: light.whatever
    state: 'on'
    service: homeassistant.turn_off
    entity_id: light.whatever
1 Like

What is the state if the sensor state is blank, i.e. “”, do I do

to: ''

Or do I have to make a new template sensor


This vibration sensor is a zigbee device and is automatically discovered, right? In other words, you don’t have an entry for it in the configuration file, correct?

What are all of this sensor’s possible states?

The Xiaomi vibration sensor is indeed discovered (through zigbee2mqtt). The states are

  • “” (this is the state when nothing happens)
  • “tilt”
  • “drop”
  • “vibrate”

OK, then an empty string would be valid:

to: ''

FWIW, I tested it and confirmed the automation gets triggered when the state value becomes an empty string.