I am a HA newbee and i have started with something simple but i looks like its not that simple at all.
I bought a Aqara motion sensor and a Aqara light bulb and i put it in the Toilet (not literally of course ).
Most of the time it works but 1 out of 10 to 15 times the light does not turn on.
This is the code i use:
The automation.yaml code you post (hint: add code fences to add formatting) logic looks fine, apart from perhaps minutes: 1 being a very short period, and type: no_motion possibly not matching the actual sensor output (but you say the issue is intermittent - so unlikely to be that). The only other thing is mode: restart.
My suggestion is to use the HASS History log to understand what the motion sensor is really doing. Intermittent issues are more likely to be real-world physical sensor issues than code race conditions.
Have a read of a recent thread discussing issues with false-triggering of an IKEA Zigbee PIR motion sensor to see an example log history, and the fix:
As an example to compare, here is one of my Zigbee PIRs (N.B. this sensor reports on and off)
- id: '123456'
alias: Bedroom 20mins OFF
description: Bedroom 20mins OFF
trigger:
- platform: state
entity_id: binary_sensor.pir_ewelink_1234_ias_zone
to: 'off'
for:
minutes: 20
condition: []
action:
- service: light.turn_off
data: {}
target:
device_id: 1234123412341234
“hint: add code fences to add formatting” Thanks i will do that next time!
I set the 1 minute to 3 minutes. My idea was that when a person is on the toilet he or she won’t really move around but he or she will move a little (breathing should be ennough i thought) and that way the triggers will keep on comming, settting the ‘turn on’ time to 1 minute on and on til some leaves the toilet. But we found out that it does not work that way in real live)
The whole day it worked fine but just now it happend again. My son opened the toiletdoor and the light did not turn on, i wil look into the history and i wil make a screenshot of it.
As you will see the sensor just does not detect anything, it even takes about a minute before the motion sensor detects my son in this area after i manually ran the code.
I have several Aqara motion sensors, and yes, on some occasions mine don’t work either. However, it’s more like 1 in 50 times, so they only thing I’ve done is put 2 in the bathroom where it matters to my use case. Overkill, but I’m lazy.
Did you pair the sensor with it in place, or in another room? Aqara sensors are known to stick with the one router/co-ordinator, whereas you would want it to be paired with the light in the same room. If it’s instead paired with your main co-ordinator, it may be losing the connection occasionally. Re-pairing it in place would fix this.
And breathing won’t be enough to trigger a PIR sensor. For this you would need a much more expensive mm-wave sensor that is externally powered. Given the cost of electricity use, just leave the light on for 30 minutes. Or put in a door sensor and turn the light off after determining if the door was closed “before” or “after” (no motion → door open → motion = “before”).
PIR sensors work with a grid of sensitivity (Fresnel lens zones), so trigger best when a body moves across the grid.
Try mounting the sensor to the side, not straight on to increase cross-grid movement
Try mounting high on the opening side of a door, NOT pointed at 90deg.
If all else fails, add a magnetic door sensor
Magnet detects the door opening - light ON
PIR turns the light OFF after 5mins of no motion
My living room uses both door and PR sensors for exactly this reason.
In the future, microwave + PIR sensors may offer both fast detection AND occupancy (a combination used in the security industry for years using (PIR AND uW) rather than (PIR OR uW) trigger logic):