Skip to content

Commit 0d6de0f

Browse files
committed
added ZactuatorSomfy
1 parent 4d03aa4 commit 0d6de0f

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

main/User_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ uint8_t wifiProtocol = 0; // default mode, automatic selection
233233
//#define ZboardM5STACK "ZboardM5STACK"
234234
//#define ZradioCC1101 "CC1101" //ESP8266, ESP32
235235
//#define ZactuatorPWM "PWM" //ESP8266, ESP32
236+
//#define ZactuatorSomfy "Somfy" //ESP8266, Arduino, ESP32
236237
//#define ZgatewayRS232 "RS232" //ESP8266, Arduino, ESP32
237238

238239
/*-------------DEFINE YOUR MQTT ADVANCED PARAMETERS BELOW----------------*/

main/ZactuatorSomfy.ino

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "User_config.h"
2+
3+
#ifdef ZactuatorSomfy
4+
5+
# include <EEPROM.h>
6+
# include <EEPROMRollingCodeStorage.h>
7+
# include <SomfyRemote.h>
8+
9+
# ifdef ZradioCC1101
10+
# include <ELECHOUSE_CC1101_SRC_DRV.h>
11+
# endif
12+
13+
void setupSomfy() {
14+
# ifdef ZradioCC1101 //using with CC1101
15+
ELECHOUSE_cc1101.Init();
16+
# endif
17+
pinMode(RF_EMITTER_GPIO, OUTPUT);
18+
digitalWrite(RF_EMITTER_GPIO, LOW);
19+
20+
# if defined(ESP32)
21+
if (!EEPROM.begin(max(4, SOMFY_REMOTE_NUM * 2))) {
22+
Log.error(F("failed to initialise EEPROM" CR));
23+
}
24+
# elif defined(ESP8266)
25+
EEPROM.begin(max(4, SOMFY_REMOTE_NUM * 2));
26+
# endif
27+
28+
Log.trace(F("ZactuatorSomfy setup done " CR));
29+
}
30+
31+
# ifdef jsonReceiving
32+
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
33+
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
34+
# ifdef ZradioCC1101
35+
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY_SOMFY);
36+
# endif
37+
Log.trace(F("MQTTtoSomfy json data analysis" CR));
38+
39+
const int remoteIndex = jsonData["remote"];
40+
if (remoteIndex >= SOMFY_REMOTE_NUM) {
41+
Log.warning(F("ZactuatorSomfy remote does not exist" CR));
42+
return;
43+
}
44+
const String commandData = jsonData["command"];
45+
const Command command = getSomfyCommand(commandData);
46+
47+
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS_START + remoteIndex * 2);
48+
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
49+
somfyRemote.sendCommand(command);
50+
# ifdef ZradioCC1101
51+
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
52+
# endif
53+
}
54+
}
55+
# endif
56+
57+
#endif

main/config_Somfy.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef config_Somfy_h
2+
#define config_Somfy_h
3+
4+
#include <Arduino.h>
5+
#include <ArduinoJson.h>
6+
7+
extern void setupSomfy();
8+
extern void MQTTtoSomfy(char* topicOri, JsonObject& RFdata);
9+
/*----------------------------USER PARAMETERS-----------------------------*/
10+
#define EEPROM_ADDRESS_START 0
11+
#define SOMFY_REMOTE_NUM 1
12+
13+
// Do not change the order of the remotes, because based on the index the rolling codes are stored
14+
const uint32_t somfyRemotes[SOMFY_REMOTE_NUM] = {0x5184c8};
15+
16+
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
17+
#define subjectMQTTtoSomfy "/commands/MQTTtoSomfy"
18+
19+
/*-------------------INTERNAL DEFINITIONS----------------------*/
20+
#define CC1101_FREQUENCY_SOMFY 433.42
21+
22+
#endif

main/main.ino

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ StaticJsonBuffer<JSON_MSG_BUFFER> modulesBuffer;
5757
JsonArray& modules = modulesBuffer.createArray();
5858

5959
// Modules config inclusion
60-
#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight)
60+
#if defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZgatewayPilight) || defined(ZactuatorSomfy)
6161
# include "config_RF.h"
6262
#endif
6363
#ifdef ZgatewayWeatherStation
@@ -132,6 +132,9 @@ JsonArray& modules = modulesBuffer.createArray();
132132
#ifdef ZactuatorPWM
133133
# include "config_PWM.h"
134134
#endif
135+
#ifdef ZactuatorSomfy
136+
# include "config_Somfy.h"
137+
#endif
135138
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK)
136139
# include "config_M5.h"
137140
#endif
@@ -690,6 +693,10 @@ void setup() {
690693
setupPWM();
691694
modules.add(ZactuatorPWM);
692695
#endif
696+
#ifdef ZactuatorSomfy
697+
setupSomfy();
698+
modules.add(ZactuatorSomfy);
699+
#endif
693700
#ifdef ZsensorDS1820
694701
setupZsensorDS1820();
695702
modules.add(ZsensorDS1820);
@@ -1520,6 +1527,9 @@ void receivingMQTT(char* topicOri, char* datacallback) {
15201527
# ifdef ZactuatorONOFF // outside the jsonpublishing macro due to the fact that we need to use simplepublishing with HA discovery
15211528
MQTTtoONOFF(topicOri, jsondata);
15221529
# endif
1530+
# ifdef ZactuatorSomfy
1531+
MQTTtoSomfy(topicOri, jsondata);
1532+
# endif
15231533
# ifdef ZgatewayRS232
15241534
MQTTtoRS232(topicOri, jsondata);
15251535
# endif

platformio.ini

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ extra_configs =
3535
;default_envs = esp32dev-rf
3636
;default_envs = esp32dev-pilight
3737
;default_envs = esp32dev-pilight-cc1101
38+
;default_envs = esp32dev-somfy-cc1101
39+
;default_envs = esp32dev-pilight-somfy-cc1101
3840
;default_envs = esp32dev-weatherstation
3941
;default_envs = esp32dev-ir
4042
;default_envs = esp32dev-ble
@@ -49,6 +51,7 @@ extra_configs =
4951
;default_envs = ttgo-lora32-v1
5052
;default_envs = nodemcuv2-rf
5153
;default_envs = nodemcuv2-rf-cc1101
54+
;default_envs = nodemcuv2-somfy-cc1101
5255
;default_envs = rf-wifi-gateway
5356
;default_envs = nodemcuv2-rf2
5457
;default_envs = nodemcuv2-rf2-cc1101
@@ -109,6 +112,7 @@ m5stickcp = https://github.com/m5stack/M5StickC-Plus.git
109112
m5stack = M5Stack@0.3.0
110113
smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.3.5
111114
stl = https://github.com/mike-matera/ArduinoSTL.git#7411816
115+
somfy_remote=https://github.com/Legion2/Somfy_Remote_Lib#v0.2.0
112116

113117
[env]
114118
framework = arduino
@@ -262,6 +266,34 @@ build_flags =
262266
'-DZradioCC1101="CC1101"'
263267
'-DGateway_Name="OpenMQTTGateway_ESP32_Pilight-CC1101"'
264268

269+
[env:esp32dev-somfy-cc1101]
270+
platform = ${com.esp32_platform}
271+
board = esp32dev
272+
lib_deps =
273+
${com-esp.lib_deps}
274+
${libraries.somfy_remote}
275+
${libraries.smartrc-cc1101-driver-lib}
276+
build_flags =
277+
${com-esp.build_flags}
278+
'-DZactuatorSomfy="Somfy"'
279+
'-DZradioCC1101="CC1101"'
280+
'-DGateway_Name="OpenMQTTGateway_ESP32_Somfy-CC1101"'
281+
282+
[env:esp32dev-pilight-somfy-cc1101]
283+
platform = ${com.esp32_platform}
284+
board = esp32dev
285+
lib_deps =
286+
${com-esp.lib_deps}
287+
${libraries.esppilight}
288+
${libraries.somfy_remote}
289+
${libraries.smartrc-cc1101-driver-lib}
290+
build_flags =
291+
${com-esp.build_flags}
292+
'-DZgatewayPilight="Pilight"'
293+
'-DZactuatorSomfy="Somfy"'
294+
'-DZradioCC1101="CC1101"'
295+
'-DGateway_Name="OpenMQTTGateway_ESP32_Pilight-Somfy-CC1101"'
296+
265297
[env:esp32dev-weatherstation]
266298
platform = ${com.esp32_platform}
267299
board = esp32dev
@@ -612,6 +644,21 @@ build_flags =
612644
'-DGateway_Name="OpenMQTTGateway_ESP8266_RF-CC1101"'
613645
board_build.flash_mode = dout
614646

647+
[env:nodemcuv2-somfy-cc1101]
648+
platform = ${com.esp8266_platform}
649+
board = nodemcuv2
650+
lib_deps =
651+
${com-esp.lib_deps}
652+
${libraries.somfy_remote}
653+
${libraries.smartrc-cc1101-driver-lib}
654+
${libraries.esp8266_mdns}
655+
build_flags =
656+
${com-esp.build_flags}
657+
'-DZactuatorSomfy="Somfy"'
658+
'-DZradioCC1101="CC1101"'
659+
'-DGateway_Name="OpenMQTTGateway_ESP8266_Somfy-CC1101"'
660+
board_build.flash_mode = dout
661+
615662
[env:manual-wifi-test]
616663
platform = ${com.esp8266_platform}
617664
board = nodemcuv2

0 commit comments

Comments
 (0)