Send HTTP request action

I’m having an issue that I suspect is within Hubitat, but am not 100% sure.

BLUF: Does Hubitat properly encode URLs entered in “send HTTP request” actions in RM that include an encoded semicolon (%3B) ?

I am using Tasmota running on a Wemos D1 mini to control relays for my pool pump, pool jets, and pool lights. For simple on/off it works wonderfully and integration in Hubitat is great. I love it!

The pool lights are capable of 14 different functions which is accomplished by cycling power off/on the number of times that matches the function. For example, if you want the "Caribbean" colors, you cycle the power to the light off/on 6 times.

Cycling the power from Hubitat kind-of works, but is not a great solution and what I would really like to do is be able to instruct Tasmota to cycle an output pin a prescribed number of times. This places the cycling routine on the D1 Mini and Tasmota rather than back at Hubitat.

To do that, Tasmota offers a blink feature where you can set both the blinktime (speed) and blinkcount (how many blinks). These commands combined with a Power command accomplish the goal of cycling the pool lights the correct number of times. Tasmota even offers a way to neatly package up all the needed commands by using the “backlog” command which executes them in sequence. Consequently, the following command issued from the Tasmota console will blink the relay#3 6 times

backlog blinktime 20 ; blinkcount 6 ; power3 3

This can also be done from a web browser as such… assuming our Tasmota device is accessible on an example IP address of{our backlog command here}

But you have to properly encode the spaces with %20 and the semicolons with %3B. The resulting URL then looks something like this:

This URL works perfectly from Firefox and Edge Chromium. The tasmota device logs that the backlog command was executed.

17:55:10 RSL: stat/tasmota_E9F888/RESULT = {"BlinkTime":20}
17:55:10 RSL: stat/tasmota_E9F888/RESULT = {"BlinkCount":6}
17:55:10 RSL: stat/tasmota_E9F888/RESULT = {"POWER3":"Blink ON"}
17:55:34 RSL: stat/tasmota_E9F888/RESULT = {"POWER3":"Blink OFF"}
17:55:34 RSL: stat/tasmota_E9F888/RESULT = {"POWER3":"ON"}
17:55:34 RSL: stat/tasmota_E9F888/POWER3 = ON

However, when I move that URL into a Hubitat RuleMachine rule as a “send HTTP request” action, the tasmota device logs a command unknown even though it is the EXACT same URL that was sent from the browser.

17:56:36 RSL: stat/tasmota_E9F888/RESULT = {"Command":"Unknown"}

After some playing around, I have determined that the part of the URL that is breaking in Hubitat is the semicolon (%3B). URLs with spaces (%20) seem to work fine, but as soon as you add the %3B the URL it no longer works when sent from Hubitat.

So, to investigate further, I sent the request to a lighttpd web server to see what Hubitat is sending and it looks nothing like what is sent from a browser.

1598393894||GET /cm?cmnd=backlognull2020null3Bnull206null3Bnull203 HTTP/1.1|200|725

1598393999||GET /cm?cmnd=backlog%20blinktime%2020%20%3B%20blinkcount%206%20%3B%20power3%203 HTTP/1.1|200|725

So… loooong story short, is this a broken feature in Hubitat or have I missed the boat altogether?

The problem you are running into is the "%" is used to wrap a Global Variable in Rule Machine. So, if you wanted to send a Global Variable with the name of "test" at the end of your url, you would do this:

Rule machine is interpreting everything between percent signs as variable names. So, if you were to add a local variable to your rule, set that variable to the properly encoded url, then add that variable to the end of your request, it would work perfectly.

Since this is a Tasmota device using a user defined driver, you could always add this to the driver at some point as well, if you decide to take a crack as writing in Groovy.

Well... thanks... that actually makes a LOT of sense and explains all the "nulls" that I'm seeing in the request. Sounds like I can leverage the variable to escape the % signs in the URL. Kewl.

As for Groovy and writing drivers, I would love to become a pro at writing/editing drivers... but feel I'm sitting at the bottom of the steep part of the hill. Maybe someday. Thanks for reading through my super long post to dig out the correct answer. Much appreciated.

No problem. If this is the first problem you've come to, then you're doing pretty damn good already, IMHO.

I guess I just don't get it...

I moved the command portion of the URL with all of it's % symbols to a string variable and HE still tries to replace whatever falls between odd and even % symbols with variables. How do I simply escape the % symbol from being interpreted as the start or end of a variable. Some languages use a backslash, others allow you to delay variable expansion, etc. I even tried to escape the % symbol with %25 which is the percent symbol when submitted in a URL. No dice. I just want to escape the % symbols.

If I place the entire URL in a file and upload to Hubitat... then set the variable to the contents of the file... then use the variable for the URL in the send HTTP request action, it works with no variable substitution. However, if I place the entire URL in the variable, it does not work and substitution occurs. Very odd behavior.

Have you tried not setting the URL encoding and just leaving it with what would be human readable (ie: spaces)?

I have... URL gets transmitted with the spaces and of course fails. At the end of the day, the only way I could get Hubitat to accept a URL with 2 or more % signs in it was to place the URL in a file, upload to HE... then read that file into a variable and use the variable for the URL value. I was not able to directly write the URL to a variable because variable substitution occurred.

At the end of the day, what I really need is the ability to escape the % signs so they are not interpreted as surrounding variable names. If HE does not support that, it should. If it does support escaping characters, PLEASE tell me how.