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

The binding also works for me for a Foscam VD1 doorbell under openHAB 3.3.

Can you also make a 3.3 snapshot or even better an official binding?

1 Like

I use the bindig to integrate my Garmin watches to OH.
I’m using the APICall App on the Garmin, to send the get calls to the httplistener.
It communicates via SSL trough myopenhab.org and it works like a charm.
I’d also like to see the httplistener as an offical binding.

I’d love to learn more about this!

Have some hard times monetizing my professional job now + some scheduled medical procedures + private life now
 I will get to the official binding listings in time - I should hit this in 2022, at least in q4.

2 Likes

Hi Jeff, i also have a Foscam VD1. Can you please post you configuration? I am not able to getting this working.

THX

@curro Here the setting for the Foscam VD1.
192.168.53.21 is my openHAB Raspberry Pi.

Below the code for the HttpListener binding.

I use the item DoorbellHttpListener_videocall to trigger the rule, in it I start the recording.

configuration: {}
triggers:
  - id: "3"
    configuration:
      itemName: DoorbellHttpListener_videocall
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/javascript;version=ECMAScript-2021
      script: >-
        /*
         * We use a function otherwise return is not working
         */
        function mainCheck() {
          // Reset trigger
          console.info('Reset trigger');
          items.getItem('DoorbellHttpListener_videocall').sendCommand('OFF');

          // Clear history
          if (items.getItem('DoorbellFoscam_GIFHistoryLength').state > 5) {
            console.info("Clear GIF history");
            items.getItem('DoorbellFoscam_GIFHistoryLength').sendCommand(0);
          }
          
          // Make a GIF record
          if (items.getItem('DoorbellFoscam_GIFRecording').state == 0 || items.getItem('DoorbellFoscam_GIFRecording').state == 'NULL') {
            for ( let i=5; i>=1; i-- ) {
              let argSrc  = '/tmpfs/doorbell/image' +  i    + '.gif'
              let argDest = '/tmpfs/doorbell/image' + (i+1) + '.gif'
              actions.Exec.executeCommandLine('cp', argSrc, argDest);
            }    
            
            actions.Things.getActions('ipcamera', 'ipcamera:foscam:DoorbellFoscam').recordGIF('image1', 4);
            console.info('Record taken');
          }
        }


        // Call your main function from the script

        mainCheck();
    type: script.ScriptAction
UID: httplistener:HttpListener:doorbell
label: Doorbell HttpListener
thingTypeUID: httplistener:HttpListener
configuration:
  jsonConfig: |-
    {
      "channels": [
        {
          "key":"motion_detection",
          "kind": "STATE",
          "state": "req.parameters.motion_detection[0]"
        },
        {
         "key": "sound_detection",
         "kind": "STATE",
         "state": "req.parameters.sound_detection[0]"
        },
            {
         "key": "video_call",
         "kind": "STATE",
         "state": "req.parameters.video_call[0]"
        },
            {
         "key": "face_detection",
         "kind": "STATE",
         "state": "req.parameters.face_detection[0]"
        }
      ]
    }

Greetings Holger

2 Likes

Thank you so much


after reading the documentation :wink: and some posts here I’m still confused.
What’s the right url to call?

E.g. I tried:
http://local_ip:4050/httplistener/interface?doorstation=ON

  • id: doorstation
    channelTypeUID: http:switch
    label: TĂŒr Klingel
    description: “”
    configuration:
    onValue: ON
    offValue: OFF

This is a valid question still unanswered in this topic or the “HTTP” binding. I’M also not sure if this binding here is actually the same as the HTTP binding currently available or something totally different.

Can someone please tell us whats the proper URL these days?

Hello. This webhook is not the same as http binding at all. http-binding lets you call external services via HTTP requests. This webhook binding lets you call your openhab through http from external services.

Whats question is stil valid and unaswered?

@messiah could you elaborate more what are you trying to achieve? Are you trying to call some doorstation (akuvox?) to open a gate or notify openhab that the doorstation detected opened gate?

I guess we both are looking for a webhook receiver, IE an app sends a request to an URL, and that gets picked up by OH to change item state. Though it seems that this was answered in another topic with “Openhab has an REST API” that can be used for this purpose

REST API does not fulfill every needs. To update a thing through rest API one should use http post method whether lots of devices cannot call a webhook with a method other than http get.

Also to update more than one thing channel through rest you must call more than once the rest API.

This binding overcomes those limitations. You can update the channel with a get call or you can update few channels with one call.

1 Like

Ok, shame on me. I tried to configure the wrong binding because the access rights were not correct for the jar file. Therefore it did not show up in the addon list.
Now I did correctly install the jar file :slight_smile:
Sidenote: You name it “webhook”, later “http listener”. Maybe use one name for it?

My actual goal is to receive a doorbell trigger from Akuvox station. The station can call a http url when the button is pressed.
Thank you for developing this binding. It could help me to easily solve this task.

Shall I use “trigger” for it?

If yes, there is an error when I try to configure an item, see screenshot

Thing Configuration:

UID: httplistener:HttpListener:d91dfb6904
label: HttpListener thing
thingTypeUID: httplistener:HttpListener
configuration:
  jsonConfig: |-
    {
      "channels": [
        {
          "key":"action-trigger",
          "kind": "TRIGGER",
          "state": "req.parameters.action-trigger[0]"
        },{
          "key": "action-state",
          "kind": "STATE",
          "state": "req.parameters.action-state[0]"
        }
      ]
    }

Update:
http://192.168.178.49:4050/httplistener/d91dfb6904?action-state=2

will cause “HTTP ERROR 500 org.apache.commons.jexl3.JexlException$Variable: org.openhab.binding.httplistener.internal.HttpListenerHandler.createChannelUpdater:113@1:23 variable ‘trigger’ is undefined”

if teems that expression “req.parameters.action-trigger[0]” is treated as a mathematical substraction operation between req.parameters.action (which is null and this is ok) and trigger[0] (which is a pointer to array but null - not ok)

If would try followin

UID: httplistener:HttpListener:d91dfb6904
label: HttpListener thing
thingTypeUID: httplistener:HttpListener
configuration:
  jsonConfig: |-
    {
      "channels": [
        {
          "key":"action-trigger",
          "kind": "TRIGGER",
          "state": "req.parameters.actiontrigger[0]"
        },{
          "key": "action-state",
          "kind": "STATE",
          "state": "req.parameters.actionstate[0]"
        }
      ]
    }

and then http get to http://192.168.178.49:4050/httplistener/d91dfb6904?actionstate=2&actiontrigger=1

I have made some changes to the binding. Instead one global configuration I have used the feature to dynamically create channels from UI. Each channel has its own
expression code-like configuration to extract data from the http call. this is my example for my akuvox intercom:

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";
        };

In upcomming changes I will expreriment to get rid off apache jexl expression language in favour of openhab own languages like javascript or v1 rules language.

1 Like

Thank you, it works now with kind “STATE”! :slight_smile:
Still kind “TRIGGER” throws an error message (“Please configure a valid profile”). But it’s fine for my purpose to use a string.

Webhook

Hello, I’m currently trying this nice program, but unfortunately I can’t get any further :frowning:

The goal is that I use a webhook (link or something) from my 3D printer server to OpenHAB to switch off the socket that is responsible for the printer when it is finished.
the other 3 options would be to change the light on the printer.
Chris.

UID: httplistener:HttpListener:PrusaPrinter
label: PrusaPrinter
thingTypeUID: httplistener:HttpListener
configuration:
  jsonConfig: |-
    {
      "channels": [
        {
          "key": "heat",
          "kind": "STATE",
          "state": "req.parameters.heat[0]"
        },
        {
         "key": "print",
         "kind": "STATE",
         "state": "req.parameters.print[0]"
        },
            {
         "key": "finish",
         "kind": "STATE",
         "state": "req.parameters.finish[0]"
        },
            {
         "key": "off",
         "kind": "STATE",
         "state": "req.parameters.off[0]"
        }
      ]
    }

Maybe following will work:

This Works, but what is the Link for Activating? :confused:

Could you elaborate more about what is following?