Some questions on how gateway works



  • Hi all

    I have resurrected my old Mysensors Ethernet gateway but I can't get Home Assistant to connect to it. I tried using yaml but I get an error saying that it can't be configured this way, so I'm thinking I'll set the gateway up as a MQTT Gateway. I first have a couple questions I need to ask.

    I used to have the Gateway integrated into my Vera 3 controller. To attach sensors I used to press a button in the GUI of Vera to start the process. How is this done with the MQTT Gateway? If I need to add a button to the Gateway to start this process, I'll need to add this as it doesn't have this yet.

    And do I need to write the sketches different when I'm creating sensors so that they work with the MQTT Gateway?

    Once I clear this up I'll be able to get building again!

    Looking forward to hearing back from someone!

    Cheers!



  • I think I'm going to move on from the Ethernet route, coz no matter what I can't get it to connect to the network. I have an ESP12F that I found in my box of stuff that I'll wire a radio to and set it up as my gateway.



  • @homer You do have to put in the MQTT parameters, such as, MQTT broker IP. The logic of your sensors and how you send the data remains the same.

    In Home Assistant you have to have the MQTT integration and the MySensors integration.

    1. Set up your MQTT broker
    2. install the MQTT integration
    3. install the MySensors integration (I always forget which goes where, MySensorsIn and MySensorsOut)
    4. create and configure your MySensors MQTT gateway
    5. add the MQTT code to your sensors

    Once you turn on your sensors, they should appear in Home Assistant as devices.



  • Thanks for your reply!

    I have had heaps of help from Chat GPT and I believe every thing is talking to each other, but I don't see any sensors in HA.

    Here is my sketch for the Gateway:

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    #define MY_MQTT_KEEPALIVE 60
    
    // Use a lower baud rate for ESP8266 serial prints
    #define MY_BAUD_RATE 9600
    
    // Radio type (enable one)
    #define MY_RADIO_RF24
    // #define MY_RADIO_RFM69
    // #define MY_RADIO_RFM95
    
    // nRF24 radio pins
    #define MY_RF24_CE_PIN 4
    #define MY_RF24_CS_PIN 15
    
    // Gateway type
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP8266
    
    // MQTT topics
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // MQTT client ID
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Support controller ID allocation
    #define MY_CONTROLLER_ID_ALLOC_SUPPORT
    
    // MQTT broker authentication (optional)
    #define MY_MQTT_USER "homeassistant"
    #define MY_MQTT_PASSWORD "oN3Oe0eile6iVaivaiphooChieNg5wei0kapa9rohJ8au0Teethah6thahsieP7A"
    
    // WiFi credentials
    #define MY_WIFI_SSID "Ext"
    #define MY_WIFI_PASSWORD "lynettekoster"
    
    // Hostname for DHCP (optional)
    // #define MY_HOSTNAME "mqtt-sensor-gateway"
    
    // Static IP configuration (optional)
    #define MY_IP_ADDRESS 192,168,0,100
    #define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // MQTT broker IP address or URL
    #define MY_CONTROLLER_IP_ADDRESS 192,168,0,77
    // #define MY_CONTROLLER_URL_ADDRESS "test.mosquitto.org"
    
    // MQTT broker port
    #define MY_PORT 1883
    
    // Inclusion mode (optional)
    // #define MY_INCLUSION_MODE_FEATURE
    // #define MY_INCLUSION_BUTTON_FEATURE
    // #define MY_INCLUSION_MODE_DURATION 60
    // #define MY_INCLUSION_MODE_BUTTON_PIN D1
    
    // LED blinking period (optional)
    // #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // LED pins (optional)
    // #define MY_DEFAULT_ERR_LED_PIN 16
    // #define MY_DEFAULT_RX_LED_PIN 16
    // #define MY_DEFAULT_TX_LED_PIN 16
    
    #include <ESP8266WiFi.h>
    #include <MySensors.h>
    
    void setup()
    {
      // Setup locally attached sensors here (if any)
    }
    
    void presentation()
    {
      // Present gateway node to controller
      sendSketchInfo("MQTT Gateway", "1.0");
    }
    
    void loop()
    {
      // Send locally attached sensors data here (if any)
    }
    
    

    My Sensor I made is using a RF-Nano, and this is the sketch:

    #define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_RF24_CE_PIN 10
    #define MY_RF24_CS_PIN 9
    #include <MySensors.h>
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <DHT.h>
    
    // MySensors definitions
    #define CHILD_ID_DS18B20_TEMP 0
    #define CHILD_ID_DHT_TEMP 1
    #define CHILD_ID_DHT_HUM 2
    
    #define ONE_WIRE_BUS 3        // DS18B20 data pin connected to Arduino pin 3
    #define DHTPIN 4              // DHT22 data pin connected to Arduino pin 4
    #define DHTTYPE DHT22         // DHT22 sensor type
    
    // Setup NRF24 radio (default CE=9, CSN=10 for RF-Nano)
    #define MY_RADIO_NRF24
    #define MY_RF24_CE_PIN 10
    #define MY_RF24_CS_PIN 9
    
    // Sleep interval in milliseconds
    #define SEND_INTERVAL 30000  // 30 seconds
    
    // Initialize sensors
    OneWire oneWire(ONE_WIRE_BUS);
    DallasTemperature ds18b20(&oneWire);
    DHT dht(DHTPIN, DHTTYPE);
    
    // Child sensor objects
    MyMessage msgDs18b20Temp(CHILD_ID_DS18B20_TEMP, V_TEMP);
    MyMessage msgDhtTemp(CHILD_ID_DHT_TEMP, V_TEMP);
    MyMessage msgDhtHum(CHILD_ID_DHT_HUM, V_HUM);
    
    unsigned long lastSendTime = 0;
    
    void setup() {
      // Initialize sensors
      ds18b20.begin();
      dht.begin();
    }
    
    void presentation() {
      // Present sensors to gateway
      present(CHILD_ID_DS18B20_TEMP, S_TEMP);
      present(CHILD_ID_DHT_TEMP, S_TEMP);
      present(CHILD_ID_DHT_HUM, S_HUM);
    }
    
    void loop() {
      unsigned long now = millis();
      if (now - lastSendTime > SEND_INTERVAL) {
        lastSendTime = now;
    
        // Read DS18B20 temperature
        ds18b20.requestTemperatures();
        float tempDS = ds18b20.getTempCByIndex(0);
    
        // Read DHT22 temp and humidity
        float tempDHT = dht.readTemperature();
        float humDHT = dht.readHumidity();
    
        // Check if reads are valid before sending
        if (tempDS != DEVICE_DISCONNECTED_C) {
          send(msgDs18b20Temp.set(tempDS, 1));
        } else {
          // Optional: send some error value or skip
        }
    
        if (!isnan(tempDHT)) {
          send(msgDhtTemp.set(tempDHT, 1));
        }
    
        if (!isnan(humDHT)) {
          send(msgDhtHum.set(humDHT, 1));
        }
      }
    
      // Sleep to save power (optional, comment out if not needed)
      // sleep(SEND_INTERVAL / 1000);
    }
    
    

    I downloaded and installed MQTT Explorer to see what messages are there. This is what shows in the app:
    mqtt.png

    I setup Mysensors using the GUI. I am running Mosquitto broker for MQTT. The only thing I see here is my Ring cameras as they are setup using MQTT. In the Mysensors integration all there is is the MQTT gateway that I created. I should have 3 new devices, but they aren't there. I do recall reading somewhere that there was something that needed to happen for a device to show up, but I don't recall what that way as at the time I read it, it was still very far from where I was up to at the time. I guess I will start doing some more searching.



  • Screenshot 2025-08-10 200908.png

    Still no topics. I only have the one sensor and I haven't actually attached any sensors to the arduino as I figured the sketch itself would send enough info to create the devices, but I am starting to wonder if the reason they aren;t there is coz of this....



  • Maybe is a silly point, but the node presents itself to the gateway, and afterwards you should see your node in your controller. The node ( in myController V1 that is my choice) I see the node's registration status as New. I need to edit the node properties and change the node status to Registered. After that the sensors show up.

    there's also an inclusion mode in the gateway if this is not possible with Vera:

    // Enable inclusion mode
    //#define MY_INCLUSION_MODE_FEATURE

    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    //#define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN D1

    https://www.mysensors.org/build/advanced_gateway



  • let me also add that if the serial protocol is possible with an ethernet gateway, I would prefer that, w/o messing with MQTT.


  • Mod

    @fsgraz you might want to use the tcp option for the ethernet gateway then. See https://www.mysensors.org/about/overview and https://www.mysensors.org/build/select_gateway



  • Thanks for the replies!!

    I have some progress, but I still don't see any sensors in Home Assistant.

    Screenshot 2025-08-11 111200.png

    As you can see. topics are being reported, but nothing related to them show up in the HA MQTT integration or the Mysensors integration.I have no idea where to go from here.



  • I gave up on this and instead went the TCP Gateway, and now I have sensors in HA!



  • @Homer That's really good to hear!



  • Thanks mate, I am very pleased! 😄



  • @mfalkvidd thanks.

    I am happily running 6 esp32 WiFi gateways with nRF24L01+, but with the mysensors serial protocol, not mqtt. I don't see any value on MQTT for a local system based entirely on mysensors like mine, but I might be wrong and don't see the potential.

    I have a couple of them working as bridges, like between BLE sensors and mysensors, or Alexa an mysensors, meteo RSS Feed etc.



  • @mfalkvidd I got what you mean.
    Yes, I am using the tcp connection using the mySensors serial API, not the USB<>UART serial interface 😉

    I am running a gateway with the nRF24 at 1Mpbs for the fast & furious sensors (mainly energy meters); another at 250kbps for the battery supplied nodes (temp/hum and door sensors); another one at 1Mbps dedicated to the actuators / mission critical.
    60 nodes running

    Another on is a BLE<>Mysensors bridge between the Mopeka Tank Pro (2) and the TPMS (4)
    Another one is a fauxmo<>Mysensors bridge.

    A few esp32 based displays (round oled, 3.5", 7")

    🙂


Log in to reply
 

Suggested Topics

  • 1
  • 8
  • 5
  • 3
  • 2
  • 1

44
Online

11.6k
Users

11.2k
Topics

112.9k
Posts