From options I tried for presence sensor like NMAP/Ping/Bluetooth/IOS component/Owntracks I find that Xiaomi MiHome’s app presence detection works better and more accurate.
The idea using it with HA is making automation that flashes Gateway light, HA see the changes in “rgb_color” values, and automation should define that it is a signal from MiHome app, but I’m stuck at the automation part
This is what I made:
in MiHome app made automation that flashes light 3 times:
turn gateway light off
delay 3s
turn gateway light on
delay 3s
turn gateway light off
delay 3s
turn gateway light on
delay 3s
turn gateway light off
delay 3s
turn gateway light on
delay 3s
turn gateway light off
in HA made variables, automation and scripts that store light changes:
If done the same in the past by just switching on a light to a brightness of 1 when leaving and 2 when coming home. If HA detects a brightness of 1 we’re not at home and HA switches of the light. No need to flash or anything like that. Works pretty well.
Thanks tried your code just needed to change “trigger.to_state.state” to “states.light.gateway.state” and the code is working
But I find this method is not reliable, sometimes HA not registering states and “toggle_count” gets only to 2 or 4 and not triggering “flash_completed”, even when I added another “on/off” cycle to lamp still some times it misses, maybe extending time period of states will help but its already taking about 20 seconds I want to look for better trigger
Xiaomi Gateway brightness can’t be set with MiHome automations but I tried your method with my Yeelight lamp, it is working but to make this trigger reliable it should stay at least 30 seconds in same brightness cause otherwise it’s triggered by just playing with the lights
So my conclusion about light as a trigger is that it is slow and not 100% reliable, need to think about better trigger, something that can be automated in MiHome app, be instant rather than sequence and have some definitive value by which we can say it’s 100% intended trigger and not something that can be set by mistake
Now I’m working on different approach with Xiaomi IR Remote, attached IR LED to RPi, installed LIRC now figuring how to make it listen to Xiaomi IR Remote and control boolean in HA
I used two levels of (very low) brigthness to detect home/away, after that the automation sets the brightness back to 100% (for example) and switches off the light. This way there is no confusion with normal switching on/off the lights and there is no need to keep the light on for a specific time. It workes very(!) reliable but you have to make sure you trigger on specific brightness not just on/off.
When Yeelight state/brightness/color changed not from HA, it takes time to update maybe 10-15 second or more, so for the safe side automation should keep low brightness for 15-20 seconds, it is too long and felt inconsistent, sometimes it takes 5 seconds sometimes 15 seconds
Eventually I made it with Xiaomi IR Remote, it’s instant and precise
Installed LIRC on my RPi, attached IR led, added random remote in MiHome app, learned 2 commands with LIRC, made 2 “.sh” scripts with “curl -X POST” to turn on and off input_boolean in HA