Hello HA lovers,
I came to HA after starting hack a Chinese smart plug called Kankun, after that I discovered this wonderful platform and now my smart plug (and a lot of other smart-things) are happily integrated in it.
When I was using my smart plug as standalone I built a nice Wi-Fi connected push button to control the plug (more info here). The button is built using an ESP8266 and it’s pretty simple, when it’s pressed the following code is fired (more details here httpget.lua):
conn:send("GET /cgi-bin/relay.cgi?"
.."toggle"
.." HTTP/1.1\r\n"
.."Connection: close\r\n"
.."Accept: */*\r\n"
.."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n"
.."\r\n")
end)
It basically sends a command to a script (relay.cgi) which is host into the smartplug and which toggles the switch.
SO… my question is: I would like to use the same concept to toggle a switch (or whatever) through the HA api, basically the same thing that Bruh did for the Amazon Dash button using these lines of code:
{"buttons":[ {
"name": "Your Name",
"address": "your:dash:mac:XX:XX:XX",
"url": "http://your.ha.ip.adderss:8123/api/services/switch/toggle",
"method": "POST",
"headers": {"x-ha-access": "your_password"},
"json": true,
"body": {"entity_id": "switch.megadesk_leds"} }]}
Since I’m a total newbie and just an amateur when we talk a about coding, can someone help me in modifying the httpget.lua to interact with the HA api?
Thanks a lot to everyone who had the patience to read all my post