27
27
#endif
28
28
29
29
#include " SinricPro.h"
30
- #include " SinricProFan .h"
30
+ #include " SinricProFanUS .h"
31
31
32
32
#define WIFI_SSID " YOUR-WIFI-SSID"
33
33
#define WIFI_PASS " YOUR-WIFI-PASSWORD"
37
37
#define BAUD_RATE 9600 // Change baudrate to your need
38
38
39
39
// we use a struct to store all states and values for our fan
40
- // powerLevel is used for fan speed (0..100 )
40
+ // fanSpeed (1..3 )
41
41
struct {
42
42
bool powerState = false ;
43
- int powerLevel = 0 ;
43
+ int fanSpeed = 1 ;
44
44
} device_state;
45
45
46
46
bool onPowerState (const String &deviceId, bool &state) {
@@ -49,16 +49,21 @@ bool onPowerState(const String &deviceId, bool &state) {
49
49
return true ; // request handled properly
50
50
}
51
51
52
- bool onPowerLevel (const String &deviceId, int &powerLevel) {
53
- device_state.powerLevel = powerLevel;
54
- Serial.printf (" Fan speed changed to %d\r\n " , device_state.powerLevel );
52
+ // Fan rangeValue is from 1..3
53
+ bool onRangeValue (const String &deviceId, int &rangeValue) {
54
+ device_state.fanSpeed = rangeValue;
55
+ Serial.printf (" Fan speed changed to %d\r\n " , device_state.fanSpeed );
55
56
return true ;
56
57
}
57
58
58
- bool onAdjustPowerLevel (const String &deviceId, int levelDelta) {
59
- device_state.powerLevel += levelDelta;
60
- Serial.printf (" Fan speed changed about %i to %d\r\n " , levelDelta, device_state.powerLevel );
61
- levelDelta = device_state.powerLevel ;
59
+ // Fan rangeValueDelta is from -3..+3
60
+ bool onAdjustRangeValue (const String &deviceId, int rangeValueDelta) {
61
+ device_state.fanSpeed += rangeValueDelta;
62
+ if (device_state.fanSpeed < 1 ) device_state.fanSpeed = 1 ;
63
+ if (device_state.fanSpeed > 3 ) device_state.fanSpeed = 3 ;
64
+ Serial.printf (" Fan speed changed about %i to %d\r\n " , rangeValueDelta, device_state.fanSpeed );
65
+
66
+ rangeValueDelta = device_state.fanSpeed ; // return absolute fan speed
62
67
return true ;
63
68
}
64
69
@@ -74,12 +79,12 @@ void setupWiFi() {
74
79
}
75
80
76
81
void setupSinricPro () {
77
- SinricProFan &myFan = SinricPro[FAN_ID];
82
+ SinricProFanUS &myFan = SinricPro[FAN_ID];
78
83
79
84
// set callback function to device
80
85
myFan.onPowerState (onPowerState);
81
- myFan.onPowerLevel (onPowerLevel );
82
- myFan.onAdjustPowerLevel (onAdjustPowerLevel );
86
+ myFan.onRangeValue (onRangeValue );
87
+ myFan.onAdjustRangeValue (onAdjustRangeValue );
83
88
84
89
// setup SinricPro
85
90
SinricPro.onConnected ([](){ Serial.printf (" Connected to SinricPro\r\n " ); });
0 commit comments