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.
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.
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.
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. 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.
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.
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.
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/
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.;
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: