Network Binding LastSeen DateTime in rules

I am having an issue getting a comparison with Network Binding lastseen and now to work.

OH 2.2
MacOS 10.13.3

I have defined a pingable device as a Thing in PaperUI (I don’t have .thing files). This shows up just fine and the Last Seen is a DateTime, however not in UTC format (with Z in it).

My items file contains the following

DateTime Phone_LastSeen         "Phone Last Seeen[%s]" <time>   {channel="network:pingdevice:db6cfc77:lastseen"}

I also tried

DateTime Phone_LastSeen         "Phone Last Seeen [%1$tY-%1$tm-%1$tdT%1$tH:%1$tM:%1$tS]" <time>   {channel="network:pingdevice:db6cfc77:lastseen"}

My rule file contains one rule with the following

rule "Phone Presence"
when
    Time cron "0 * * * * ?"
then
logInfo("--DEBUG--","Runnig1")
    var DateTimeType LastMotionPhone = Phone_LastSeen.state
logInfo("--DEBUG--","Runnig2")
logInfo("--DEBUG--","LM: " + LastMotionPhone)

But LastMotionPhone is NULL. I cannot get a date out of it. Any clues as to what I am doing wrong?

rule "Phone Presence"
when
    Time cron "0 * * * * ?"
then
logInfo("--DEBUG--","Runnig1")
    //var DateTimeType LastMotionPhone = Phone_LastSeen.state
logInfo("--DEBUG--","Runnig2")
logInfo("--DEBUG--","LM: " + Phone_LastSeen.state.toString)

But in the end I want to get the time difference between now and the LastSeen time. I did this earlier with Motion sensors like this:

var Number AwayTime = Seconds::secondsBetween(new DateTime(Phone_LastSeen.calendar.timeInMillis),now).getSeconds

But it’s not working…

Still gives NULL

FYI @vzorglub the details
2018-04-18_13h04_39

Try the following,
Remove the binding from your item definition

DateTime Phone_LastSeen         "Phone Last Seeen[%s]" <time>

And link the item to the channel through the PaperUI only

And how does the item know which channel to use ?? Phone_LastSeen is just a madeup name (like any other item name is )… confused

As expected as it does not know where to get the information from it’s still NULL

2018-04-18 13:24:00.252 [INFO ] [pse.smarthome.model.script.--DEBUG--] - Runnig1
2018-04-18 13:24:00.253 [INFO ] [pse.smarthome.model.script.--DEBUG--] - Runnig2
2018-04-18 13:24:00.253 [INFO ] [pse.smarthome.model.script.--DEBUG--] - LM: NULL

And how does the item know which channel to use ?? Phone_LastSeen is just a madeup name (like any other item name is )… confused

On the things configuration screen in the paperUI you can link a channel to an existing item
As you have defined an item Phone_LastSeen (Now without binding declaration), you can link it to the channel in the PaperUI

I am running in simple mode (no items visible)… so linking is done for me in the background. I can just reference channels.

I am going to add the channel back in because that’s how OH works in item files and simple mode. If you can help me any further please let me know.

This may seem silly but try adding spaces in your binding {}

{ channel="network:pingdevice:db6cfc77:lastseen" }

The binding parser is very particular with syntax

1 Like

My item file already contain 15 channels which work… and this item would need spaces? Really?

I don’t know… Trying some things…

Weird enough that worked… Pretty picky this binding…