Control By Web WebRelay

Hi,
I have a Control by Web Webrelay X-WR-1R12-1I5-E (1 relay, 1 inpute) that I have been able to get the Relay to activate using the Command line platform and Curl with Get. I am however stuck on trying to figure out how to have HA read the Input state of the input on the device. I also would like to see if there is a way for HA to “monitor” the state of the relay so if something else triggers it on HA will know that it is on and the status will be updated on HA.

I am not sure if anyone else has had experience with this but I thought I would put it out there in case they have. I am going to guess that I need to use the RESTful Sensor or RESTful Binary Sensor however I am not sure exactly how to set that up. I am also not sure if I need to setup Remote Relay Options on the Webrelay.

Here is the link to the manual if anyone needs it as a resource. https://www.controlbyweb.com/webrelay/webrelay_users_manual.pdf
The remote Relay options start on page 45. Page 59 also has all of the xml control strings listed.

This is what I am using for the switch part. It works to activate the Relay on and Off but it does not see the state it is in so if something else activates HA does not know that it is on.

1 Like

The manual does not clearly describe how to get the state. My guess would be, that you just have to leave out the =0 at the end of the URI you’re using.

So in HA it would look like this?

sensor:

This is what the States url on the webrelay looks like (http://10.152.7.80/state.xml

0 0 0 0

You probably need to somehow parse the output. In the manual it says:

<?xml version="1.0" encoding="utf-8" ?>
-<datavalues>
<relaystate>1</relaystate>
<inputstate>0</inputstate>
<rebootstate>0</rebootstate>
<totalreboots>0</totalreboots>
</datavalues>

With that info in mind I would assume the first 0 corresponds to the actual state of the relay. So the option value_template template mentioned in the docs would be what you need to extract the first 0.

I havnt even come close to working templates so I dont quite understand them. :slight_smile: First to clarify are you going the route of see what the relay state is so HA can update the state or have you been talking about the input?

From what i can see in the template doc you need to know what the incoming values looking like. Is there a way to know/check or would it be built from what is on the state.xml page?

I’m not a template expert either. I always have to look at the docs because I rarely use them.

What I’m talking about is the state of the relay / switch. You are currently switching it via command line, but you consier changing that to the restful switch. After having another look, the rest switch might not be what you need. The command switch has more flexibility, so I would stick to the command switch you already have. That one has the command_state option, together with the value_template. The way I thought of before would have actually given you the switch and a separate sensor you would have to monitor, which wouldn’t be so nice.

So what could work would be something like:

platform: command_line
  switches:
    relay_one:
      command_on: "curl -X GET http://10.152.7.80/state.xml?relayState=1"
      command_off: "curl -X GET http://10.152.7.80/state.xml?relayState=0"
      command_state: "curl -X GET http://10.152.7.80/state.xml?relayState"
      value_template: '{{ value.split(" ")[0] }}'

Edit: The template would work if the output realy is 0 0 0 0. It may not work if it’s the xml as described in the documentation. In that case it probably will become a lot more difficult.

Ok so that one I might not worry about.

Do you have an idea on the input one to use it as a sensor or would that probably be about the same?

According to the manual the input is the second 0 in what you get from the API. So it would be pretty muh the same as getting the state of the switch.

Ever have any luck with this? I have a X-332 and just installed home assistant on a pi. Looking to do similar. Any light at the end of the tunnel?

I have not had any luck on the input or Status with the WebRelay. I have been able to get curl working to turn it on and off but that is it. Since i cant get the status it is also just and assumed state. For instance if I were to turn the webrelay on via the webui HA would not update to match.

It worked for me that way with a WebRelay-Quad:

The way to get there has been by debugging via sensors as follows:

I hope it helps!

How did you come up with the number used in the Template?

I think i just figured it out. thats the number location of the character?

thanks @polclota that is exactly what i was looking for. The only down fall and question to see if you would know is that if the webrelay gets a state change from something other than HA the state in the HA UI takes about 20 seconds to update. is there a way to get the switch to poll the state quicker?

@ansonchevrolet the number for the value is kind of tricky to come across. You need to view the source page of the state.xml page. Once you do that you need to do some character counting. for me I used a basic text editor. Below is my source page. Dont count the first < at ?xml. also there are two spaces on the carrage returns. so for me i was looking for the 0 below in the 0 which ends up making that value 66.

<?xml version="1.0" encoding="utf-8"?> 0 0 0 0

Yes, the number within the square brackets is char position. That’s why I added the sensors to see if my count was wright. Use this online tool to count them, http://www.charactercountonline.com/

This is how it looks for me:
image

If you turn the relay on or off from the webrelay ui do you have the 15-20 second delay for HA to update?

No. It’s almost instant for me. May be because I added:
scan_interval: 5

Add that into the switch also? I had it on the sensor but wasn’t sure if it could go on the switch too.

Oops, sorry I missed that…I don’t think that works with switches…they have command_state instead.

Hi Guys,

I have the same controlbyweb device - well an X310 to be exact. - I seem to be having a similar problem to you guys initially, but with some different symptoms. - I don’t know anything about coding ( im an electrical engineer, - hardward not S/W), I ive basically hacked what you guys have done, experimented with of the HA command line switch examples in the wiki.;

OK, here’s what Ive got in the config.yaml:

Here’s the dashboard with the switches
barn%20HA

When I activate the switch, two things happen…

    • the switch in the GUI slides to on, and the little comment appears in the lower left, but then turns off again after a second or two. ( includes all relays, not just relay 4 - the pulse commanded relay)
      2 - Nothing happens on the actual hardware device.

If I got into a seperate browser, and manually enter the HTTP, the relay fires and the response is as such:

Its as if nothing is being fired to the X310.

If I can get this working, then I’ll start looking into how to get the feedback from the X310 to let HA know if the relay is on or off.

Any help appreciated.

Jarrod, from Australia.