Change item state by external http call

Hi!
I have device - MegaD328. It’s remote relays controller.
For on or off light i’m use item:

Switch LCab “Люстра” (GCabinet, Lights) { http=“>[ON:GET:http://192.168.1.51/tac/?pt=9&cmd=9:1] >[OFF:GET:http://192.168.1.51/tac/?pt=9&cmd=9:0]” }

It’s work perfectly, but i also have wall switch that can change relay state.
If i toggle wall switch then relays controller send GET ( http://openhab-ip-address/script?pt=n
?pt=n - relay numbers).
I need to parse ?pt=n part, request status of relay n (clarify on or off) and change associated item state for correct display GUI.
Please tell me what I should do to create such a script?

If I understand correctly, you can use openHAB’s REST API to post the update instead of needing to parse the attributes of the URL. This assumes you have a separate Switch for each node and you can change the address that the relay controllers send the GET to.

Instead of sending the get to the address you describe send it to: http://[openhab-ip-address]/CMD?[Switch Name]=[New State]

Where [openhab-ip-address] is the address of your openHAB installation, [Switch Name] is the name of the Item to update (in your example that would be LCab), and [New State] is the state the item should be in (for Switches that would be either ON or OFF).

So, for example, to update LCab when the light is manually turned on you would use:

http://openhab-ip-address/CMD?LCab=ON

and when turned off use:

http://openhab-ip-address/CMD?LCab=OFF

2 Likes

Unfortunately, i can’t use URL to manipulate items, beacause part after “?” is immutable.
I can configure openhab ip address and script name, but arguments generated automaticly by device - it’s a main problem for me.
Also, GET http://openhab-ip-address/script?pt=n is insufficient (it’s only toggle trigger), therefore i need additional request for rubast state synchronization in openhab and relays controller.

Well, I think you are beyond my level of expertise. I’ve looked in the wiki and experimented on my own installation and as far as I can tell http://openhab-ip-address/script doesn’t exist. Are you on openHAB 1.x or openHAB 2?

That being said, I would solve this problem by setting up a proxy web server to receive the ?pt=n part and convert that to an openHAB REST call or MQTT message that openHAB can understand.

1 Like

I use openhab 1.7.1.
I will try to create an analogue of CMD. If this fail, then take up a proxy.
Dear Rich Koshak, thank you for your answers and advices!

Could you solve your issue? What was your approach?
I have a security camera that do not accept the “?” parameter…

First, I set up nginx proxy, but it seemed bad solution to me.
After I wrote special binding for my device.