Need help to convert java script to rest command

Hi All,
I need some help how can I convert my java script to switch to config file.
I use this to control my legacy Arduno based home control.

This is the command what works with my Arduino, I control it via simple html.

script:
function proceed (x) {var form = document.createElement(‘form’);form.setAttribute(‘method’, ‘post’);switch (x){
case 1:form.setAttribute(‘action’, ‘http://192.168.1.123/blinkled1’);break;
case 2:form.setAttribute(‘action’, ‘http://192.168.1.123/blinkled2’);break;
}
form.setAttribute(‘target’,‘hidden-form’);form.style.display = ‘hidden’;document.body.appendChild(form);form.submit();} :script end

I use this command to run:

#<#a onclick=“proceed(1)” title=“light up” style="position: absolute; left: 61%; top: 15%; width: 10%; height: 10%; z-index: 99; "/a>
#<#<a onclick=“proceed(2)” title=“light down” style=“position: absolute; left: 61%; top: 32%; width: 10%; height: 10%; z-index: 9;”/a>

I think you first need to set the two urls up as restful commands. You can then check them out with developer tools to make sure they work, and then use the commands as services in scripts.

Yes, however this is my problem, i do not know how to do it. I tried it different ways w/o success

Which bit do you not understand?

How to set up the restfull command first>
I started with this one, but does not work:
rest_command:
example_request:
url: ‘http://192.168.1.123/blinkled1

I think you need to use the POST method. The default is GET.

And can you format your yaml snippets using the instructions in the blue box at the top of the page, it makes them easier to see any problems as spacing is important.

Thank you !
It is working now

Br

1 Like