Switch that perform http actions

Good morning everyone, at home I have several Raspberry that perform many home automation tasks. Each of them has a webserver made in php and pyton that exposes a html page of the type attached in figure 1:

I have a no-ip system configured in the modem and the ports opened so I can get to the various Raspberry even from the internet.
each web server has its own authentication and works in https, after authentication to requests like: mysyte.sytes.net
the webserver responds in the browser line with:
mysite.sytes.net/cgi-bin/ciao.cgi?IN1=off&IN2=off
Each Raspberry is completely autonomous and I would like to maintain autonomy.
But I would like to replicate all the commands with the open hab interface so that I can also use Google Home.
What I would need and that by pressing a button on the interface of openhab is sent an http request like this:

On command: mysite.sytes.net/cgi-bin/OUT1ON.php
Off command: mysite.sytes.net/cgi-bin/OUT1OFF.php

Is it possible to send http requests from Openhab?

Thank You

Stefano Fredella

This can be achieved by utilising the HTTP Binding directly:

Take a look at https://www.openhab.org/addons/bindings/http1/ for examples,

or could be achieved in rules utilising the sendHttpGetRequest(url) command.

2 Likes

Thank You, I read the guide and I can solve the first part of the problem. in fact now I can turn the light on and off. I do not know how to read the status of light from the webserver’s response. What should I do to read a field in the url and compare it with the strings for the on and for the off?
Now the item is:

// Remote control
Switch ExternalLight1 "Esterno 1" ["Lighting"] {http=">[ON:POST:http://myuser:mypassword@192.168.1.137/ON.php] >[OFF:POST:http://myuser:mypassword@192.168.1.137/OFF.php]"}

thank you.

Can anyone help me?

There are examples in the binding docs, and in this forum. What have you tried so far? What form does the response take?

Hi, I write to http.cfg:

my1Cache.url=http://mysytes.net/mypage.cgi?IN1=%1$s&IN2=%2$s
my1Cache.updateInterval=1000

I don’t know if this code is good to read the string but if yes I think that is necessary a rule to read my1Cache, to change the status of Item ExternalLight1 .
In my mind the my1Cache must be parse to read the status of in1 and in2 and the status of the switch must be set equal to in1. The seconds in2 can be ignored for now
I have no idea how to read and parse the string my1Cache in a rule.

The examples that I found always read the status from the same page. I must read the status from another page because when I call the url for switch on or off the light, the server redirect the browser to another page with the new status of the light. ((http://mysite.sytes.net/cgi-bin/OUT1ON.php is redirected to http://mysite.sytes.net/cgi-bin/ciao.cgi?IN1=on&IN2=off)

Thank You in advance

Okeydoke, I would create a test Item of type String to begin with, link it to your HTTP cache without any transformation, and make sure you get the response you expect.

If that seems to work, make a test Item of Switch type. This will need a transformation, type REGE I expect. I don’t know much about that, maybe someone else would help there.

Once you have it working on your test switch, bind to your real switch instead.

This looks similar