SinricPro Library
README.md
1 
2 # SinricPro (ESP8266 / ESP32 SDK)
3 
4 ## Installation
5 
6 ### VS Code & PlatformIO:
7 1. Install [VS Code](https://code.visualstudio.com/)
8 2. Install [PlatformIO](https://platformio.org/platformio-ide)
9 3. Install **SinricPro** library by using [Library Manager](https://docs.platformio.org/en/latest/librarymanager/)
10 4. Use included [platformio.ini](examples/platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automaticly.
11 
12 ![sinricpro library manager](https://raw.githubusercontent.com/sinricpro/images/master/platformio-install-sinricpro.png)
13 
14 ### ArduinoIDE
15 1. Open Library Manager (*Tools / Manage Libraries*)
16 2. Search for *SinricPro* and click *Install*
17 3. Repeat step 2 for all [dependent libraries](#dependencies)!
18 4. Open example in ArduinoIDE (*File / Examples / SinricPro / ...*)
19 
20 ![ArduinoIDE Library Manager](https://raw.githubusercontent.com/sinricpro/images/master/ArduinoIDE-Library-Manager.png)
21 
22 ---
23 
24 ## Dependencies
25 [ArduinoJson](https://github.com/bblanchon/ArduinoJson) by Benoit Blanchon (minimum Version 6.12.0)
26 [WebSockets](https://github.com/Links2004/arduinoWebSockets) by Markus Sattler (minimum Version 2.2.0)
27 
28 ---
29 
30 ## Full user documentation
31 Please see here for [full user documentation](https://sinricpro.github.io/esp8266-esp32-sdk)
32 
33 ---
34 
35 ## Examples
36 See [examples](https://github.com/sinricpro/esp8266-esp32-sdk/tree/master/examples) on GitHub
37 
38 ---
39 
40 ## Usage
41 ### Include SinricPro-Library (SinricPro.h) and SinricPro-Device-Libraries (eg. SinricProSwitch.h)
42 ```C++
43 #include <SinricPro.h>
44 #include <SinricProSwitch.h>
45 ```
46 
47 ### Define your credentials from SinricPro-Portal (portal.sinric.pro)
48 ```C++
49 #define APP_KEY "YOUR-APP-KEY" // Should look like "de0bxxxx-1x3x-4x3x-ax2x-5dabxxxxxxxx"
50 #define APP_SECRET "YOUR-APP-SECRET" // Should look like "5f36xxxx-x3x7-4x3x-xexe-e86724a9xxxx-4c4axxxx-3x3x-x5xe-x9x3-333d65xxxxxx"
51 #define SWITCH_ID "YOUR-DEVICE-ID" // Should look like "5dc1564130xxxxxxxxxxxxxx"
52 ```
53 
54 ### Define callback routine(s)
55 ```C++
56 bool onPowerState(const String &deviceId, bool &state) {
57  Serial.printf("device %s turned %s\r\n", deviceId.c_str(), state?"on":"off");
58  return true; // indicate that callback handled correctly
59 }
60 ```
61 
62 ### In setup()
63 ```C++
64  // create and add a switch to SinricPro
65  SinricProSwitch& mySwitch = SinricPro[SWITCH_ID];
66  // set callback function
67  mySwitch.onPowerState(onPowerState);
68  // startup SinricPro
69  SinricPro.begin(APP_KEY, APP_SECRET);
70 
71 ```
72 
73 ### In loop()
74 ```C++
75  SinricPro.handle();
76 ```
77 
78 ---
79 ## How to add a device?
80 Syntax is
81 ```C++
82  DeviceType& myDevice = SinricPro[DEVICE_ID];
83 ```
84 Example
85 ```C++
86  SinricProSwitch& mySwitch = SinricPro["YOUR-SWITCH-ID-HERE"];
87 ```
88 *Example 2 (alternatively)*
89 ```C++
90  SinricProSwitch& mySwitch = SinricPro.add<SinricProSwitch>("YOUR-SWITCH-ID-HERE");
91 ```
92 
93 ---
94 ## How to retrieve a device for sending an event?
95 Syntax is
96 ```C++
97  DeviceType& myDevice = SinricPro[DEVICE_ID];
98 ```
99 Example 1
100 ```C++
101  SinricProDoorbell& myDoorbell = SinricPro["YOUR-DOORBELL-ID-HERE"];
102  myDoorbell.sendDoorbellEvent();
103 ```
104 
105 *Example 2 (alternatively)*
106 ```C++
107  SinricPro["YOUR-DOORBELL-ID-HERE"].as<SinricProDoorbell>().sendDoorbellEvent();
108 ```
109 
110 
111 ---
112 
113 # Devices
114 * Switch
115 * Dimmable Switch
116 * Light
117 * TV
118 * Speaker
119 * Thermostat
120 * Fan (US and non US version)
121 * Lock
122 * Doorbell
123 * Temperaturesensor
124 * Motionsensor
125 * Contactsensor
126 * Windows Air Conditioner
127 * Interior Blinds
128 * Garage Door
129 
130 ---
131