Status of things in sitemap?

(Halvhjearne) #1

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?

0 Likes

(Michael) #2

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.

0 Likes

(Halvhjearne) #3

without creating a rule

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

0 Likes

(Rolf Vermeer) #4

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

(Kim Andersen) #5

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)
0 Likes

(Halvhjearne) #6

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

0 Likes

(Halvhjearne) #7

without creating a rule

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

0 Likes

(Kim Andersen) #8

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

(Rossko57) #9

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

0 Likes

(Rolf Vermeer) #10

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.

0 Likes

(Rossko57) #11

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.

0 Likes

(Halvhjearne) #12

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.

0 Likes