I got Tenda Beli SP3 smart plug. Searched web, it seems to work using rest api. Still new to HA. I have latest docker HA 2023.9.3 on Qnap NAS. tried http://x.x.x.x:8123/api with e404 error. looks like api is not loaded. Anyone can help to let me know how to get Rest API enabled on my HA?
I got SP3 smart plug in static ip already 192.168.11.40. how to added into HA. Till now I am using all GUI interface with limited scipt knowledge when using automation to add random time period only.
Hello,
Sorry but I’m confused …
Where is the API you want to access?
If it is the HA one from the plug, then you have to get a long term token created in your profile and use it like so (in python, query state of a light)
from requests import get, post
url = "http://x.x.x:8123/api/states/light.my_light"
headers = {
"Authorization": "Bearer yourverylongtimetoken",
"content-type": "application/json",
}
response = get(url, headers=headers)
print(response.text)
If it is the API of the plug, then you can use the RESTful Sensor integration.
Or the Scrape integration if it is read only
finally I got it working. following Tenda SP3 wifi plug with RTL8710BX chipset
Will post more detail as I went through a lot try and error and etc.
Hi,
From what I read on various forums including your post, I declared SP3 in Home Assistant quite simply this way :
switch:
- platform: rest
resource: http://@IP:5000/setSta
name: SP3_1
unique_id: @mac
state_resource: http://@IP:5000/getSta
is_on_template: ‘{{ value_json.data.status == 1 }}’
body_on : '{"status":1}'
body_off : '{"status":0}'
headers:
Content-Type: application/json
@IP is the IP address of the SP3 (DHCP Reservation)
@mac is the mac address of SP3 which I use as a unique identifier
I command this to turn it on and off.
I am now looking at how to get these states into HA.
Thanking you for your publication
Marc