Java.lang.number error in log


(Timothy Harrison) #14

so the Goood news is you were right even though i changed the script in the router to not include the {} brackets it needed a reboot to implement the change this in turn showed the sitemap as such


when i changed the item file so that present was included in the ] like so

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

and the sitemap to Text it does nothing


(Timothy Harrison) #15

If I add present to the Transform I get the required effect


(Timothy Harrison) #16

one problem Ive noticed is that my router scripts only update last seen every minute. The event script is only sent should my wifi connect or disconnect. However the 4 min expire is turning the presence off as no event happens and my phone is still here so no script is sent.

Any thoughts?


(Rich Koshak) #17

Ok, this is different behavior than expected which might require a rule.

It might not.

First of all, is it possible to update the php script to report the event every minute instead of just when the phone goes online or offline?

Is last seen published even when the phone is no longer connected? If it stops when the phone is disconnected we can use those messages to drive the switches instead of the events.

Do you always get a disconnect event when the phone goes away? If so we can use the events and do away with the timers, or change slightly how we use the timer.


(Timothy Harrison) #18

Ok so the last seen scipt is run by a cronjob that starts every minute, The event script is placed in the RC Local file with a nohup command so as far as I understand, it runs continuously and sends the mqtt message when a phone disconnects or connects.

The phones becomes an ‘associated station’ on the router which in theory means that as long as the phone doesnt disconnect from wifi it should show as present no matter how long you leave the phone (sleep mode) however I have noticed that the wife’s iphone does disconnect when sleeping but so far my android has not( I will be changing her phone for an android soon so hopefully this wont be a problem).

The last seen script only sends the date,time and MAC addresses for any associated stations hence why i have to specify the MAC addresses i want receive updates for in my items. (namely my wife’s and my phone )
so if the phone disconnects it wont send the message for that MAC address.

The only problem with using this as the trigger is that it sometimes takes several minutes before the device become disassociated but this is still an option however once again it will be a problem with the iphone.

So far with my phone at least I have had accurate disconnect events and as far as ive seen so far i do not disconnect or become disassociated when my phone is idle.

As I only have the date and time and a power socket working on my openhab I havent left my openhab running as I wanted a presence detection working before I left it running continuously. So I havent got any logs to show whether my phone has 100% no disconnects or disasociations using the mqtt messages . The logs on my router are minimal and only really show when a handshake is performed between devices and that the last seen script is run. Its only by viewing the routers admin page that I see my wifes phone disconnect when idle or that my phone appears to never disconnect.

Maybe I should leave openhab running and at least this will show me if my theory is correct.


(Rich Koshak) #19

Good luck with that. I tried to do that once… :wink:

Good. We can use that. Add the following to your Person_x Items:

<[mosquitto:/presence/wifi/*-*-*-*-*-*:state:ON]

So every time the router sends a LastSeen message it will update the Switch Item to ON. since that happens every minute it will keep the expire binding from changing the Switch to OFF. 4 minutes after the last LastSeen message (if for some reason the disconnected event didn’t get sent) the Switch will go OFF.

This will be a problem no matter what I suspect.

Detecting iPhones on the network is a well known and difficult problem. When it goes to sleep it puts the device into a hibernation mode that makes it mostly unresponsive to network events. However, if you search the forum for “hping” you will see one way a lot of people have got around this problem with iPhones. The Network binding just added and arping feature that essentially does the same as the hping solution.

Personally, I use a combination of presence sensors in my system. I configured my and my wife’s phones with static IPs on the router. Then I use the Network binding to periodically ping them to see if they are present.

But the iPhone disconnects so I also use Bluetooth detection on a number of Raspberry Pis that I already have scattered throughout the house for other purposes using a script I wrote. Finally, I’ve added reelyActive to my Raspberry Pi 3 which also does BT device presence detection but in a smarter way. I’ve since replaced one of my old Pi 1s with a Pi Zero W so plan on adding reelyActive to that one as well and see if I can start to get some better resolution (e.g. tell which floor the device is on). That is a relatively low-level priority though.

BT works well for me because both my wife and I have a smart watch and my wife has a medical device always attached which also uses BT so it works well.

Anyway, I require at least two sensors to report a device as present to mark a person as present (BT can have false positives).


(Timothy Harrison) #20

Good luck with that. I tried to do that once… :wink:
Tell me about it :laughing:

I’ll have to do a bit of research on here about this arping solution with the network binding sounds like this will help with the accuracy of my presence detection.

I’ve also thought about Bluetooth as an option especially using reelyactive and I like the idea of using multiple sensors to attack the presence accuracy from different directions. I assume you have mentioned this in another thread. I’ll have to have a look into the things you’ve mentioned and try and implement it into my system.

Out of interest how close to 100% accurate is your setup, do you still get the occasional false presence or false away event ?

Thanks for all your help in getting theses problems with my presence setup sorted I’ll shall add that addition to my items and hopefully incorporate your other ideas.


(Rich Koshak) #21

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.


(Timothy Harrison) #22

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" }

(Rich Koshak) #23

Errors in the log?


(Timothy Harrison) #24

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


(Rich Koshak) #25

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.


(Timothy Harrison) #26

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:


(Gustavo Z. B.) #30

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


(Timothy Harrison) #31

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.


(Gustavo Z. B.) #32

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

(Timothy Harrison) #33

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


(Rich Koshak) #34

See the following for iPhone approaches:

iCloud integration:

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

Scripts:


(Timothy Harrison) #35

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


(Gustavo Z. B.) #36

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