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?
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.
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
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!..
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.
How to get a result like the following on the sitemap?
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
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
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"