Hi Guys,
So i’ve been busy trying to control my Somfy blinds with Blynk. I finnaly got it working and wanted to share my code with u guys.
Hardware:
Wemos D1 Mini (esp8266 based)
433mHz transmitter, (replaced the crystal for a 433.4mHz)
Connected to GPIO 2 (D4)
#define EMITTER_GPIO 2
#define EEPROM_ADDRESS 0
#define REMOTE 0x5184c8
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <EEPROM.h>
#include <EEPROMRollingCodeStorage.h>
#include <SomfyRemote.h>
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS);
SomfyRemote somfyRemote(EMITTER_GPIO, REMOTE, &rollingCodeStorage);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "cD40wZ1wcxfl_7jZ3t9Y63e2h62XVCm8";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Pannenkoek";
char pass[] = "Metstroop#12";
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
int pinData = param.asInt();
if (pinData == 1)
{
const Command command = getSomfyCommand("1");
somfyRemote.sendCommand(command);
}
if (pinData == 2)
{
const Command command = getSomfyCommand("2");
somfyRemote.sendCommand(command);
}
if (pinData == 4)
{
const Command command = getSomfyCommand("4");
somfyRemote.sendCommand(command);
}
}
void setup()
{
// Debug console
Serial.begin(115200);
somfyRemote.setup();
#if defined(ESP32)
if (!EEPROM.begin(4)) {
Serial.println("failed to initialise EEPROM");
delay(1000);
}
#elif defined(ESP8266)
EEPROM.begin(4);
#endif
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop()
{
Blynk.run();
}