Fauxmo/Wemo Emulation HA Integration

Good day, i implemented this project (http://www.instructables.com/id/How-to-Connect-Your-Somfy-Remote-to-Alexa-With-an-/) which basically controls a remote with an ESP8266 via Alexa and was wondering if anyone can offer any guidance as to how to integrate into Home Assistance.

Another gentleman created an MQTT version of the sketch (https://github.com/kolcun/awning-control), but i struggled with adapting to my requirement as the server details etc are not straight forward. Seems he’s using an Alexa server as broker. I have Mosquito set up in my Pi and would like to integrate that way. (Im new to HA, so still learning the basics)

Thank you in advance.

All, solved the problem and have a working sketch if anyone interested

Hi, I not have blinds in my place, but i could adapt your code for another project, can you please share the esp8266 code and the HA config.yaml file ??
Thank you very much

hi this is the arduino:

#include <PubSubClient.h>
#include <ESP8266WiFi.h>

#define OFF D1
#define ON D2

const char* ssid = “WifiUsername”;
const char* password = “WifiPassword”;

char* espTopic = “ha/esp”;
char* controlTopic = “ha/somfy2”;
char* stateTopic = “ha/somfy2/state”;
char* server = “mqtt ip”;
char* mqttMessage;

WiFiClient wifiClient;
PubSubClient pubSubClient(wifiClient);

void setup() {
Serial.begin(115200);
delay(10);

pinMode(OFF, OUTPUT);
pinMode(ON, OUTPUT);
digitalWrite(OFF, HIGH);
digitalWrite(ON, HIGH);

connectToWifi();

pubSubClient.setServer(server, 1883);
pubSubClient.setCallback(mqttCallback);

if (!pubSubClient.connected()) {
reconnect();
}
}

void reconnect() {
while (!pubSubClient.connected()) {
if (pubSubClient.connect(“client id”, “mqtt username”, “mqtt password”)) {
Serial.println(“Connected to MQTT broker”);
pubSubClient.publish(espTopic, “somfy control online”);
if (!pubSubClient.subscribe(controlTopic, 1)) {
Serial.println(“MQTT: unable to subscribe”);
}
} else {
Serial.print(“failed, rc=”);
Serial.print(pubSubClient.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}

}

void loop() {

if (!pubSubClient.connected()) {
reconnect();
}
pubSubClient.loop();
}

void connectToWifi() {
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println(“WiFi connected”);
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

}

void mqttCallback(char* topic, byte* payload, unsigned int length) {
Serial.print(F(“MQTT Message Arrived [”));
Serial.print(topic);
Serial.print(F("] "));
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();

mqttMessage = (char*) payload;

if (strcmp(topic, controlTopic) == 0) {
if (strncmp(mqttMessage, “OFF”, length) == 0) {
Serial.println(“Somfy Close”);
closeSomfy();
} else if (strncmp(mqttMessage, “ON”, length) == 0) {
Serial.println(“Somfy Open”);
openSomfy();
}
}

}

void openSomfy() {
pubSubClient.publish(stateTopic, “ON”);
digitalWrite(ON, LOW);
delay(250);
digitalWrite(ON, HIGH);
}

void closeSomfy() {
pubSubClient.publish(stateTopic, “OFF”);
digitalWrite(OFF, LOW);
delay(250);
digitalWrite(OFF, HIGH);

}

And this is the configuration.yaml entry:

Switch:

  • platform: mqtt
    name: “Curtains”
    command_topic: “ha/somfy2”
    state_topic: “ha/somfy2/state”
    qos: 1
    payload_on: “ON”
    payload_off: “OFF”
    retain: true

Any way to add the STOP command to this?

Am curious why you’ve defined both D1 and D2 for fauxmo device. Are you controlling 2 Somfy units?
Thanks, Liz

Liz, i’m afraid i cant help much. I just copied the code from a hackster post if I recall correctly.
d1 for up and d2 for down.

Hi Jaun,

Thanks for your speedy reply. It’s OK - I figured it out. In my case, D1 & D2 control a light and a fan - so 2 separate devices. Since the word “curtains” was there, I assume there was a left and right motor.

Best - Liz