Page 1 of 1

Rest and OpenHab

Posted: Wed Dec 28, 2016 6:41 pm
by tobbe
Hi

I was wondering if it is possible to have ONH (opennethome) push status changes (eg. lamp1 turn ON) to OpenHab via REST?
I know you can read the status via REST, but it would be terribly inefficient to constantly check the status of all items or run a cron job every minute (would shwo updates with an unacceptable delay).
Yes, I know I could just use OpenHab directly, but unfortunately the support for Tellstick remotes or motion sensors is more or less nonexistent...
This would allow me to keep the most excellent Tellstick support of ONH and utilise OpenHabs support for my audioamp.
Of course I could run both ONH and OpenHab, but I would prefer not to have to switch applications, depending on what I'm trying to do.


Regards,
Tobbe

Re: Rest and OpenHab

Posted: Thu Dec 29, 2016 8:08 am
by stefangsbb
There is no "out of the box" solution to generate REST-calls for actions in the system. The question is what you want to do really. If you want specific buttons in ONH to cause REST-Calls to another system, then you can for example use the ActionButton with a custom action of type "exec", which runs a shell command. That shell command could send a REST-call either via a script or directly via "curl" if you are running on Linux.

Re: Rest and OpenHab

Posted: Thu Dec 29, 2016 5:27 pm
by tobbe
Ok, I was kind of afraid you would say that...
In practice that would mean I have to write a rest call for every button, sensor and switch I have (32 buttons at least) and I think that would turn into spaghetti code quickly...
If I have understood the documentation properly, changes are pushed to the telnet interface, right?
Maybe it would be possible to somehow have openhab interpet the changes that way?

Regards,
Tobbe

Re: Rest and OpenHab

Posted: Thu Dec 29, 2016 11:31 pm
by stefangsbb
Well, yes, there is a possibility to do something like that, but it is a bit more complicated. Internally ONH uses an event hub, and many messages between items are sent as events. When you press the on button in an NexaLamp, the NexaLamp will send a Nexa_Message-event which is received by the TellStick-Item for example to be sent. You can connect to a TCPCommandPort-Item with Telnet (or any program) and issue the "subscribe"-command. Then you will get all events from the event bus in a easily parsed text format. You can then use some external program or script to transform these events into appropriate REST calls to an external system.
This requires that you write this external program that parses the Events and transforms them into REST calls that the external system understands.