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.7k 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 Bram81

    Hi,

    Maybe this is a stupid question, but I've only got my first Arduino Uno in two days ago and I'm a complete mysensors newbie... Already have been working with Domoticz on Rpi for over a year now. Recently I've build a water irrigation system for my garden, controlled by a relay which can be switched through Domoticz using a GPIO. Now I would like to add some ground moisture sensors, using a Arduino and the domoticz Gateway to Mysensors to water the garden when the soil gets too dry.
    I've uploaded the serialgateway sketch to an Arduino Uno and I also have a sketch to read the output of the sensor using the Analog output. Now my question is, how can a add this sketch to the arduino without deleting the gateway sketch?

    If I understand correctly, uploading the gateway sketch is obviously the first step, after that you'll have to upload specific sketches for various sensors to be able to add a 'node' ?

    Can anyone put me on the right track? Thanks in advance!

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

    @Bram81 domoticz with mysensors is awesome. However, the gateway is one arduino with nrf that is connected to the rpi and notify the controller what is happening. The sensor nodes are also arduinos with nrf and they are running the sensor sketch. Hope this clarified thing a bit...

    B 1 Reply Last reply
    0
    • Moshe LivneM Moshe Livne

      @Bram81 domoticz with mysensors is awesome. However, the gateway is one arduino with nrf that is connected to the rpi and notify the controller what is happening. The sensor nodes are also arduinos with nrf and they are running the sensor sketch. Hope this clarified thing a bit...

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

      @Moshe-Livne Thanks for your reply! So if I understand correctly there is one Arduino with the serial sketch on it that acts as the gateway and I have to use another arduino to add sensors to. Will a second Arduino connected to the Rpi through USB and running my sensor sketch be picked up by the gateway automatically?

      1 Reply Last reply
      0
      • scalzS Offline
        scalzS Offline
        scalz
        Hardware Contributor
        wrote on last edited by
        #4

        Yes you can do that. For example, you can have a gateway and a node connected on your computer so you can serial debug each. But of course, one Gateway (gateway sketch) for n nodes (nodes sketch).

        B 1 Reply Last reply
        0
        • scalzS scalz

          Yes you can do that. For example, you can have a gateway and a node connected on your computer so you can serial debug each. But of course, one Gateway (gateway sketch) for n nodes (nodes sketch).

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

          @scalz Ok, that is what I was hoping... Right now I have one Arduino Uno conncted through USB to my Rpi running the gateway sketch on port ACM0

          Another Uno which has a soil moisture sensor connected to it and running a sketch is also connected through USB to ACM1 port. Still I can't see any new devices in Domoticz...

          Would this be the way to go or am I doing something verry wrong..?

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

            I think you have to add the gateway as hardware in domoticz. Then when the gateway recieve info from the node/sensor its transferred into domoticz. If you have connected the node/sensor through the GPIO i think you need to create some sort of virtual device and program this in domoticz, but then the gateway are not used. The best way is Domoticz -> Gateway -> Sensors.

            The MySensors use the radio to talk to the gateway... i dont know how to do that with a wire/usb.

            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
              #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
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          14

                                          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