[webhook] New, very simple binding for listening incomming http requests

Thank you Oliver!

Yes a few week ago I updated from OH3 to OH4. Sadly something went wrong and OH didn’t start any more. I think it was because of JDK17. After upgrade still v11 was installed. I couldn’t manage it to install v17 manually on the Raspi (seems to be rocket science). I then decided to start with a fresh new openhabian image for my Raspi. As I always configured everything through config files and I had a backup of those, I could quickly recover everything apart from the bell. So yes, I am on JDK v17 and bullseye.

I can confirm that I can not select this binding in the “choose binding” dialog (was it available in OH3?).

I am not sure how to check in karaf. I tried the bundle:list command and could find this:
image

I also tried enabling inkompatible add-ons and the fix permissions option…without success.

Is it possible to define the log level of this binding somewhere?

log:set TRACE org.openhab.binding.httplistener
//or log:set DEBUG org.openhab.binding.httplistener

Please note, I can confirm that this binding works when triggering a channel. I did not test sending a command to an item.

Thank you Oliver!!

I didn’t know that it’s possible to execute a rule when a channel is triggered. At the end I don’t need this Klingel-item.

So I changed my thing to kind : TRIGGER and changed my rule accordingly. Now it is working perfectly!

Thank you so much!

1 Like

Yeah, I could arrange that. The binding is on github, but in the form of merge request to openhab main repository, version 3.x

I could strip of the repo to be standalone project and then open to pull requests and finally deliver it to third party marketplace.

2 Likes

I’ve created new github GitHub - ptrbojko/openhab-webhook-binding

code is compiling, ready to have some support love

2 Likes

Hi Piotr,
not sure what you mean. Github site is the same, I can see updated files but no jar file at all.
What is new?

Oh, my message was rather a poke to @Raphael1 :slight_smile: - he was offering help to maintain the binding to bring it to the marketplace :slight_smile:

Anyway, I have get rid of all boilerplate and remove all repository in which resides all official bindings and leave only the webhook binding itself. Previously the repository was kind of directed towards pull to official bindings, not the third party makertplace. However pulling to official brings much more effort and it is beyond my spare time.

1 Like

Hi
Are there updated snippet (I’m using OH4) that works to trigger String value using a query string param ?
Does POST Form request (“Content-Type: application/x-www-form-urlencoded”) works ?
Thanks.

Hi, what do you mean stating "updated snippet?

Binding should work for all http request methods (GET, POST, PUT, etc)

Hi,

I am preparing to release a binding to the marketplace. However I lack of spare time to test the release against OH 4.x (I had to increase work hours due to low on family budget :frowning: )

This is a build https://github.com/ptrbojko/openhab-webhook-binding/actions/runs/7233350729/artifacts/1119250334

Any help appreciated. (I have also setup Github Sponsors profile to repair my family budget).

Error message while loading. I probably need to install a dependency package jexl3:

2023-12-16 19:01:24.575 [WARN ] [org.apache.felix.fileinstall        ] - Error while starting bundle: file:/usr/share/openhab/addons/org.openhab.binding.webhook-0.1.0-SNAPSHOT.jar
org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.webhook [243]
  Unresolved requirement: Import-Package: org.apache.commons.jexl3; version="[3.2.0,4.0.0)"
	at org.eclipse.osgi.container.Module.start(Module.java:463) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:445) ~[org.eclipse.osgi-3.18.0.jar:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1260) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1233) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:520) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:365) ~[?:?]
	at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:316) ~[?:?]

I am on a OH 4.0.4 64bit bookworm test system

I am little rusty on this. Maybe this build will be ok https://github.com/ptrbojko/openhab-webhook-binding/actions/runs/7235282635/artifacts/1119484794

Here are my test results:

  1. Binding not visible in MainUI (neither in settings nor when adding a thing)
  2. For this reason adding a thing needs to be done through rest-API (took some time to realize that the ID of your binding changed from httplistener to webhook)
  3. After adding a channel, the channel type (switch, number, string) is not visible and editable anymore in channel config menu
  4. Most importantly: I have no idea what I need to enter into Response expression. In the old version I needed to provide a JSON expression which does not work anymore

It seems that 0h3->0h4 switch should contain far more changes that I thought. I’ve setup dev env for oh4 and trying to pass though problems.

ok. Got it. It needs to be

return req.parameters.action[0];

for example.
The other points I mentioned above are not crucial, ugly at most, but your binding is working well!

Example from my home instance:

Thing:

UID: webhook:Webhook:intercomhook
label: Intercom webhook
thingTypeUID: webhook:Webhook
configuration:
  expression: resp.status=200
channels:
  - id: call
    channelTypeUID: webhook:string-channel
    label: Call
    description: ""
    configuration:
      expression: |-
        if (req.parameters.action[0] == "call") {
          return "CALLING";
        };
  - id: wicketbutton
    channelTypeUID: webhook:switch-channel
    label: Wicket button
    description: ""
    configuration:
      expression: |-
        if (req.parameters.action[0] == "input2") {
          return "ON";
        };
  - id: WicketOpeningSensor
    channelTypeUID: webhook:contact-channel
    label: Wicket opening sensor
    description: ""
    configuration:
      expression: |-
        if (req.parameters.action[0] == "input1") {
          return "OPEN";
        };
  - id: CardEntered
    channelTypeUID: webhook:trigger-channel
    label: Card entered
    description: ""
    configuration:
      expression: >
        if (req.parameters.action[0] == "validcard" || req.parameters.action[0]
        == "invalidcard") {
          return req.parameters.card[0];
        };

I’ve change the config to split one json like config to apache jexl epxressions per thing (to describe the http response) and per channels (to describe mapping from request to channel value).

Little donation for your family sent👍🏻

2 Likes

Can you share a curl example that call this service ?

openhab:8080/webhook/thingName?action=ON