Status of things in sitemap?

i have 2 MCP23017 chips connected to my raspberry with openhab and it usually works well, however, sometimes the chips will not go online after a reboot, so i thought maybe it was possible to just retrive the status in an item and show it on the sitemap.
is this possible, without creating a rule to retrive the status?

things example:

Thing 		mcp23017:mcp23017:chipA 		"MCP23017 chip A" 		[address=24,bus=1]

item example:

Switch switch_chipA_A0 	"Lys Switch Chip A A0" 		<light> (Terr_Lysalle, Terr_Lys1) {channel="mcp23017:mcp23017:chipA:output#A0"}

i would just like to have an item that looks like this:

String status_chipA 	"Chip A Status:  [%s]" {channel="mcp23017:mcp23017:chipA:status"}

and show in sitemap, if this is possible?

Hi,

yes it works.

Here an example with a Homematic thing:

Create a rule that triggers on “thing changes”

rule "Thing_GATEWAY_EXTRAS changed"
when
    Thing "homematic:GATEWAY-EXTRAS-OEQ0608684:OEQ0608684:GWE00000000" changed
then
    var Status            = getThingStatusInfo("homematic:GATEWAY-EXTRAS-OEQ0608684:OEQ0608684:GWE00000000").getStatus()
    if (Status.toString() == "ONLINE")
    {
        logInfo("homematic_thing.rules", "GATEWAY_EXTRAS Status:" + Status)
        Thing_GATEWAY_EXTRAS_Online.postUpdate(ON)
    }
    else
    {
        var StatusDetail      = getThingStatusInfo("homematic:GATEWAY-EXTRAS-OEQ0608684:OEQ0608684:GWE00000000").getStatusDetail()
        var StatusDescription = getThingStatusInfo("homematic:GATEWAY-EXTRAS-OEQ0608684:OEQ0608684:GWE00000000").getDescription()
        logError("homematic_thing.rules", "GATEWAY_EXTRAS Status:" + Status)
        logError("homematic_thing.rules", "GATEWAY_EXTRAS StatusDetail:" + StatusDetail)
        logError("homematic_thing.rules", "GATEWAY_EXTRAS StatusDescription:" + StatusDescription)
        Thing_GATEWAY_EXTRAS_Online.postUpdate(OFF)
    }
end

In this rule you can also set your Item to anything you like and display this then in your sitemap.

without creating a rule

there must be an easier way to retrive the status and show if the thing is online or not.

Not sure if you define this as easier, but you could define an item which uses the http binding, the REST API and a JSONPATH transform.
I’m not using this myself but you could make a request to
http://yourip:port/rest/things/thingUID/status and use the JSON path transform to get the value of the status returned.

1 Like

I use this rule:

rule "Zwave Node5 status"
when
  Thing "zwave:device:169d5902619:node5" changed 
then

      var thingStatusInfo = getThingStatusInfo("zwave:device:512:node5")

if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    logInfo("ThingStatus", "ZwaveNode5 is online.")
  ZWaveNode5_status.postUpdate(ON)
} else {
    logError("ThingStatus", "ZwaveNode5 is offline or doesn't exist.")
  ZWaveNode5_status.postUpdate(OFF)

}
end

And this is the status item used in sitemap:

Switch    ZWaveNode5_status    "Multisensor6 On/Offline [%s]"    <switch>	    (gOn_offline)
2 Likes

sounds like an idea, but tbh i feel there should be an easier way to retrive the status of any things to an item …
if my thing looks like this:

Thing 		mcp23017:mcp23017:chipA 		"MCP23017 chip A" 		[address=24,bus=1]

there should be an option to retrive status to an item, something like this:

String status_chipA 	"Chip A Status:  [%s]" {channel="mcp23017:mcp23017:chipA:status"}

… why is this (or similar) not already possible?
i cant be the only one that wants that

without creating a rule

i wonder if guys like you and @Schrott.Micha even reads before answering?

Well…
The thing is, if it could be done without a rule, I would suspect most would use it…
I read your post as, you thought using a rule was complexed…I just wanted to show how easy it could be… I guess I was wrong, sorry!..

Good luck hunting whatever needs you may have!

1 Like

That would be up to the binding author to provide a channel for whatever it is you are interested in.

As @rossko57 already mentions, that would have to be something that should be implemented at the binding level and that might be the case for some bindings that I am not aware of, but in general that is not the case.

You can raise an issue on Github for the specific bindings you are using, or better yet, create and suggest a PR that would implement such a feature yourself.

The Modbus binding provides a couple of “admin” channels alongside the regular data channels for target device data. e.g. “lastReadError” which is a datetime, and can be linked to an Item.

That’s not a simple online/offline status because -
(a) it’s the nature of Modbus that you cannot know the accessibility of a device until you do something to it. Other technologies may be different.
(b) a read error is not a catastrophic failure, transient errors might occur and transfers can be retried. Other technologies may act different.

But this does allow for a simple rule watching for an Item change to ring a bell or whatever you want.

i made a rule now that returns the status, but tbh i still feel there should be an easier way to do this.

thanks for the help anyway.

I wonder what PaperUI does to show the thing status in the things configuration list.

PaperUI%20Thing%20status
How to catch that status info and put it on a sitemap?
(It might well be that the methods described above are used by PaperUI as well…)

Any idea?

To put anything in a sitemap, you need to capture it into an Item.
The rules earlier show how to do that.

How to get a result like the following on the sitemap?
Power
with the switch icon changing to “red” for any thing status other than “online”?

How to get rid of the “dash”?

Even better would be to state the things status as text as visible in PaperUI… (no need for the switch icon in such case), e.g. Online or Offline in green/red color

For some reason the switch icon doesn’t change to “red” when the Fritzbox is diconnected.
Do I need to ping it somehow or what would be the refresh rate by default?

In which log file can I find the Info and Error messages?

I use the following rule:

rule "FRITZ!Box (Modem) Status"
when
  Thing "avmfritz:fritzbox:192_168_0_1" changed 
then
      var thingStatusInfo = getThingStatusInfo("avmfritz:fritzbox:192_168_0_1")
if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
    logInfo("ThingStatus", "ONLINE")
  fritzbox_modem_status.postUpdate(ON)
} else {
    logError("ThingStatus", "OFFLINE")
  fritzbox_modem_status.postUpdate(OFF)
}
end

item

String fritzbox_modem_status "FRITZ!Box" <switch>

sitemap

Text item=fritzbox_modem_status

Thx.

http://www.openhab.org/docs/configuration/sitemaps.html#label-and-value-colors

Text item=fritzbox_modem_status valuecolor=[=="Offline"="red", =="Online"="green"]
1 Like

How to transfer the strings “Online” or “Offline” to the item?
How does this work with postUpdate?

Thx.

Which Item?
This one?

This is an Item of type String.
To update the state of any Item, you can use the .postUpdate method.
In the case of a String Item, you should postUpdate a string value

fritzbox_modem_status.postUpdate("Online")

I’m still struggeling with the Thing Status showing in the sitemap… I was then trying another approach using a cron job to obtain thing status on a regular basis instead of a rule on thing status change. By that I should be able to set the time interval of the cron job for each thing separately. e.g. network device more frequently, Zwave less frequently. That’s the idea.

In some input in this thread:

In order to test the basic logic, I was just trying to get the the string “Online” to show in the sitemap and used the following rule…

rule "FRITZ!Box (Modem) Status"
  when
    Time cron "0 * * ? * * *"
  then
    fritzbox_modem_status.postUpdate("Online")
end

Item:

String fritzbox_modem_status

Sitemap:

Text item=fritzbox_modem_status label="FRITZ!Box (Modem)" icon="none"

No string appears in the sitemap.

What is wrong?

You have asked for the state not to be displayed. Try -

Text item=fritzbox_modem_status label="FRITZ!Box (Modem) [%s]" icon="none"