Sonoff and Vera



  • I'm completely new to MySensors, and I don't understand how it works 100%. I wanted to connect sonoff relays to my Vera, but I don't know how the connection works: it says on the website that the vera needs a serial or ethernet gateway, but why would I need that when the relay already has WiFi? Do I need to create multiple devices and configure them as a separate gateway for every relay? Thanks for your help.


  • Admin

    You would have to run the MySensors firmware on your Sonoff (acting as gateway) presenting and controlling the relays in the device.

    I haven't tried this myself (haven't got any sonoffs) but in theory it should work.



  • Which one? The only firmware for the esp8266 that I can find is for gateway only, but the sonoff also has an onboard relay... Do I have to modify the code or something to make it work?


  • Admin

    You have to find out which ESP-pins that controls the relays and modify the gateway sketch using the Relay example as a hint.

    https://github.com/mysensors/MySensors/blob/development/examples/RelayActuator/RelayActuator.ino



  • @hek Sorry for being annoying, but I don't know anything about MySensors. I know that the relay is controlled by GPIO 12 and is active high. Do I flash the esp8266, the RelayActuator.ino or do I merge the two together? Thanks so much for your help.


  • Admin

    You will have to merge them.



  • @hek Thank you so much! I've been able to write my code for the relay. The problem is that it doesn't compile because it finds errors in the mysensor.h library. How can I fix this? Did I do something wrong?

    Arduino: 1.8.0 (Mac OS X), Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None"
    
    Build options changed, rebuilding all
    In file included from /Users/Federico/Documents/Arduino/libraries/MySensors/MySensors.h:204:0,
                     from /Users/Federico/Desktop/GatewayESP8266/GatewayESP8266.ino:44:
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:45:24: error: 'WiFiServer' does not name a type
     #define EthernetServer WiFiServer
                            ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:62:1: note: in expansion of macro 'EthernetServer'
     EthernetServer _ethernetServer(_ethernetGatewayPort);
     ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:46:24: error: 'WiFiClient' does not name a type
     #define EthernetClient WiFiClient
                            ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:69:8: note: in expansion of macro 'EthernetClient'
     static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS];
            ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportInit()':
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:106:2: error: 'WiFi' was not declared in this scope
      WiFi.mode (WIFI_STA);
      ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:106:13: error: 'WIFI_STA' was not declared in this scope
      WiFi.mode (WIFI_STA);
                 ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:114:26: error: 'WL_CONNECTED' was not declared in this scope
      while (WiFi.status() != WL_CONNECTED) {
                              ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:162:2: error: '_ethernetServer' was not declared in this scope
      _ethernetServer.begin();
      ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportSend(MyMessage&)':
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:212:37: error: 'clients' was not declared in this scope
      for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
                                         ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:36:32: note: in definition of macro 'ARRAY_SIZE'
     #define ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
                                    ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool _readFromClient(uint8_t)':
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:228:9: error: 'clients' was not declared in this scope
      while (clients[i].connected() && clients[i].available()) {
             ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp: In function 'bool gatewayTransportAvailable()':
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:347:37: error: 'clients' was not declared in this scope
      for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
                                         ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:36:32: note: in definition of macro 'ARRAY_SIZE'
     #define ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
                                    ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:354:8: error: '_ethernetServer' was not declared in this scope
        if (_ethernetServer.hasClient()) {
            ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:367:26: error: '_ethernetServer' was not declared in this scope
      if (allSlotsOccupied && _ethernetServer.hasClient()) {
                              ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:46:24: error: 'WiFiClient' was not declared in this scope
     #define EthernetClient WiFiClient
                            ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:370:3: note: in expansion of macro 'EthernetClient'
       EthernetClient c = _ethernetServer.available();
       ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:370:18: error: expected ';' before 'c'
       EthernetClient c = _ethernetServer.available();
                      ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:371:3: error: 'c' was not declared in this scope
       c.stop();
       ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:374:37: error: 'clients' was not declared in this scope
      for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
                                         ^
    /Users/Federico/Documents/Arduino/libraries/MySensors/core/MyGatewayTransportEthernet.cpp:36:32: note: in definition of macro 'ARRAY_SIZE'
     #define ARRAY_SIZE(x)  (sizeof(x)/sizeof(x[0]))
                                    ^
    exit status 1
    Error compiling for board Generic ESP8266 Module.
    
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    


  • @nicomedia I stumbled on this doing a google search. Just wondering if you are still trying to get your Sonoff's working with your Vera controller? If so, I have written a blog post on the subject. It uses a different firmware called ESP Easy and an HTTP Switch plugin on the Vera rather than MySensors. but it works rather well for me. Here is the link to the blog post:
    https://dan.bemowski.info/2017/07/04/using-a-sonoff-with-espeasy-and-vera/
    I use this in conjunction with some MySensors wall switches that I built.
    https://dan.bemowski.info/2017/06/11/my-start-into-open-source-hardware/


Log in to reply
 

382
Online

6.7k
Users

7.6k
Topics

80.4k
Posts

Suggested Topics

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.