Skip to content

Commit a7575b2

Browse files
authored
added ZactuatorSomfy (#816)
* added ZactuatorSomfy * added Somfy RTS docs
1 parent 4d03aa4 commit a7575b2

File tree

8 files changed

+230
-1
lines changed

8 files changed

+230
-1
lines changed

docs/setitup/actuators.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@
1515

1616
Vcc pin of the board and the Module to a 5V supply source
1717
Ground pins of the board and the Module to the ground of the supply source.
18+
19+
## Somfy RTS
20+
For this actuator a 433.42 MHz RF transmitter is required.
21+
The standard 433.92 MHz transmitter don't work.
22+
The CC1101 Transceiver supports both 433.42 MHz and 433.92 MHz and can be used with the Somfy RTS actor.
23+
The wiring of the hardware is described in the [RF gateway](rf).

docs/setitup/rf.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Connect the Emitter and Receiver to a 5V (**3.3V** for CC1101) supply source, an
2727
|ESP8266|D2/**D3**/D1/D8|**RX**/D2|D5|**3V3**|D7|D6|D8|GND
2828
|ESP32|**27**/26|12|D18|**3V3**|D23|D19|D5|GND
2929

30+
To use the CC1101 module, `ZradioCC1101` must be uncomment in the `User_config.h` or added to the `build_flags`.
3031
More information about the [CC1101 wiring](https://github.com/LSatan/SmartRC-CC1101-Driver-Lib#wiring).
3132

3233

docs/use/actuators.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,42 @@ After this calibration, if you set the `r` channel to 0.0, it will be remapped t
7474
Also, the gamma curve for this channel will be set to 2.5.
7575
This means that input values are raised to the power 2.5 internally.
7676
This can be used to improve the linearity of inputs.
77+
78+
## Somfy RTS
79+
This actuator allows to control Somfy RTS devices.
80+
81+
### Setup
82+
Before the module can be used, virtual Somfy RTS remotes must be created.
83+
This is done in `config_Somfy.h`.
84+
85+
`SOMFY_REMOTE_NUM` must be set to the number of virtual Somfy RTS remotes you want to have.
86+
Then create for each of the virtual Somfy RTS remotes a unique 3-byte code and add them to `somfyRemotes`.
87+
After a remote is setup, the order and codes should not be changed, else the setup process for all remotes have to be repeated.
88+
Adding new codes at the end of the list is no problem.
89+
Example of three virtual Somfy RTS remote codes:
90+
```C
91+
const uint32_t somfyRemotes[SOMFY_REMOTE_NUM] = {0x5184c8, 0xba24d0, 0xb77753};
92+
```
93+
94+
Next the virtual Somfy RTS remotes must be paired with the Somfy RTS devices you want to control.
95+
The next section describes how the PROG command/button of the virtual remote can be used.
96+
Use the manual of the device you want to control for instructions on how to pair the virtual remote with the device.
97+
98+
### Commands
99+
Commands must be send to the `commands/MQTTtoSomfy` subtopic.
100+
Only json messages are supported.
101+
The json message must contain two properties:
102+
* remote: the index of the remote which is used to send the command (index start at zero)
103+
* command: the command which should be send with the remote as string, see [table of command names](https://github.com/Legion2/Somfy_Remote_Lib#available-commands).
104+
105+
::: tip NOTE
106+
The middle button on physical Somfy RTS Remote controls is called "My".
107+
:::
108+
109+
Send PROG command with remote 0:
110+
111+
`mosquitto_pub -t home/OpenMQTTGateway_Somfy/commands/MQTTtoSomfy -m '{"remote":0,"command":"Prog"}'`
112+
113+
Send Up command with remote 1:
114+
115+
`mosquitto_pub -t home/OpenMQTTGateway_Somfy/commands/MQTTtoSomfy -m '{"remote":1,"command":"Up"}'`

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: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
OpenMQTTGateway - ESP8266 or Arduino program for home automation
3+
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
4+
Send and receiving command by MQTT
5+
6+
This actor enables to:
7+
- receive MQTT data from a topic and send Somfy RTS remote control signals corresponding to the received MQTT data
8+
9+
Copyright (C) 2020 Leon Kiefer
10+
11+
This file is part of OpenMQTTGateway.
12+
13+
OpenMQTTGateway is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 3 of the License, or
16+
(at your option) any later version.
17+
OpenMQTTGateway is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
GNU General Public License for more details.
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
#include "User_config.h"
25+
26+
#ifdef ZactuatorSomfy
27+
28+
# include <EEPROM.h>
29+
# include <EEPROMRollingCodeStorage.h>
30+
# include <SomfyRemote.h>
31+
32+
# ifdef ZradioCC1101
33+
# include <ELECHOUSE_CC1101_SRC_DRV.h>
34+
# endif
35+
36+
void setupSomfy() {
37+
# ifdef ZradioCC1101 //using with CC1101
38+
ELECHOUSE_cc1101.Init();
39+
# endif
40+
pinMode(RF_EMITTER_GPIO, OUTPUT);
41+
digitalWrite(RF_EMITTER_GPIO, LOW);
42+
43+
# if defined(ESP32)
44+
if (!EEPROM.begin(max(4, SOMFY_REMOTE_NUM * 2))) {
45+
Log.error(F("failed to initialise EEPROM" CR));
46+
}
47+
# elif defined(ESP8266)
48+
EEPROM.begin(max(4, SOMFY_REMOTE_NUM * 2));
49+
# endif
50+
51+
Log.trace(F("ZactuatorSomfy setup done " CR));
52+
}
53+
54+
# ifdef jsonReceiving
55+
void MQTTtoSomfy(char* topicOri, JsonObject& jsonData) {
56+
if (cmpToMainTopic(topicOri, subjectMQTTtoSomfy)) {
57+
# ifdef ZradioCC1101
58+
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY_SOMFY);
59+
# endif
60+
Log.trace(F("MQTTtoSomfy json data analysis" CR));
61+
62+
const int remoteIndex = jsonData["remote"];
63+
if (remoteIndex >= SOMFY_REMOTE_NUM) {
64+
Log.warning(F("ZactuatorSomfy remote does not exist" CR));
65+
return;
66+
}
67+
const String commandData = jsonData["command"];
68+
const Command command = getSomfyCommand(commandData);
69+
70+
EEPROMRollingCodeStorage rollingCodeStorage(EEPROM_ADDRESS_START + remoteIndex * 2);
71+
SomfyRemote somfyRemote(RF_EMITTER_GPIO, somfyRemotes[remoteIndex], &rollingCodeStorage);
72+
somfyRemote.sendCommand(command);
73+
# ifdef ZradioCC1101
74+
ELECHOUSE_cc1101.SetRx(CC1101_FREQUENCY); // set Receive on
75+
# endif
76+
}
77+
}
78+
# endif
79+
80+
#endif

main/config_Somfy.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
OpenMQTTGateway - ESP8266 or Arduino program for home automation
3+
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
4+
Send and receiving command by MQTT
5+
6+
This actor enables to:
7+
- receive MQTT data from a topic and send Somfy RTS remote control signals corresponding to the received MQTT data
8+
9+
Copyright (C) 2020 Leon Kiefer
10+
11+
This file is part of OpenMQTTGateway.
12+
13+
OpenMQTTGateway is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 3 of the License, or
16+
(at your option) any later version.
17+
OpenMQTTGateway is distributed in the hope that it will be useful,
18+
but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
GNU General Public License for more details.
21+
You should have received a copy of the GNU General Public License
22+
along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*/
24+
#ifndef config_Somfy_h
25+
#define config_Somfy_h
26+
27+
#include <Arduino.h>
28+
#include <ArduinoJson.h>
29+
30+
extern void setupSomfy();
31+
extern void MQTTtoSomfy(char* topicOri, JsonObject& RFdata);
32+
/*----------------------------USER PARAMETERS-----------------------------*/
33+
#define EEPROM_ADDRESS_START 0
34+
#define SOMFY_REMOTE_NUM 1
35+
36+
// Do not change the order of the remotes, because based on the index the rolling codes are stored
37+
const uint32_t somfyRemotes[SOMFY_REMOTE_NUM] = {0x5184c8};
38+
39+
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
40+
#define subjectMQTTtoSomfy "/commands/MQTTtoSomfy"
41+
42+
/*-------------------INTERNAL DEFINITIONS----------------------*/
43+
#define CC1101_FREQUENCY_SOMFY 433.42
44+
45+
#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=Somfy_Remote_Lib@0.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)