Help? Terminal Curl to Applescript for BTT - Smart Lights/Plugs

I have been working on a way to check the status of Smart Plugs/Lights. I figured out how to poll the status of the light in terminal.app and receive the correct results (ON or OFF), but when trying to do this in apple script, Im getting a lot of errors/issues. The script is below that DOES work in terminal (I changed the device token/IDs for privacy). I guess its the formatting this code for AppleScript, I use Do Shell Script, and the Json fails. So anyone know how to change the format to work in an AppleScript???

If anyone has any ideas how to change this for BTT to call this script, it would be appreciated.

Checks current status of relay/switch (works in Terminal)

curl -s --request POST "https://wap.tplinkcloud.com/?token=4020fad5-A4uZA38Udl HTTP/1.1"
--data '{"method":"passthrough", "params": {"deviceId": "80067CF3B3279C1845", "requestData": "{"system":{"get_sysinfo":null},"emeter":{"get_realtime":null}}" }}'
--header "Content-Type: application/json" | grep -q '..relay_state..:1' && echo "ON" || echo "OFF"

Turns on or off the switch depending on the "state"

do shell script "curl --request POST https://use1-wap.tplinkcloud.com/?token=4020fad5-A4uZA38 --data '{'method':'passthrough', 'params': {'deviceId': '80067CF3B3279C1845', 'requestData': '{"system":{"set_relay_state":{"state":1}}}' }}' --header 'Content-Type: application/json'"

Why? I found a way to by pass using IFTTT web hooks to control these devices, and call them directly using the same commands as the smart home app itself (Kasa - TPLink). These commands turn on/off plugs instantly and will be able to return the status of the plugs, which I can then use for BTT to show status of your Smart Home devices in Touch Bar. Basically, putting the Kasa.app in your Touch Bar.

No matter what changes I make to the formatting of this curl script, I cannot get it working in AppleScript. Works fine in terminal. I know AppleScript dent like double quotes, or single quotes, or this and that, no changes I can make provide we with a result :(.

Hopping someone here may have a better understanding of AppleScript and Curl.

Got this working thanks to Andreas for pointing out BTT supports Shell Scripts natively in a widget. I cant believe I never saw that!!!

Imprint | Privacy Policy