[SOLVED] Status update error

hello everyone! i’m here again with a problem that i cannot solve by myself…

in short, i’ve installed the network binding and then i’ve created all files below.
my goal is to have on the same line the status (Online or Offline) and next the response time.
i’ve obtained to have the status and response time on the same line when the pinged hostname is online, but i cannot se on to “Offline” when the hostname is down.
i only have this status when offline: “Offline UNDEF ms”
when online i have the right value: “Online 3 ms”

here are my files.

network.items

Switch nas "NAS [MAP(network.map):%s]" { channel="network:pingdevice:nas:online" }
Number nastime { channel="network:pingdevice:nas:latency" }
String nasstatus "Stato [MAP(network.map):%s]"

network.map (to translate from ON or OFF to Online and Offline)

ON=Online
OFF=Offline

network.rules

//////////NAS STATUS CHANGE//////////

rule "Offline NAS"
when
    Item nastime changed to UNDEF
then
    var nas = transform("MAP","network.map", nas.state.toString)
    nasstatus.postUpdate("Offline")
end


rule "Online NAS"
when
    Item nastime received update
then
    var nas = transform("MAP","network.map", nas.state.toString)
    nasstatus.postUpdate(nas + " " + nastime.state.toString + " ms")
end

network.sitemap

sitemap network label="Network Binding"
{
	Frame {
//            Text item=lcd
              Text item=lcdstatus label="LCD BTicino [%s]"
//            Text item=lcdtime label="Tempo di risposta [%s]"
  }
}

network.things

Thing network:pingdevice:nas [ hostname="192.168.1.10" ]

i’ve tried to set UNDEF in map file, but doesn’t work.
i’m really lost :frowning:

thanks at all!

How about replacing both rules with this…

rule "NAS status"
when
    Item nastime received update
    or
    Item nas changed
then
    if (nas.state == ON) {
        nasstatus.postUpdate("Online " + nastime.state.toString + " ms")
    else {
        nasstatus.postUpdate("Offline")
    }
end

One thing to note from your rules is that you are trying to use a variable name that is the same as an item name. I would expect you would have errors from this.

there should be another error…because now i haven’t any status. i only have “-” :frowning:

Does nastime have a value? This might help…

rule "NAS status"
when
    Item nastime received update
    or
    Item nas changed
then
    if (nas.state == ON) {
        if (nastime.state == NULL) {
            nasstatus.postUpdate("Online")    
        else {
            nasstatus.postUpdate("Online " + nastime.state.toString + " ms")
        }
    else {
        nasstatus.postUpdate("Offline")
    }
end

Do you see any errors in the logs?

tried to add in sitemap the “nas” and “nastime” items and both have values.

also with the last rule you sent, it’s not working. i still get no values when both items are merged into one…

Change the nasstatus item:

String nasstatus "NAS Status [%s]"

You don’t need the transform in there, only the String display.
OH is trying to transform your string and can’t find a match and therefore displays -

removed the MAP from items…same problem. displayed “-”

Did you check the logs?
And did you remove your two original rules?

yes
yes
no errors in log openhab.log and in events.log, at least not related to network binding.
in events.log i can see tha nastime value changing.
tried to search for nasstatus and i found only “Item ‘nasstatus’ has been updated.”

GOT IT! thank you!
in your sybtax were missing 2 } :wink:

Please mark the thread as solved:

rule "NAS status"
when
    Item nastime received update
    or
    Item nas changed
then
    if (nas.state == ON) {
        if (nastime.state == NULL) {
            nasstatus.postUpdate("Online")    
        } else {
            nasstatus.postUpdate("Online " + nastime.state.toString + " ms")
        }
    } else {
        nasstatus.postUpdate("Offline")
    }
end