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