├── 3d mount ├── README.md ├── configuration.yaml └── mqttblinds.ino /3d mount: -------------------------------------------------------------------------------- 1 | http://www.thingiverse.com/thing:759658 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project will detail the setup of standard 2 inch window blinds that are controlled by an esp8266 and a futaba s3003 servo. 2 | -------------------------------------------------------------------------------- /configuration.yaml: -------------------------------------------------------------------------------- 1 | light: 2 | - platform: mqtt 3 | name: "Window Bottom Center" 4 | state_topic: "blind/bc/state" 5 | command_topic: "blind/bc/command" 6 | brightness_state_topic: "blind/bc/state" 7 | brightness_command_topic: "blind/bc/level" 8 | brightness_scale: 100 9 | qos: 0 10 | payload_on: "ON" 11 | payload_off: "OFF" 12 | optimistic: false 13 | retain: true 14 | 15 | - platform: mqtt 16 | name: "Window Bottom Right" 17 | state_topic: "blind/br/state" 18 | command_topic: "blind/br/command" 19 | brightness_state_topic: "blind/br/state" 20 | brightness_command_topic: "blind/br/level" 21 | brightness_scale: 100 22 | qos: 0 23 | payload_on: "ON" 24 | payload_off: "OFF" 25 | optimistic: false 26 | retain: true 27 | -------------------------------------------------------------------------------- /mqttblinds.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | 18 | /************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/ 19 | #define wifi_ssid "" //enter your WIFI SSID 20 | #define wifi_password "" //enter your WIFI Password 21 | 22 | #define mqtt_server "" // Enter your MQTT server adderss or IP. I use my DuckDNS adddress (yourname.duckdns.org) in this field 23 | #define mqtt_user "" //enter your MQTT username 24 | #define mqtt_password "" //enter your password 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | WiFiClient espClient; 34 | PubSubClient client(espClient); 35 | 36 | Servo myservo; 37 | 38 | int val; 39 | int itsatrap = 0; 40 | 41 | 42 | void setup() { 43 | Serial.begin(115200); 44 | 45 | setup_wifi(); 46 | 47 | client.setServer(mqtt_server, 1883); //CHANGE PORT HERE IF NEEDED 48 | client.setCallback(callback); 49 | 50 | } 51 | 52 | 53 | void setup_wifi() { 54 | 55 | delay(10); 56 | Serial.println(); 57 | Serial.print("Connecting to "); 58 | Serial.println(wifi_ssid); 59 | 60 | WiFi.mode(WIFI_STA); 61 | WiFi.begin(wifi_ssid, wifi_password); 62 | 63 | while (WiFi.status() != WL_CONNECTED) { 64 | delay(500); 65 | Serial.print("."); 66 | } 67 | 68 | Serial.println(""); 69 | Serial.println("WiFi connected"); 70 | Serial.println("IP address: "); 71 | Serial.println(WiFi.localIP()); 72 | } 73 | 74 | void callback(char* topic, byte* payload, unsigned int length) { 75 | char p[length + 1]; 76 | memcpy(p, payload, length); 77 | p[length] = NULL; 78 | String message(p); 79 | String mytopic(topic); 80 | if (itsatrap == 0 && mytopic == "" && message.equals("ON")){ 81 | myservo.attach(D4); 82 | delay(500); 83 | myservo.write(90); 84 | client.publish("", "ON"); 85 | delay(1000); 86 | myservo.detach(); 87 | } 88 | else if (mytopic == "" && message.equalsIgnoreCase("OFF")){ 89 | myservo.attach(D4); 90 | delay(500); 91 | myservo.write(0); 92 | client.publish("", "OFF"); 93 | delay(1000); 94 | myservo.detach(); 95 | } 96 | else if (mytopic == ""){ 97 | myservo.attach(D4); 98 | delay(500); 99 | val = message.toInt(); //converts command to integer to be used for positional arrangement 100 | val = map (val, 0, 99, 0, 180); 101 | myservo.write(val); 102 | client.publish("", "ON"); 103 | delay(3000); 104 | myservo.detach(); 105 | itsatrap = 1; 106 | } 107 | else{ 108 | itsatrap = 0; 109 | } 110 | 111 | } 112 | 113 | 114 | 115 | void loop() { 116 | 117 | if (!client.connected()) { 118 | reconnect(); 119 | } 120 | client.loop(); 121 | } 122 | 123 | 124 | void reconnect() { 125 | // Loop until we're reconnected 126 | while (!client.connected()) { 127 | Serial.print("Attempting MQTT connection..."); 128 | // Attempt to connect 129 | if (client.connect("ESPBlindstl", mqtt_user, mqtt_password)) { 130 | Serial.println("connected"); 131 | 132 | client.subscribe(""); 133 | client.subscribe(""); 134 | client.publish("", "OFF"); 135 | } else { 136 | Serial.print("failed, rc="); 137 | Serial.print(client.state()); 138 | Serial.println(" try again in 5 seconds"); 139 | // Wait 5 seconds before retrying 140 | delay(5000); 141 | } 142 | } 143 | } 144 | 145 | 146 | 147 | --------------------------------------------------------------------------------