Closed dradissoftware closed 10 months ago
Hi @dradissoftware
sendPowerStateEvent
is to let the server know about physical changes. Sending on/off state to a device can be done via API only.
To use the API,
curl --location --request POST 'https://ifttt.sinric.pro/v1/actions'
--data-raw '{
"api_key" : "xxxx",
"device_id": "xxx",
"action": "setPowerState",
"value": { "state": "On" }
}'
Ref: https://github.com/sinricpro/esp8266-esp32-sdk/issues/70#issuecomment-644781907
Thank you, that was just what I needed. I can now make calls to the API from my ESP01 with code like this...
char* host = "https://ifttt.sinric.pro/v1/actions"; int httpsPort = 443;
String data = "{ \"api_key\": \"ffffff-1111-2222-33333\", \"device_id\": \"123567890abcdef\", \"action\": \"setPowerState\", \"value\": { \"state\": \"On\" } }";
WiFiClientSecure client; client.setInsecure(); client.connect(host, httpsPort);
HTTPClient http; http.begin(client, host); http.addHeader("Content-Type", "application/json"); int httpCode = http.POST(data); http.end();
Is it possible to set the PowerState of a switch from a remote ESP device? For instance, if I wanted a to flip a switch to turn on all my individual lights (switches), I could get all the switch devices by ID and then call setPowerState to turn them all on or off. It seems like "sendPowerStateEvent" only notifies Sinric that the power state has changed, it doesn't actually fire the switches "onPowerState" function.