Can't get web request to work properly


#1

1) Give a description of the problem
I want to use web request in several pistons. One piston for putting my TV in standby and the other to control home assistant (hassio). In both pistons the action web request doesn’t work…

2) What is the expected behavior?
For the TV, when (virtual switch) ‘Bedroom TV off’ turns on, the web request should be made and switch turned off again.
The lights should go on -depending on day or night with an amount of brightness- if the light is off and off if the light is on.

3) What is happening/not happening?
With the lights nothing happens. Not even finding the web response in the logs.
My TV does respond in the log with ‘service unavailable’, while it did function once and using Tasker on my android phone, using a http post from there, it works fine.

4) Post a Green Snapshot of the pistonimage


5) Attach any logs (From ST IDE and by turning logging level to Full)




08:34:31: info ╔ Event processed successfully (141ms)
08:34:31: trace ║╔ Execution stage complete. (2ms)
08:34:31: trace ║╚ Execution stage started
08:34:31: trace ║ Runtime (44578 bytes) successfully initialized in 48ms (v0.3.105.20180628) (135ms)
08:34:31: debug ║ RunTime Analysis CS > 19ms > PS > 48ms > PE > 67ms > CE
08:34:31: info ╚ Received event [Home].time = 1533018872301 with a delay of -1245ms
08:34:12: info ╔ Event processed successfully (113ms)
08:34:12: trace ║╔ Execution stage complete. (17ms)
08:34:12: trace ║║ Executed virtual command log (1ms)
08:34:12: info ║║ []
08:34:12: trace ║╚ Execution stage started
08:34:12: trace ║ Runtime (44581 bytes) successfully initialized in 30ms (v0.3.105.20180628) (94ms)
08:34:12: debug ║ RunTime Analysis CS > 13ms > PS > 30ms > PE > 49ms > CE
08:34:12: info ╚ Received event [Home].wc_async_reply = httpRequest with a delay of 0ms
08:34:12: info ║ Setting up scheduled job for Tue, Jul 31 2018 @ 8:34:32 AM CEST (in 19.995s)
08:34:12: trace ║║ Requesting a wake up for Tue, Jul 31 2018 @ 8:34:32 AM CEST (in 20.0s)
08:34:12: debug ║║ Sending internal web request to: 192.168.2.252:8123/api/services/light/turn_on
08:34:12: debug ║║ Condition group #5 evaluated true (state changed) (19ms)
08:34:12: trace ║╔ Execution stage complete. (83ms)
08:34:12: debug ║║ Cancelling statement #10's schedules...
08:34:12: debug ║║ Comparison (enum) pushed gets (string) pushed = true (0ms)
08:34:12: debug ║║ Condition #17 evaluated false (27ms)
08:34:12: debug ║║ Cancelling condition #5's schedules...
08:34:12: debug ║║ Comparison (enum) off is (string) off = true (1ms)
08:34:12: debug ║║ Cancelling condition #4's schedules...
08:34:12: debug ║║ Condition group #1 evaluated false (state did not change) (38ms)
08:34:12: debug ║║ Comparison (datetime) 1533018852238 is_between (datetime) 1533065520000 .. (datetime) 1533009420000 = false (3ms)
08:34:12: trace ║ Runtime (44588 bytes) successfully initialized in 31ms (v0.3.105.20180628) (103ms)
08:34:12: debug ║║ Condition #4 evaluated true (9ms)
08:34:12: debug ║║ Comparison (enum) pushed gets (string) pushed = true (1ms)
08:34:12: info ╚ Received event [Double light switch].button = pushed with a delay of 50ms
08:34:12: debug ║ RunTime Analysis CS > 11ms > PS > 31ms > PE > 60ms > CE
08:33:44: info ╔ Piston successfully started (587ms)
08:33:44: trace ║╔ Finished subscribing (209ms)
08:33:44: info ║║ Subscribing to Switch 2.button...
08:33:44: info ║║ Subscribing to Double light switch.button...
08:33:44: trace ║╚ Subscribing to devices...
08:33:44: info ╚ Starting piston... (v0.3.105.20180628)

Pretty new to webcore… So probably a mistake from my end…
Thanks in advance!


#2

I’ve only looked at your first piston, but I notice both TV commands turn it OFF.
(there is no TV ON command)


#3

Thanks for your reply. I think the turn off you are reffering to are the ‘Bedroom TV on/off’ switches.
Yes, the piston turns these off. Both switches ‘Bedroom TV on’ and ‘Bedroom TV off’ are the virtual switches that triggers the piston to either turn the TV on (by WOL) or off (by web request).
After that’s done, the virtual switches are put back to off to be ready to be used again.


#4

Right you are… That’s what I get for replying while half-asleep… LOL


#5

When using Send Variables, webCoRE will encode the variables that you select into a JSON object with the name of the variable as the key and the value of the variable encoded as the value. Send a variable named “level” with a value of 12.5 and webCoRE will send the JSON request { "level": 12.5 }.

If you want to build the JSON string manually rather than having a variable for each key in the JSON request you will need to choose the CUSTOM request body type with application/json as the request content type. Your existing json-encoded variables like Light_night should work as the request body with that approach.


Send JSON body with POST request?
#6

That seemed to do the trick. Thanks! Seems webcore is easier than expected, not needing to code it like that.