Java.lang.number error in log

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.

1 Like

oddly adding this line to items causes the sitemap to just show is unknown to be again even when I disconnect wifi and reconnect it remains unchanged

Switch Person_2_Wifi_Event "Kat Wifi" (Person_2) { mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)] <[mosquitto:/presence/wifi/*-*-*-*-*-*:state:ON]", expire="4m,state=OFF" }

Errors in the log?

No which would suggest it not receiving updates from my mqtt but the other two items that show last seen are working fine.

You need a comma between the two parts of the MQTT config.

mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)],<[mosquitto:/presence/wifi/*-*-*-*-*-*:state:ON]"

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.
:roll_eyes:

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

Did you use the scripts from the link

Also did you change the permissions for the scripts using 'chmod’
The router needs to be able to execute the script.

Yes I use. :frowning:

My router is sending messages:
image

My itens code:

//Presence Detection
Group:Switch:OR(ON, OFF) Presence "Peolpe at home: [%d]" <presence>
  Group:Switch:OR(ON, OFF) Person_1 "Person 1 [%d]" <man> (Presence)
    Switch Person_1_Geofency "Person 1 Geofency [%s]" (Person_1)
    Switch Person_1_Wifi "Person 1 Wifi [%s]" (Person_1)
  Group:Switch:OR(ON, OFF) Person_2 "Person 2 [%d]" <woman> (Presence)
  	Switch Person_2_Wifi "Person 2 Wifi [%s]" (Person_2)

// DO NOT restore state from database for `Person_X_Wifi_LastSeen_State`
// If you want to restore the state use `Person_X_Wifi_LastSeen_Seconds`

Switch   Person_1_Wifi_LastSeen_State
DateTime Person_1_Wifi_LastSeen         "Person 1 Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" { mqtt="<[mosquitto:owrtwifi/status/mac-d0-17-c2-8f-af-21/lastseen/iso8601:state:default]" }
Number   Person_1_Wifi_LastSeen_Seconds "Person 1 Wifi last seen [%d]" { mqtt="<[mosquitto:owrtwifi/status/mac-d0-17-c2-8f-af-21/lastseen/epoch:state:default]" }

Switch   Person_2_Wifi_LastSeen_State
DateTime Person_2_Wifi_LastSeen         "Person 2 Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" { mqtt="<[mosquitto:owrtwifi/status/mac-00-00-00-00-00-00/lastseen/iso8601:state:default]" }
Number   Person_2_Wifi_LastSeen_Seconds "Person 2 Wifi last seen [%d]" { mqtt="<[mosquitto:owrtwifi/status/mac-00-00-00-00-00-00/lastseen/epoch:state:default]" }

Switch   Person_1_Wifi_Event            "Person 1 Wifi Event [%s]" { mqtt="<[mosquitto:owrtwifi/status/mac-d0-17-c2-8f-af-21/event:state:MAP(presence_event.map)]" }
Switch   Person_2_Wifi_Event            "Person 2 Wifi Event [%s]" { mqtt="<[mosquitto:owrtwifi/status/mac-00-00-00-00-00-00/event:state:MAP(presence_event.map)]" }

But my item do not change your state. See the log:
image

See too the state of my scripts:

presence_event.sh
#!/bin/sh

MQTT_SERVER="192.168.1.254"
MQTT_ID="OpenWRT-Presence-Event"
MQTT_TOPIC="owrtwifi/status/mac-"

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="owrtwifi/status/mac-"

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//:/-}/lastseen/iso8601" -m $(date +%Y-%m-%dT%H:%M:%S%z)
    mosquitto_pub -h $MQTT_SERVER -i $MQTT_ID -t "${MQTT_TOPIC}${mac//:/-}/lastseen/epoch" -m $(date +%s)
  done
done

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.

https://community.openhab.org/t/java-lang-number-error-in-log/32512/4?u=greymarvel

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

My items look like this

Group:Switch:OR(ON,OFF) Presence "Someone [MAP(present.map):%s] " <present>
Group:Switch:OR(ON,OFF) Person_1 "Tim [MAP(present.map):%s] " <man_3> (Presence)
Group:Switch:OR(ON,OFF) Person_2 "Kat [MAP(present.map):%s] " <woman_3> (Presence)


Switch Person_1_Wifi_Event "Tim Wifi" (Person_1) { mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)], <[mosquitto:/presence/wifi/*-*-*-*-*-*:state:ON]", expire="3m,state=OFF" }


Switch Person_2_Wifi_Event "Kat Wifi" (Person_2) { mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*/event:state:MAP(presence_event.map)], <[mosquitto:/presence/wifi/*-*-*-*-*-*:state:ON]", expire="3m,state=OFF" }


DateTime Person_1_Wifi_LastSeen "Tim Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <clock> { mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*:state:default]" }


DateTime Person_2_Wifi_LastSeen "Kat Wifi last seen [%1$td.%1$tm.%1$tY %1$tH:%1$tM]" <clock> { mqtt="<[mosquitto:/presence/wifi/*-*-*-*-*-*:state:default]" }

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

See the following for iPhone approaches:

iCloud integration:

ARPING option on lastest Network Binding:
http://docs.openhab.org/addons/bindings/network/readme.html

Scripts:

1 Like

Thanks Rich fortunately I’ve manage to convert my wife over to android now :wink:
But this will be useful for others reading this.

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