Monitor z-wave stick availability (SOLVED)


OH is running in a Windows VM, with a z-wave stick passed through via some USB over TCP software. If the VM is saved and then resumed again (e.g. the host is restarted), OH needs its service restarting to pick it up again.

Just wondering what the best way would be to monitor the state of the z-wave stick? Ideally I would like to be able to run a PowerShell script to get the state, which I would then pass into PRTG to generate an alert if its gone.


Relevant to my interests. Recently my Ubuntu instance (via docker) has started having USB issues, and the controller has been disconnecting/reconnecting and changing serial port.

So I’ve been thinking about monitoring it. I monitor a chromecast as a thing, and can tell if it’s online offline (I use it for figuring out my tv is turned on). So I think I’ll look at that first, from that you can run a rule when the device is listed as offline. I’ll post the code for that if it might help you.

The powershell part I can’t help with, to do something about it, but at least we can work on the detection bit.

So here’s my chromecast thing detestion rule:

rule "Stereo Chromecast online"
    Thing 'chromecast:audio:7cf71a960cc620ff79365b5f8b581956' changed from OFFLINE to ONLINE
    logInfo("Chromecast", "Chromecast is online, that means the Stereo is on")
    Notify_Info.postUpdate(String::format("Chromecast is online, that means the Stereo is on"))

So using this, we should be able to do the same with the zwave controller thing.

rule "Zwave offline"
    Thing 'zwave:serial_zstick:a5365e91' changed from ONLINE to OFFLINE
    logError("ZWave", "Zwave is offline")
    Notify_Error.postUpdate(String::format("Z-Wave is offline!!"))

rule "Zwave online"
    Thing 'zwave:serial_zstick:a5365e91' changed from OFFLINE to ONLINE
    logError("ZWave", "Zwave is online")
    Notify_Error.postUpdate(String::format("Z-Wave is online!!"))

I haven’t test it (taking it offline yet), but it didn’t through any errors.

Ok so looked into creating a rule to store the device state (PowerShell could query the database to get this), but then realised OH has its REST API. Long story short, getting the status is a doddle:

((Invoke-RestMethod -Method Get -Uri “http://[OH URL]/rest/things/[Z-wave stick UID]” -Headers @{“Accept”=“application/json”}).statusInfo).status

Thanks for the help!

Interesting, where do you get [Z-wave stick UID] from? is that the serial_zstick:a5365e91?

Yes. Navigating to http://[OH URL]/rest/things/ will give you an output of everything - I just found my z-wave stick UID and then dropped in on the end. I read about it here:

It says if you install the REST Documentation misc addon under Paper UI, when you go to your root OH web page, one of the options alongside Paper UI/Basic/Habmin/etc is the REST doco.

Yeah I just found mine by looking in org.eclipse.smarthome.core.thing.Thing.json in userdata/jsondb

For reference, if anyone else wants something like this in PRTG, you dont even need a custom script - the HTTP XML/REST Value sensor works with JSON. My config is:

URL: http://[OH URL]/rest/things/[Z-wave stick UID]
XML Node: statusInfo/status
HTTP Username: [blank]
HTTP Password: [blank]
Sensor Value: User the value of the selected XML node
Namespaces: Remove namepsaces
Content Type in Header: Disabled
HTTP Headers: Accept: application/json
If Channel Value Changes: Trigger ‘change’ notification