The best I’ve ever seen is probably around 90%. Presence detection is one of those really really hard problems with more edge cases than you can imagine. The more sensors and the more diverse your sensors the better detection will be, but the more weird edge cases that you have to deal with.
I have fairly good wifi coverage so about 80% of the time a phone will connect to the wifi before we open the garage door. However, 20% of the time this doesn’t happen and I get “The garage door has opened and no one is home!” alerts. The BT detection, based on its nature, takes a few minutes before it will recognize a device is near by. You can make it work faster but that results in it flapping much more frequently which makes you have to deal with false absent events.
About the only full proof presence detection will involve not just sensing presence of devices but also heat sensors and/or cameras in every room.
I would have expected to see an error in the logs from the MQTT binding about that.
While you are at it, make double sure that the new part added to the event Item exactly matches the LastSeen Item except instead of using state:default use state:ON. This should cause the Person_x_Wifi_Event Item to receive an ON update every time any message is received on the LastSeen topic, regardless of the message’s contents.
Thanks Rich I copied and pasted the text from my other item and as you say change default to ON. I didn’t even notice I’d missed out the comma silly mistake !, well that’s the problem with C&P I suppose.
Tim, do you can post yours folows files: itens, presence_event.sh and presence_lastseen.sh?
My itens don’t be updated when router send mqtt messages…
Thanks
Ok so your router scripts are fine and you are receiving messages on your openHabian mqtt broker.
I didn’t use the items written in the link. as they require rules to update the items and as Rich and I discussed above, the rules in the example were using Setstate instead of Sendcommand which isnt good.
Thanks to Rich I changed my items and now they use a timer Binding instead of Rules to change my items status to off and Rules to only show a log and to send messages to my OpenHab mobile app when someone leaves or Arrives
I Have both the event script and lastseen script updating the item with a timer this updates my item every minute and after 3 minutes if the router doesn’t see my phone it shows as not present.
This works pretty well but not for Iphones
I have 2 Map transforms for my items
present.map
ON=is present
OFF=is not present
-=is unknown to be
and presence_event.map
new=ON
del=OFF
If you want to use the items format from the example I would recommend contacting the author through the Github link
Thanks guys, it’s working, follow my files, to other noobs like me:
Itens:
Switch Person_1_Wifi_Event "Gustavo Wifi" (Person_1)
{ mqtt="<[broker:presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)],
<[broker:presence/wifi/*-*-*-*-*-*/event:state:ON]",
expire="4m,state=OFF" } // turns OFF 4 minutes after last time it is set ON
Switch Person_2_Wifi_Event "Juliana Wifi" (Person_2)
{ mqtt="<[broker:presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)],
<[broker:presence/wifi/*-*-*-*-*-*/event:state:ON]",
expire="4m,state=OFF" } // turns OFF 4 minutes after last time it is set ON
DateTime Person_1_Wifi_LastSeen "Gustavo Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <clock> { mqtt="<[broker:presence/wifi/*-*-*-*-*-*:state:default]" }
DateTime Person_2_Wifi_LastSeen "Juliana Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <clock> { mqtt="<[broker:presence/wifi/*-*-*-*-*-*:state:default]" }
SItemap
Frame label="Presence" {
Text item=Presence
Switch item=Person_1
Text item=Person_1_Wifi_LastSeen
Switch item=Person_2
Text item=Person_2_Wifi_LastSeen
}
presence_event.sh
#!/bin/sh
MQTT_SERVER="192.168.1.254"
MQTT_ID="OpenWRT-Presence-LastSeen"
MQTT_TOPIC="presence/wifi/"
iw event | \
while read LINE; do
if echo $LINE | grep -q -E "(new|del) station"; then
EVENT=`echo $LINE | awk '/(new|del) station/ {print $2}'`
MAC=`echo $LINE | awk '/(new|del) station/ {print $4}'`
#echo "Mac: $MAC did $EVENT"
mosquitto_pub -h $MQTT_SERVER -i $MQTT_ID -t "$MQTT_TOPIC${MAC//:/-}/event" -m $EVENT
fi
done
presence_lastseen.sh
#!/bin/sh
MQTT_SERVER="192.168.1.254"
MQTT_ID="OpenWRT-Presence-LastSeen"
MQTT_TOPIC="presence/wifi/"
for interface in `iw dev | grep Interface | cut -f 2 -s -d" "`
do
# for each interface, get mac addresses of connected stations/clients
maclist=`iw dev $interface station dump | grep Station | cut -f 2 -s -d" "`
# for each mac address in that list...
for mac in $maclist
do
mosquitto_pub -h $MQTT_SERVER -i $MQTT_ID -t "$MQTT_TOPIC${mac//:/-}" -m $(date +%Y-%m-%dT%H:%M:%S%z)
done
done