How to trigger an action with a HTTP request from an external device?

Hi everyone,

Although I’ve been tinkering with home automation for a couple of years, I barely scratched the surface and I still feel green about it. Hopefully you can point me in the right direction.

I’d like to use a Mobotix video doorbell’s “light” button to turn on the outside lights for a few minutes. Nothing fancy.

Most of the components for the execution end are already in place: openHAB is configured with the KNX interface and can control the lights, and the script to react on a trigger to turn the lights on and off after a few minutes is not that hard to build.

The part I don’t know is how to handle the trigger from the Mobotix camera. It can only send a HTTP (GET but not POST) request, with or without waiting for a response, or a raw TCP packet with whatever content I want, when the button is pressed. Not very integration-friendly with other solutions, but works with other Mobotix devices.

What software can react to that HTTP request (or raw TCP connection)? Can openHAB be triggered somehow with a specially constructed URL? Do I need some sort of other software to listen to HTTP requests and send another type of message out (MQTT)? Do I need another automation engine like Node Red just for this?

Is there an obvious solution staring at me and I’m just oblivious to it?

I looked at the HTTP Binding but that seems to work the other way around - openHAB sending HTTP requests to trigger actions in other devices or to pull data in from other systems. The one-line description for the binding is not that self-explanatory to me.

Many, many thanks in advance!

Have a look into

Thanks, @Wolfgang_S - looks like it’s exactly what I need. I have a working script to behave like a staircase light, just struggling a bit to trigger it through httplistener.

The JSON for the thing is:

{
  "channels": [
    {
      "key":"action",
      "kind": "STATE",
      "state": "req.parameters.action[0]"
    },{
      "key": "card",
      "kind": "STATE",
      "state": "req.parameters.card[0]"
    },{
      "key":"run",
      "kind":"TRIGGER",
      "state":"req.parameters.run[0]"
    }
  ]
}

The URL invoked is: http://openhab_ip:port/httplistener/script_id?run=GO . I also tried with action=something or without GET parameters, but the script is not running. Any clue what am I doing wrong, please?

is the uid of your thing ?
Best would be to post the comlete YML code of your thing.

Hi,

Sorry for the delay, I was on a work-related trip with no time to access remotely the homelab. And thank you for the prompt offer to look into the details!

The script_id is really the ID.

I caught up a bit with sleep deficit and found my mistake :slight_smile: I was trying to invoke the Script UID to test that the lights are turning on and off, but that didn’t work.

Now I created a Rule with the same script to be executed, and put the HTTP Thing as Trigger. I can trigger the Thing and it starts the Rule with the script just fine. All I have to do is configure the Mobotix camera with the URL and that’s it.

For reference:

HTTP Listener Thing:

UID: httplistener:HttpListener:1b255e2698
label: HttpListener
thingTypeUID: httplistener:HttpListener
configuration:
  jsonConfig: |-
    {
      "channels": [
        {
          "key":"action",
          "kind": "STATE",
          "state": "req.parameters.action[0]"
        },{
          "key": "card",
          "kind": "STATE",
          "state": "req.parameters.card[0]"
        },{
          "key":"run",
          "kind":"TRIGGER",
          "state":"req.parameters.run[0]"
        }
      ]
    }

URL to trigger it:

http://<openhab_IP>:<port>/httplistener/1b255e2698?run=ON

Rule:
When channel httplistener:HttpListener:1b255e2698 was triggered
Then execute a given script

  1. Send command “ON” to item “Front_door_light”
  2. After “x” seconds do with timer “FrontLightTimer”
    send command “OFF” to item “Front_door_light”
    reschedule if retriggered
2 Likes