Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. Domoticz
  4. How to add a sensor to the serial gateway

How to add a sensor to the serial gateway

Scheduled Pinned Locked Moved Domoticz
25 Posts 6 Posters 25.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bram81
    wrote on last edited by
    #7

    Thanks for your post. Aha I thought that working without radio was the difference between serial and ethernet gateways. I've ordered some nRF24L01+. modules, probably getting them in a couple of days.

    So I'll have to connect one of those to the gateway and one to the arduino Uno holding my moisture sensors?

    Moshe LivneM 1 Reply Last reply
    0
    • B Bram81

      Thanks for your post. Aha I thought that working without radio was the difference between serial and ethernet gateways. I've ordered some nRF24L01+. modules, probably getting them in a couple of days.

      So I'll have to connect one of those to the gateway and one to the arduino Uno holding my moisture sensors?

      Moshe LivneM Offline
      Moshe LivneM Offline
      Moshe Livne
      Hero Member
      wrote on last edited by
      #8

      @Bram81 yes.... no way around it. the controller talks with the gateway through the USB (Serial)
      or Ethernet (Ethernet gateway) but the gateway communicates with the sensor nodes through the nrf modules.

      1 Reply Last reply
      0
      • hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by
        #9

        @Bram81

        You try using the serial gateway in this branch:
        https://github.com/mysensors/Arduino/tree/gateway-refactoring

        It allows sensors to be attached to the gateway itself. Note that it is still WIP (and I'm unsure if all controllers support this).

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bram81
          wrote on last edited by
          #10

          Thanks everybody! Got the serial gateway working and it's being picked up by domoticz. Now another Arduino Uno is holding a moisture sensor, it's communicating with the gateway, but Domoticz sees the sensor as a lamp so it's not logging the sensor output. The sensor is a YL-38. Is there a way to fix this or is this type simply not supported by Domoticz?

          1 Reply Last reply
          0
          • sundberg84S Offline
            sundberg84S Offline
            sundberg84
            Hardware Contributor
            wrote on last edited by
            #11

            Hi!

            Is the sensor presented correctly - what does the domoticz log say when you power up the sensor?
            Do you see anything in the domoticz and or gateway log when sending temp-values?

            Controller: Proxmox VM - Home Assistant
            MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
            MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
            RFLink GW - Arduino Mega + RFLink Shield, 433mhz

            B 1 Reply Last reply
            0
            • sundberg84S sundberg84

              Hi!

              Is the sensor presented correctly - what does the domoticz log say when you power up the sensor?
              Do you see anything in the domoticz and or gateway log when sending temp-values?

              B Offline
              B Offline
              Bram81
              wrote on last edited by
              #12

              @sundberg84 Hey!

              Domoticz log shows:
              015-07-01 15:44:03.331 MySensors: Gateway Ready...
              2015-07-01 15:44:28.776 Hardware Monitor: Fetching data (System sensors)
              2015-07-01 15:44:41.187 (Gateway) Lighting 2 (Vochtigheid border)
              2015-07-01 15:44:45.357 (Gateway) Lighting 2 (Vochtigheid border)
              2015-07-01 15:44:58.920 Hardware Monitor: Fetching data (System sensors)
              2015-07-01 15:45:28.298 MySensors: Node: 3, Sketch Name: Soil Moisture Sensor
              2015-07-01 15:45:28.302 MySensors: Node: 3, Sketch Version: 1.0

              Hooking up the gateway and node to a laptop to use the serial monitor shows data being send from the sensor and received by the gateway.

              After plugging in the gateway to my pi running domoticz there was a new hardware detected right away, but only not as a sensor but as a lightning2 type lamp switch which I've named 'vochtigheid border'. The log of this 'switch itself shows:
              2015-07-01 15:44:45 On
              2015-07-01 15:44:41 Off
              2015-07-01 15:41:02 On
              2015-07-01 14:49:43 Off
              2015-07-01 14:31:56 On
              2015-07-01 14:31:56 Off

              Does this make any sense to you...?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bram81
                wrote on last edited by
                #13

                Oh and I'm using this sketc btw : http://www.mysensors.org/build/moisture

                1 Reply Last reply
                0
                • sundberg84S Offline
                  sundberg84S Offline
                  sundberg84
                  Hardware Contributor
                  wrote on last edited by sundberg84
                  #14

                  Hi @Bram81
                  Looks good so far... i was just about to suggest the domoticz forum, but then i saw this: link text and i guess its you :)

                  In the link (Rain & Moisture scetch) it looks like the GW.present: gw.present(CHILD_ID, S_MOTION);
                  Does this mean its presented as a motion sensor? @hek ?

                  Anyhow - in the Domoticz code there is not any code for S_MOTION so you have to request this.
                  MySensorsBase.cpp

                  I dont know what happens if you try to present is a humidity sensor? Both humidity and soil is presented as % ??

                  Br

                  Controller: Proxmox VM - Home Assistant
                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                  B 1 Reply Last reply
                  0
                  • sundberg84S sundberg84

                    Hi @Bram81
                    Looks good so far... i was just about to suggest the domoticz forum, but then i saw this: link text and i guess its you :)

                    In the link (Rain & Moisture scetch) it looks like the GW.present: gw.present(CHILD_ID, S_MOTION);
                    Does this mean its presented as a motion sensor? @hek ?

                    Anyhow - in the Domoticz code there is not any code for S_MOTION so you have to request this.
                    MySensorsBase.cpp

                    I dont know what happens if you try to present is a humidity sensor? Both humidity and soil is presented as % ??

                    Br

                    B Offline
                    B Offline
                    Bram81
                    wrote on last edited by
                    #15

                    Hi@sundberg84 Yes, that's me.. ;-) I saw that file too, but being still a newbie in Mysensors, Arduino and sketches I didn't really know how to use it. Do I have to put in my libraries folder and add a line #include <filename> in the gateway sketch..?

                    Right now the sensor is automatically seen as a certain device, within Domoticz there is no way to present it otherwise right?

                    1 Reply Last reply
                    0
                    • sundberg84S Offline
                      sundberg84S Offline
                      sundberg84
                      Hardware Contributor
                      wrote on last edited by sundberg84
                      #16

                      If you mean MySensorsBase.cpp - no thats the domoticz scourscode and you dont use that in the sensor/gateway.
                      Looking closer at the code shows also your sensors sends V_TRIPPED to domoticz, and thats why you get on/off.

                      I dont know it this works, but i would try to change:
                      MyMessage msg(CHILD_ID, V_TRIPPED);
                      to
                      MyMessage msg(CHILD_ID, V_HUM);

                      and
                      gw.present(CHILD_ID, S_MOTION);
                      to
                      gw.present(CHILD_ID, S_HUM);

                      and upload the scetch to the Moisture sensor again...
                      It will present the sensor in domoticz as a Humidity sensor but as I said i hope both Moisture and Humidity presents its value from 0-100 %

                      Br

                      Controller: Proxmox VM - Home Assistant
                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        Bram81
                        wrote on last edited by
                        #17

                        Hey, thanks for your help. The sensor presents itself as a Humidity sensor and shows a value of 1% even after adding water to the ground nothing changes, so it seems it's not being updated correctly.

                        Last week when I was just playing around for the first time with the arduino and sensor used this simple sketch:

                        int sensorPin = A0; // select the input pin for the potentiometer
                        int sensorValue = 0; // variable to store the value coming from the sensor

                        void setup() {
                        // declare the ledPin as an OUTPUT:
                        Serial.begin(9600);
                        }

                        void loop() {
                        // read the value from the sensor:
                        sensorValue = analogRead(sensorPin);
                        delay(1000);
                        Serial.print("sensor = " );
                        Serial.println(sensorValue);
                        }

                        Using the analog output on the sensor and analog0 on the arduino. The values are presented in number between 1-1200 (aprox.)

                        Even readings in just a number would be fine for me / can be easily transered to a % I guess, where a value of aprox 300 is liquid water and 1050 is the value read when the sensor is in the open air and not sticked in the soil.

                        Can you think of alike types of sensors with values presented in that range?

                        1 Reply Last reply
                        0
                        • sundberg84S Offline
                          sundberg84S Offline
                          sundberg84
                          Hardware Contributor
                          wrote on last edited by sundberg84
                          #18

                          Hi @Bram81

                          Yes - the analog is 0 - 1023 and many use it to measure battery %.
                          This can be converted to % pretty much by dividing it by 10 i think

                          int sensorValue = analogRead(sensorPin);
                          Serial.println(sensorValue);
                          sensorValue  = sensorValue / 10;
                          

                          You can do much more with upper and lower limits... its just a matter of math and code.

                          Edit:
                          This is used in the battery when we want figures from 1.9 (VMIN)-3.3V (VMAX)... maybe it can help you somhow:

                          int Pcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);```

                          Controller: Proxmox VM - Home Assistant
                          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                          1 Reply Last reply
                          0
                          • sundberg84S Offline
                            sundberg84S Offline
                            sundberg84
                            Hardware Contributor
                            wrote on last edited by
                            #19

                            Doing some fast math here: Vbat = your analog read value (say 500 as example), VMIN = 300 VMAX = 1023 gives us
                            500 - 300 / 1023-300 = 200/ 723 = 0,27 = 27%

                            Controller: Proxmox VM - Home Assistant
                            MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                            MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                            RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                            B 1 Reply Last reply
                            0
                            • sundberg84S sundberg84

                              Doing some fast math here: Vbat = your analog read value (say 500 as example), VMIN = 300 VMAX = 1023 gives us
                              500 - 300 / 1023-300 = 200/ 723 = 0,27 = 27%

                              B Offline
                              B Offline
                              Bram81
                              wrote on last edited by
                              #20

                              @sundberg84 Hi, I've been trying to modify the sketch
                              screenshot sketch analog.png
                              But it gives me errors I cant resolve... Got to a point where the node send back info to the gateway:

                              683
                              send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
                              682
                              send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
                              683
                              send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0
                              682
                              send: 3-3-0-0 s=0,c=1,t=1,pt=2,l=2,st=ok:0

                              Also Domoticz was receiving info, log showed :+1:
                              2015-07-02 10:31:24.898 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.914 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.929 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.944 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.959 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.975 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:24.990 (Gateway) Temp + Humidity (TempHum)
                              2015-07-02 10:31:25.005 (Gateway) Temp + Humidity (TempHum)

                              But still the humidity switch was showing either 0% or 1%.
                              I guess that is propably because the values must be transfered into % in the sketch, but I am kind of stuck...

                              1 Reply Last reply
                              0
                              • sundberg84S Offline
                                sundberg84S Offline
                                sundberg84
                                Hardware Contributor
                                wrote on last edited by sundberg84
                                #21

                                @Bram81
                                I would try (not at home and cant try):

                                int Analog_Input_Soil_Sensor= A0;
                                int Analog_Input_Soil_Sensor = 0;

                                as you wrote before, and not #define interrupt analog_input_soil_sensor -2

                                Also you get only 0 and 1 because this is what you send to the gateway: gw.send(Msg.set(soilva... 0?1:0)
                                Either you have to define what 0 and 1 is (say dry = 0 moist = 1) or if you want to send it as % use another gw.send code.

                                Controller: Proxmox VM - Home Assistant
                                MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                1 Reply Last reply
                                0
                                • sundberg84S Offline
                                  sundberg84S Offline
                                  sundberg84
                                  Hardware Contributor
                                  wrote on last edited by sundberg84
                                  #22

                                  Here is an example of someone build a soil sensor using the light_sensor
                                  http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
                                  If you remove the battery code this could be used if you connect to analog pin (Se code below)

                                  #include <SPI.h>
                                  #include <MySensor.h>
                                  
                                  #define CHILD_ID_LIGHT 0
                                  #define LIGHT_SENSOR_ANALOG_PIN 1
                                  
                                  MySensor gw;
                                  MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                                  int lastLightLevel;
                                  
                                  void setup()
                                  {
                                  gw.begin();
                                  
                                  // Send the sketch version information to the gateway and Controller
                                  gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
                                  
                                  // Register all sensors to gateway (they will be created as child devices)
                                  gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                                  }
                                  
                                  void loop()
                                  {
                                  int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
                                  Serial.println(lightLevel);
                                  if (lightLevel != lastLightLevel) {
                                  gw.send(msg.set(lightLevel));
                                  lastLightLevel = lightLevel;
                                  }
                                  }
                                  
                                  

                                  if you want lightlevel in % with a Min and a Max then:

                                  #include <SPI.h>
                                  #include <MySensor.h>
                                  
                                  #define CHILD_ID_LIGHT 0
                                  #define LIGHT_SENSOR_ANALOG_PIN 1
                                  #define MIN 300  // Liquid
                                  #define MAX 1023 // Air
                                  
                                  MySensor gw;
                                  MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                                  int lastLightLevel;
                                  
                                  void setup()
                                  {
                                  gw.begin();
                                  
                                  // Send the sketch version information to the gateway and Controller
                                  gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
                                  
                                  // Register all sensors to gateway (they will be created as child devices)
                                  gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                                  }
                                  
                                  void loop()
                                  {
                                  int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.);
                                  Serial.println(lightLevel);
                                  if (lightLevel != lastLightLevel) {
                                  gw.send(msg.set(lightLevel));
                                  lastLightLevel = lightLevel;
                                  }
                                  }
                                  
                                  

                                  I have read some more...
                                  About the digital pin and use (as you mentioned at first... )
                                  It looks like there is a switch/nob on the hardware you can turn.
                                  This will set the trigger point between dry and moist and send 1 or 0.
                                  I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
                                  I dont know how to program or wire this though...

                                  Best of luck :) Hope i didnt just complicate things...

                                  Controller: Proxmox VM - Home Assistant
                                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                  B 1 Reply Last reply
                                  0
                                  • sundberg84S sundberg84

                                    Here is an example of someone build a soil sensor using the light_sensor
                                    http://forum.mysensors.org/topic/1492/soil-moisture-analog-input-question
                                    If you remove the battery code this could be used if you connect to analog pin (Se code below)

                                    #include <SPI.h>
                                    #include <MySensor.h>
                                    
                                    #define CHILD_ID_LIGHT 0
                                    #define LIGHT_SENSOR_ANALOG_PIN 1
                                    
                                    MySensor gw;
                                    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                                    int lastLightLevel;
                                    
                                    void setup()
                                    {
                                    gw.begin();
                                    
                                    // Send the sketch version information to the gateway and Controller
                                    gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
                                    
                                    // Register all sensors to gateway (they will be created as child devices)
                                    gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                                    }
                                    
                                    void loop()
                                    {
                                    int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
                                    Serial.println(lightLevel);
                                    if (lightLevel != lastLightLevel) {
                                    gw.send(msg.set(lightLevel));
                                    lastLightLevel = lightLevel;
                                    }
                                    }
                                    
                                    

                                    if you want lightlevel in % with a Min and a Max then:

                                    #include <SPI.h>
                                    #include <MySensor.h>
                                    
                                    #define CHILD_ID_LIGHT 0
                                    #define LIGHT_SENSOR_ANALOG_PIN 1
                                    #define MIN 300  // Liquid
                                    #define MAX 1023 // Air
                                    
                                    MySensor gw;
                                    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                                    int lastLightLevel;
                                    
                                    void setup()
                                    {
                                    gw.begin();
                                    
                                    // Send the sketch version information to the gateway and Controller
                                    gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");
                                    
                                    // Register all sensors to gateway (they will be created as child devices)
                                    gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                                    }
                                    
                                    void loop()
                                    {
                                    int lightLevel = static_cast<int>(((analogRead(LIGHT_SENSOR_ANALOG_PIN)-MIN)/(MAX-MIN))*100.);
                                    Serial.println(lightLevel);
                                    if (lightLevel != lastLightLevel) {
                                    gw.send(msg.set(lightLevel));
                                    lastLightLevel = lightLevel;
                                    }
                                    }
                                    
                                    

                                    I have read some more...
                                    About the digital pin and use (as you mentioned at first... )
                                    It looks like there is a switch/nob on the hardware you can turn.
                                    This will set the trigger point between dry and moist and send 1 or 0.
                                    I think thats why the scetches was using S_Motion... either its dry (untriggered) or wet (triggered).
                                    I dont know how to program or wire this though...

                                    Best of luck :) Hope i didnt just complicate things...

                                    B Offline
                                    B Offline
                                    Bram81
                                    wrote on last edited by
                                    #23

                                    @sundberg84 Hey! Thank you verry much for your help and suggestions!!
                                    I actually got it working combining your sketch witch my simple one resulting in this:

                                    #include <SPI.h>
                                    #include <MySensor.h>

                                    #define CHILD_ID_LIGHT 0
                                    #define LIGHT_SENSOR_ANALOG_PIN 1
                                    #define MIN 300 // Liquid
                                    #define MAX 1023 // Air

                                    int sensorPin = A0; // select the input pin for the potentiometer
                                    int sensorValue = 0; // variable to store the value coming from the sensor

                                    MySensor gw;
                                    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
                                    int lastLightLevel;

                                    void setup(){

                                    Serial.begin(9600);

                                    gw.begin();

                                    // Send the sketch version information to the gateway and Controller
                                    gw.sendSketchInfo("Soil_Moist_Sensor_grb", "1.15");

                                    // Register all sensors to gateway (they will be created as child devices)
                                    gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
                                    }

                                    void loop(){
                                    // read the value from the sensor:
                                    sensorValue = analogRead(sensorPin);
                                    delay(1000);
                                    Serial.print("sensor = " );
                                    Serial.println(sensorValue);
                                    gw.send(msg.set(sensorValue));
                                    }

                                    The sensor shows up in Domoticz as a light sensor meassuring in lux, but the numbers do match the output of the sensor.

                                    Another thing is that after about 15 min the gateway started functioning. Seems like a problem that I had last week returned...
                                    Loading the board with the pingpongtest shows that suddenly my radio chip is recognized as NRF24L01 instead of the + version, although the label on te chips shows NRF24L01+
                                    Changing radios doesn't help, I'm completely in the dark... maybe just shitty radios..?

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      mortommy
                                      wrote on last edited by
                                      #24

                                      Hi @hek , the link above it's broken. Is it yet available anywhere?
                                      Thank you.

                                      1 Reply Last reply
                                      0
                                      • hekH Offline
                                        hekH Offline
                                        hek
                                        Admin
                                        wrote on last edited by
                                        #25

                                        It has been merged now. Available here:
                                        https://github.com/mysensors/Arduino

                                        1 Reply Last reply
                                        0
                                        Reply
                                        • Reply as topic
                                        Log in to reply
                                        • Oldest to Newest
                                        • Newest to Oldest
                                        • Most Votes


                                        10

                                        Online

                                        11.7k

                                        Users

                                        11.2k

                                        Topics

                                        113.1k

                                        Posts


                                        Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                        • Login

                                        • Don't have an account? Register

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • MySensors
                                        • OpenHardware.io
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular