Control Somfy blinds with Blynk

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();
}

Hi I’m totally new to this, how do you get your code to link to Blynk?

Thanks

Maybe I need to rephrase, I have compiled the code in Arduino but how do I link this code to Blynk to use the app? Do I have to merge it with a modified Blynk template?

you can post your whole sketch so we can take a look at it.

It’s already “linked to Blynk”, but is written for the old version of Blynk, not the new version.
For it to work with the new version you’ll need to create a template and add a device based on that template. Once you’ve done this you will get a template ID and device name, plus an Auth token. These need to be added to the sketch.

You’ll also need to set-up datastream on virtual pin 1 with suitable minimum and maximum values (1-4 judging by the sketch) and add a slider widget attached to V1.

Personally, I think the sketch looks a bit dodgy, as it has options to deal with slider value of 1, 2 & 4, but not 3.
It also uses EEPROM to store data, and the EEPROM memory of devices like the D1 Mini has a limited life (around 100,000 read/write operations on average).
EEPROM has been superseded by SPIFFS, which has since been superseded by LittleFS.
I don’t know if the SomfyRemote library has been updated to work with SPIFFS or LittleFS.

Pete.

Thanks, hoped it would be a simple copy and paste to get control of my blinds without having to learn too much!