Last active
September 15, 2021 16:19
-
-
Save kakopappa/ec3a1c664e116a8423ce0a6b33ed7a7d to your computer and use it in GitHub Desktop.
drape and curtain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#define ENABLE_DEBUG | |
#ifdef ENABLE_DEBUG | |
#define DEBUG_ESP_PORT Serial | |
#define NODEBUG_WEBSOCKETS | |
#define NDEBUG | |
#endif | |
#include <Arduino.h> | |
#ifdef ESP8266 | |
#include <ESP8266WiFi.h> | |
#endif | |
#ifdef ESP32 | |
#include <WiFi.h> | |
#endif | |
#include "SinricPro.h" | |
#include "SinricProBlinds.h" | |
#define WIFI_SSID "" | |
#define WIFI_PASS "" | |
#define APP_KEY "" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx" | |
#define APP_SECRET "" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx" | |
#define DRAPE_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx" | |
#define CURTAIN_ID "" // Should look like "5dc1564130xxxxxxxxxxxxxx" | |
#define BAUD_RATE 9600 // Change baudrate to your need | |
int drapeBlindsPosition = 0; | |
int curtainBlindsPosition = 0; | |
bool onDrapePowerState(const String &deviceId, bool &state) { | |
Serial.printf("Drape %s power turned %s \r\n", deviceId.c_str(), state?"on":"off"); | |
digitalWrite(22, HIGH); | |
return true; // request handled properly | |
} | |
bool onDrapeRangeValue(const String &deviceId, int &position) { | |
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position); | |
return true; // request handled properly | |
} | |
bool onDrapeAdjustRangeValue(const String &deviceId, int &positionDelta) { | |
drapeBlindsPosition += positionDelta; | |
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, drapeBlindsPosition); | |
positionDelta = drapeBlindsPosition; // calculate and return absolute position | |
return true; // request handled properly | |
} | |
bool onCurtainPowerState(const String &deviceId, bool &state) { | |
Serial.printf("Curtain %s power turned %s \r\n", deviceId.c_str(), state?"on":"off"); | |
return true; // request handled properly | |
} | |
bool onCurtainRangeValue(const String &deviceId, int &position) { | |
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position); | |
return true; // request handled properly | |
} | |
bool onCurtainAdjustRangeValue(const String &deviceId, int &positionDelta) { | |
curtainBlindsPosition += positionDelta; | |
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, curtainBlindsPosition); | |
positionDelta = curtainBlindsPosition; // calculate and return absolute position | |
return true; // request handled properly | |
} | |
// setup function for WiFi connection | |
void setupWiFi() { | |
Serial.printf("\r\n[Wifi]: Connecting"); | |
WiFi.begin(WIFI_SSID, WIFI_PASS); | |
while (WiFi.status() != WL_CONNECTED) { | |
Serial.printf("."); | |
delay(250); | |
} | |
IPAddress localIP = WiFi.localIP(); | |
Serial.printf("connected!\r\n[WiFi]: IP-Address is %d.%d.%d.%d\r\n", localIP[0], localIP[1], localIP[2], localIP[3]); | |
} | |
void setupSinricPro() { | |
// get a new Blinds device from SinricPro | |
SinricProBlinds &myDrape = SinricPro[DRAPE_ID]; | |
myDrape.onPowerState(onDrapePowerState); | |
myDrape.onRangeValue(onDrapeRangeValue); | |
myDrape.onAdjustRangeValue(onDrapeAdjustRangeValue); | |
SinricProBlinds &myCurtain = SinricPro[CURTAIN_ID]; | |
myCurtain.onPowerState(onCurtainPowerState); | |
myCurtain.onRangeValue(onCurtainRangeValue); | |
myCurtain.onAdjustRangeValue(onCurtainAdjustRangeValue); | |
// setup SinricPro | |
SinricPro.onConnected([](){ Serial.printf("Connected to SinricPro\r\n"); }); | |
SinricPro.onDisconnected([](){ Serial.printf("Disconnected from SinricPro\r\n"); }); | |
SinricPro.begin(APP_KEY, APP_SECRET); | |
} | |
// main setup function | |
void setup() { | |
Serial.begin(BAUD_RATE); Serial.printf("\r\n\r\n"); | |
pinMode(22, OUTPUT); | |
setupWiFi(); | |
setupSinricPro(); | |
} | |
void loop() { | |
SinricPro.handle(); | |
} |
Author
kakopappa
commented
Sep 15, 2021
via email
What’s the device type of: DRAPESs21?
…On Wed, 15 Sep 2021 at 7:54 AM nakamuramitsuhiro ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
[image: Screenshot_20210915_092216_pro sinric]
<https://user-images.githubusercontent.com/26788550/133352400-3fcd5ae8-b4e8-49ce-a8ff-92e9e9f6c24e.jpg>
Good morning!
About schedule,
It seems have a bug at the action input box.
Although I set action with PC, App doesn't reflect action.
Do you still know this occur?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/ec3a1c664e116a8423ce0a6b33ed7a7d#gistcomment-3893378>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZAZZVYMEPQUTGOPRK3VKDUB7VF7ANCNFSM45EMAN6A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
device type is blind
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment