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. Development
  3. MySensors - Get Temperature value from another node through the Gateway

MySensors - Get Temperature value from another node through the Gateway

Scheduled Pinned Locked Moved Development
36 Posts 7 Posters 5.6k Views 6 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.
  • rejoe2R rejoe2

    @ben999 You are welcome.
    For "indirect" communication you may use the V_VARx-method already mentionned. This requires the controller to have the requested info stored at the right place (eg. FHEM would store V_VAR1 of Child 101 in a reading named "value1101" of the respective device).
    Then just use the EnergyMeterPulse-sketch as example how to ask info from nodes side to be send from controller while not sleeping.
    That should do the trick.

    Just one remark: Having a display and a sleeping node doesn't fit to well together imo :grinning:

    EDIT: To make things more clear: the V_VARx has to be stored in the values of the requesting node, so if the display is attached to node 6, your controller has to provide the values as reading on node 6...

    ben999B Offline
    ben999B Offline
    ben999
    wrote on last edited by ben999
    #21

    @rejoe2 Dude!!! It worked! Awesome :D Node-to-node is now understood and tested :)

    Now i need (for my personal benefit) to get my node to fetch data from controller
    FHEM seems to be some type of controller software like Openhab and so many others... ? Next move is to discover where and how data is stored within openhab...

    Once again @rejoe2 thank you very much for passing on your knowledge

    Just one remark: Having a display and a sleeping node doesn't fit to well together imo 😀

    I just wanted to make sure you would not lead me to any other way :D as i wanted to understand both ways of sharing data between nodes
    Thank you so much for that :+1:

    rejoe2R 1 Reply Last reply
    1
    • ben999B ben999

      @rejoe2 Dude!!! It worked! Awesome :D Node-to-node is now understood and tested :)

      Now i need (for my personal benefit) to get my node to fetch data from controller
      FHEM seems to be some type of controller software like Openhab and so many others... ? Next move is to discover where and how data is stored within openhab...

      Once again @rejoe2 thank you very much for passing on your knowledge

      Just one remark: Having a display and a sleeping node doesn't fit to well together imo 😀

      I just wanted to make sure you would not lead me to any other way :D as i wanted to understand both ways of sharing data between nodes
      Thank you so much for that :+1:

      rejoe2R Offline
      rejoe2R Offline
      rejoe2
      wrote on last edited by
      #22

      @ben999 said in MySensors - Get Temperature value from another node through the Gateway:
      Thx for reporting about getting this to work as expected!

      FHEM seems to be some type of controller software like Openhab and so many others... ?

      FHEM is - as mentionned in my signature - also a controller software. It's written in perl (which is very special) and a very flexible solution allowing a broad spectrum of hardware to be integrated, but unfortunately not very famous outside Germany (as most posts in the forum are in german). But questions in english are also answered, see fhem.de for more details, if you're interested.

      Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

      1 Reply Last reply
      1
      • J Offline
        J Offline
        Joe13
        wrote on last edited by Joe13
        #23

        @rejoe2 i got to understand quite some things from all what you have shared and thanks for that. just a bit more confusion left.
        so i have node 1N/child id 1C to send the temp value to the LCD node 4N / child id 4C, so is the below correct.

        send(1N.setDestination(4).setSensor(4C).set(temperature, 1));
        

        And if node 1N / child id 1C is to send the temp value to GW(DOMOTICZ), is the below correct and how can node 4/child 4C (LCD) retreive this value from GW.

        MyMessage pcMsg(1C,V_VAR1);
        send(pcMsg.set(TEMP from this sensor))
        
        rejoe2R 1 Reply Last reply
        0
        • J Joe13

          @rejoe2 i got to understand quite some things from all what you have shared and thanks for that. just a bit more confusion left.
          so i have node 1N/child id 1C to send the temp value to the LCD node 4N / child id 4C, so is the below correct.

          send(1N.setDestination(4).setSensor(4C).set(temperature, 1));
          

          And if node 1N / child id 1C is to send the temp value to GW(DOMOTICZ), is the below correct and how can node 4/child 4C (LCD) retreive this value from GW.

          MyMessage pcMsg(1C,V_VAR1);
          send(pcMsg.set(TEMP from this sensor))
          
          rejoe2R Offline
          rejoe2R Offline
          rejoe2
          wrote on last edited by rejoe2
          #24

          @joe13 Your naming convention ist a bit confusing.
          In general, for sending info to the controller, you can use the "short" send() command in the form they are included in the examples from the Build section.
          The additional parts between the points (setDestination() and setSensor()) just change the default values (setDestination usually is "0" for the GW; setSensor() is typically defined in the ...Msg() in each sketches header section (in your example: pcMsg()). V_VAR1 btw seems not to be the right type for this kind of message (Temp).
          You may have a look at the "Temperature" sketch: This is a good official example how to use the setSensor() variable dynamically.

          Hope this helps to light out the remaining questions, it's quite hard for me to explain all these things. I myself learned about these mechanisms by studiing the examples and doing some (...) tests, but I'm not an educated programmer, so I am not able to lead you to the right keywords for theoretical backgroud.

          Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

          J 1 Reply Last reply
          1
          • rejoe2R rejoe2

            @joe13 Your naming convention ist a bit confusing.
            In general, for sending info to the controller, you can use the "short" send() command in the form they are included in the examples from the Build section.
            The additional parts between the points (setDestination() and setSensor()) just change the default values (setDestination usually is "0" for the GW; setSensor() is typically defined in the ...Msg() in each sketches header section (in your example: pcMsg()). V_VAR1 btw seems not to be the right type for this kind of message (Temp).
            You may have a look at the "Temperature" sketch: This is a good official example how to use the setSensor() variable dynamically.

            Hope this helps to light out the remaining questions, it's quite hard for me to explain all these things. I myself learned about these mechanisms by studiing the examples and doing some (...) tests, but I'm not an educated programmer, so I am not able to lead you to the right keywords for theoretical backgroud.

            J Offline
            J Offline
            Joe13
            wrote on last edited by
            #25

            @rejoe2 Completely understand and thanks for your time on all this. Probably i am not getting something very basic here.
            this is the code that i am using to send the data to GW. i juse put in a constant num to send for VAR 1

            MyMessage pcMsg(0,V_VAR1);
            send(pcMsg.set(50));
            

            and in my LCD node, which doesnt have any physical sensor, trying to get that VAR1 value like below

            request(0, V_VAR1);
            
            void receive(const MyMessage &message) {
              // We only expect one type of message from controller. But we better check anyway.
              if (message.type==V_VAR1) {
            
                
                 // Write some debug info
                 Serial.print("Incoming change for sensor:");
                 Serial.print(message.sensor);
                 Serial.print(", New status: ");
                 Serial.println(message.getLong());
               } 
            }
            

            but the Serial monitor always shows 0 and just trying to figure out why. I am quite sure that it is probably a really minor change that needs to be done

            Requested temp from gw VAR1223055 TSF:MSG:READ,0-0-1,s=0,c=2,t=24,pt=0,l=0,sg=0:
            Incoming change for sensor:0, New status: 0
            
            rejoe2R K 2 Replies Last reply
            0
            • J Joe13

              @rejoe2 Completely understand and thanks for your time on all this. Probably i am not getting something very basic here.
              this is the code that i am using to send the data to GW. i juse put in a constant num to send for VAR 1

              MyMessage pcMsg(0,V_VAR1);
              send(pcMsg.set(50));
              

              and in my LCD node, which doesnt have any physical sensor, trying to get that VAR1 value like below

              request(0, V_VAR1);
              
              void receive(const MyMessage &message) {
                // We only expect one type of message from controller. But we better check anyway.
                if (message.type==V_VAR1) {
              
                  
                   // Write some debug info
                   Serial.print("Incoming change for sensor:");
                   Serial.print(message.sensor);
                   Serial.print(", New status: ");
                   Serial.println(message.getLong());
                 } 
              }
              

              but the Serial monitor always shows 0 and just trying to figure out why. I am quite sure that it is probably a really minor change that needs to be done

              Requested temp from gw VAR1223055 TSF:MSG:READ,0-0-1,s=0,c=2,t=24,pt=0,l=0,sg=0:
              Incoming change for sensor:0, New status: 0
              
              rejoe2R Offline
              rejoe2R Offline
              rejoe2
              wrote on last edited by
              #26

              @joe13 As you are doing the data transfer through the controller: How did you transfer the info from Node A, V_VAR1@Child X to Node B, V_VAR1@Child Y? If you are issuing request(), you are asking the controller to send the later info.
              How to manage that is not a MySensors question - it's controller specific. @FHEM, one would use typically a "notify"-function to copy incoming info from one node to the other.

              Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

              1 Reply Last reply
              1
              • J Joe13

                @rejoe2 Completely understand and thanks for your time on all this. Probably i am not getting something very basic here.
                this is the code that i am using to send the data to GW. i juse put in a constant num to send for VAR 1

                MyMessage pcMsg(0,V_VAR1);
                send(pcMsg.set(50));
                

                and in my LCD node, which doesnt have any physical sensor, trying to get that VAR1 value like below

                request(0, V_VAR1);
                
                void receive(const MyMessage &message) {
                  // We only expect one type of message from controller. But we better check anyway.
                  if (message.type==V_VAR1) {
                
                    
                     // Write some debug info
                     Serial.print("Incoming change for sensor:");
                     Serial.print(message.sensor);
                     Serial.print(", New status: ");
                     Serial.println(message.getLong());
                   } 
                }
                

                but the Serial monitor always shows 0 and just trying to figure out why. I am quite sure that it is probably a really minor change that needs to be done

                Requested temp from gw VAR1223055 TSF:MSG:READ,0-0-1,s=0,c=2,t=24,pt=0,l=0,sg=0:
                Incoming change for sensor:0, New status: 0
                
                K Offline
                K Offline
                kimot
                wrote on last edited by
                #27

                @joe13
                First, you send to controller command to store V_VAR1 for node X ( your temp node )
                Secondly you ask controller for V_VAR1 of node Z ( different node ! - your LCD)
                And there is nothing stored, so it returns 0.
                You must write some scripts in controller to write correct value for correct V_VAR.

                For example if temperature from node X changed ( or periodically every minute etc )
                copy this temperature to V_VAR1 of your LCD node Z.
                How you "copy" this, depends on controller sw ability.
                Then, if LCD node asks controller for V_VAR1, it obtain what you want.

                1 Reply Last reply
                1
                • K Offline
                  K Offline
                  kimot
                  wrote on last edited by kimot
                  #28

                  Here are types, which can be requested from Domoticz for example:

                  else if (message_type == MT_Req)
                  	{
                  		//Request a variable
                  		std::string tmpstr;
                  		switch (sub_type)
                  		{
                  		case V_STATUS:
                  		case V_PERCENTAGE:
                  		case V_RGB:
                  		case V_RGBW:
                  			if (GetSwitchValue(node_id, child_sensor_id, sub_type, tmpstr))
                  				SendNodeCommand(node_id, child_sensor_id, message_type, sub_type, tmpstr);
                  			break;
                  		case V_VAR1:
                  		case V_VAR2:
                  		case V_VAR3:
                  		case V_VAR4:
                  		case V_VAR5:
                  			//send back a previous stored custom variable
                  			tmpstr = "";
                  			GetVar(node_id, child_sensor_id, sub_type, tmpstr);
                  			//SendNodeSetCommand(node_id, child_sensor_id, message_type, (_eSetType)sub_type, tmpstr, true, 1000);
                  			SendNodeCommand(node_id, child_sensor_id, message_type, sub_type, tmpstr);
                  			break;
                  		case V_TEXT:
                  			{
                  				//Get Text sensor value from the database
                  				bool bExits = false;
                  				tmpstr = GetTextSensorText(node_id, child_sensor_id, bExits);
                  				SendNodeCommand(node_id, child_sensor_id, message_type, sub_type, tmpstr);
                  			}
                  			break;
                  		default:
                  			while (1==0);
                  			break;
                  		}
                  		while (1==0);
                  	}
                  	else {
                  		//Unhandled message type
                  		while (1==0);
                  	}
                  
                  

                  There is V_TEXT too.
                  I do not find like handle V_VAR1 in Domoticz, but if create TEXT node with V_TEXT, then I am able store temperature from different node into this V_TEXT of another node, which can be requested by MySensors.

                  1 Reply Last reply
                  1
                  • J Offline
                    J Offline
                    Joe13
                    wrote on last edited by Joe13
                    #29

                    Thanks for all the info. I have not yet started scripting in the Controller. But what you guys have mentioned above makes sense, that passing value from Node A to VAR1 needs to be transferred to Node B VAR1 through the controller. Let me play around with all the info provided above. Probably looks like i would have to do node-node. But my understanding has improved now.
                    @kimot is that request code that you mentioned to be part of the MySensors code in the node or is that a Domoticz input?

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      Joe13
                      wrote on last edited by Joe13
                      #30

                      As an update.
                      Finally after wrapping my head around the topic and knowing that you cant just send a value from one node in a VAR1 and expect it to just retain that value and get it in another node, i used the node - node communication and it worked!!!.

                      so my send sketch is

                      send(pcMsg.setDestination(1).setSensor(101).set(temperature,1));
                      

                      and receive sketch is

                      void loop() 
                      {
                         request(0, V_VAR1);
                       }
                      
                      void receive(const MyMessage &message) {
                      
                       if (message.type==V_VAR1) {
                         if (message.sensor==101) {
                      
                         
                          // Write some debug info
                          Serial.print("Incoming change for sensor:");
                          Serial.print(message.sensor);
                          Serial.print("\n");
                          Serial.print(", New status: ");
                          Serial.println(message.getFloat());
                         }
                        } 
                      

                      I am able to get the value from the second node. But was just wondering why '0' is used in the request(0, V_VAR1) call when the value is being directly sent from the 1st node to the 2nd node

                      rejoe2R 1 Reply Last reply
                      1
                      • J Joe13

                        As an update.
                        Finally after wrapping my head around the topic and knowing that you cant just send a value from one node in a VAR1 and expect it to just retain that value and get it in another node, i used the node - node communication and it worked!!!.

                        so my send sketch is

                        send(pcMsg.setDestination(1).setSensor(101).set(temperature,1));
                        

                        and receive sketch is

                        void loop() 
                        {
                           request(0, V_VAR1);
                         }
                        
                        void receive(const MyMessage &message) {
                        
                         if (message.type==V_VAR1) {
                           if (message.sensor==101) {
                        
                           
                            // Write some debug info
                            Serial.print("Incoming change for sensor:");
                            Serial.print(message.sensor);
                            Serial.print("\n");
                            Serial.print(", New status: ");
                            Serial.println(message.getFloat());
                           }
                          } 
                        

                        I am able to get the value from the second node. But was just wondering why '0' is used in the request(0, V_VAR1) call when the value is being directly sent from the 1st node to the 2nd node

                        rejoe2R Offline
                        rejoe2R Offline
                        rejoe2
                        wrote on last edited by
                        #31

                        @joe13 The request() call in your loop() is no longer neccessary. Receiving what is sent from another node is handled without that...

                        Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                        J 1 Reply Last reply
                        2
                        • rejoe2R rejoe2

                          @joe13 The request() call in your loop() is no longer neccessary. Receiving what is sent from another node is handled without that...

                          J Offline
                          J Offline
                          Joe13
                          wrote on last edited by
                          #32

                          @rejoe2 thanks works perfectly now.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            iahim67
                            wrote on last edited by iahim67
                            #33

                            Hi @Joe13, I managed to request information from the Domoticz controller and put it on a LCD (LCD2004A in my case). My Arduino code below, not very polished nor optimized as I am not a programmer :smile: but it works nicely so far. This code running on the Arduino Nano will create 4 text devices on the Domoticz side: LCD1_LINE1, LCD1_LINE2, LCD1_LINE3 and LCD1_LINE4 then it will display what ever Domoticz will put (change) in these text devices. At the end of the Arduino sketch there is a DzVents code that will count both Mysensors devices (except text devices) and Domoticz devices (all) and will place this information in the text device LCD1_LINE3 which will be displayed on my LCD accordingly - on the third line. You can create DzVents (or LUA) code that will place in these text devices virtually anything available in Domoticz, temperature included of course.
                            Second DzVents code at the end of my Arduino code will display on the first line on my LCD the temperature set on a virtual TERMOSTAT device and the current temperature measured with a cheap thermistor on the same node as the LCD device.
                            Comment this line if you use the default radion channel: #define MY_RF24_CHANNEL 83
                            Hope it helps ...

                            /*
                              LCD2004A 20x4
                                - LCD pin 1 --> GND
                                - LCD pin 2 --> +5V
                                - LCD pin 3 --> (1K - 10K) POTI
                                - LCD pin 5 --> GND
                                - LCD pin 15 --> to +5V in series with 100 OHM (Backlight "+")
                                - LCD pin 16 --> GND (Backlight "-")
                                - LCD function:  RS, E, D4, D5, D6, D7
                                - LCD2004A pins: 4 , 6 ,11 ,12, 13, 14
                                - NANO pins: 3, 4, 5, 6, 7, 8
                            
                                Thermistor: 4K7 / B57164K0472J000 in series with 4K7 resistor
                                TH pin1 to GND
                                TH pin2 to pin2 of the series resistor and together to A0 on the Arduino side
                                Series resistor pin1 to +5V
                                _nominal_resistor adjusted to 4660 (compared to Fluke TK80 thermocouple module + Fluke 87 multimeter)
                                to get the same temperature as the Fluke thermocouple @ around 25 Celsius - each Thermistor requires individual "calibration"
                            */
                            
                            // Enable debug prints to serial monitor
                            //#define MY_DEBUG
                            
                            #define MY_RADIO_NRF24
                            #define MY_NODE_ID 240
                            // Enable repeater functionality for this node
                            #define MY_REPEATER_FEATURE
                            #define MY_RF24_CHANNEL 83
                            #define DEBUG 1
                            
                            #include <MySensors.h>
                            
                            // Node specific
                            #define SKETCH_NAME "LCD2004A_1_Nano"
                            #define SKETCH_VERSION "1.0_2.2.0"
                            #define SENSOR_DESCRIPTION "LCD1_MySensors"
                            #define LCD_TH "LCD1_TH"
                            #define LCD_LINE1 "LCD1_LINE1"
                            #define LCD_LINE2 "LCD1_LINE2"
                            #define LCD_LINE3 "LCD1_LINE3"
                            #define LCD_LINE4 "LCD1_LINE4"
                            
                            #define LCD_TH_CHILD_ID 241
                            #define LCD_LINE1_CHILD_ID 242
                            #define LCD_LINE2_CHILD_ID 243
                            #define LCD_LINE3_CHILD_ID 244
                            #define LCD_LINE4_CHILD_ID 245
                            // Node specific
                            
                            #include "LiquidCrystal.h"
                            LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
                            
                            
                            int _nominal_resistor = 4660;
                            int _nominal_temperature = 25;
                            int _b_coefficient = 3950;
                            int _series_resistor = 4697;
                            int _pin = 0;
                            
                            String line1 = "line1               ";
                            String line2 = "line2               ";
                            String line3 = "line3               ";
                            String line4 = "line4               ";
                            
                            bool line1received = false;
                            bool line2received = false;
                            bool line3received = false;
                            bool line4received = false;
                            
                            MyMessage msgTemp(LCD_TH_CHILD_ID, V_TEMP);
                            MyMessage msgLine1(LCD_LINE1_CHILD_ID, V_TEXT);
                            MyMessage msgLine2(LCD_LINE2_CHILD_ID, V_TEXT);
                            MyMessage msgLine3(LCD_LINE3_CHILD_ID, V_TEXT);
                            MyMessage msgLine4(LCD_LINE1_CHILD_ID, V_TEXT);
                            
                            void setup() {
                              Serial.begin(115200);
                              // put your setup code here, to run once:
                              // set up the LCD's number of columns and rows:
                              lcd.begin(20, 4);
                              lcd.clear();
                              lcd.home();
                              LCD_test();
                            }
                            
                            void presentation()
                            {
                              // Send the sketch version information to the gateway and Controller
                              sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                            
                              // Register all sensors to gw (they will be created as child devices)
                              present(LCD_TH_CHILD_ID, S_TEMP, LCD_TH);
                              present(LCD_LINE1_CHILD_ID, S_INFO, LCD_LINE1);
                              present(LCD_LINE2_CHILD_ID, S_INFO, LCD_LINE2);
                              present(LCD_LINE3_CHILD_ID, S_INFO, LCD_LINE3);
                              present(LCD_LINE4_CHILD_ID, S_INFO, LCD_LINE4);
                            
                            }
                            
                            void loop()
                            {
                              line1received = false;
                              line2received = false;
                              line3received = false;
                              line4received = false;
                            
                              tempReport();
                            
                              if (!line1received) {
                                request(LCD_LINE1_CHILD_ID, V_TEXT);
                            #if DEBUG == 1
                                Serial.println("Requested line1 from gw !");
                            #endif
                                wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                              }
                            
                              if (!line2received) {
                                request(LCD_LINE2_CHILD_ID, V_TEXT);
                            #if DEBUG == 1
                                Serial.println("Requested line1 from gw !");
                            #endif
                                wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                              }
                            
                              if (!line3received) {
                                request(LCD_LINE3_CHILD_ID, V_TEXT);
                            #if DEBUG == 1
                                Serial.println("Requested line1 from gw !");
                            #endif
                                wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                              }
                            
                              if (!line4received) {
                                request(LCD_LINE4_CHILD_ID, V_TEXT);
                            #if DEBUG == 1
                                Serial.println("Requested line1 from gw !");
                            #endif
                                wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                              }
                            
                              wait(15000);
                            }
                            
                            // Temperature report
                            void tempReport()
                            {
                              wait(100);
                              // read the voltage across the thermistor
                              float adc = analogRead(_pin);
                              // set TH_PIN LOW
                              //digitalWrite(TH_PIN, LOW);
                              // calculate the temperature
                              float reading = (1023 / adc)  - 1;
                              reading = _series_resistor / reading;
                              float temperature;
                              temperature = reading / _nominal_resistor;     // (R/Ro)
                              temperature = log(temperature);                  // ln(R/Ro)
                              temperature /= _b_coefficient;                   // 1/B * ln(R/Ro)
                              temperature += 1.0 / (_nominal_temperature + 273.15); // + (1/To)
                              temperature = 1.0 / temperature;                 // Invert
                              temperature -= 273.15;                         // convert to C
                            #if DEBUG == 1
                              Serial.print(F("THER I="));
                              Serial.print(LCD_TH_CHILD_ID);
                              Serial.print(F(" V="));
                              Serial.print(adc);
                              Serial.print(F(" T="));
                              Serial.println(temperature);
                            #endif
                              // Send temperature to the controller
                              send(msgTemp.set(temperature, 1));
                            }
                            
                            void receive(const MyMessage &message)
                            {
                              int ID = message.sensor;
                            
                              if (ID == LCD_LINE1_CHILD_ID) {
                                // Receive line1
                                if (message.type == V_TEXT) {
                                  line1 = message.getString();
                            #if DEBUG == 1
                                  Serial.print("Sensor: ");
                                  Serial.println(ID);
                                  Serial.print("Received line1 from gw: ");
                                  Serial.println(line1);
                            #endif
                                  line1received = true;
                                  printline1();
                                }
                              }
                            
                              if (ID == LCD_LINE2_CHILD_ID) {
                                // Receive line2
                                if (message.type == V_TEXT) {
                                  line2 = message.getString();
                            #if DEBUG == 1
                                  Serial.print("Sensor: ");
                                  Serial.println(ID);
                                  Serial.print("Received line2 from gw: ");
                                  Serial.println(line2);
                            #endif
                                  line2received = true;
                                  printline2();
                                }
                              }
                            
                              if (ID == LCD_LINE3_CHILD_ID) {
                                // Receive line3
                                if (message.type == V_TEXT) {
                                  line3 = message.getString();
                            #if DEBUG == 1
                                  Serial.print("Sensor: ");
                                  Serial.println(ID);
                                  Serial.print("Received line3 from gw: ");
                                  Serial.println(line3);
                            #endif
                                  line3received = true;
                                  printline3();
                                }
                              }
                            
                              if (ID == LCD_LINE4_CHILD_ID) {
                                // Receive line4
                                if (message.type == V_TEXT) {
                                  line4 = message.getString();
                            #if DEBUG == 1
                                  Serial.print("Sensor: ");
                                  Serial.println(ID);
                                  Serial.print("Received line4 from gw: ");
                                  Serial.println(line4);
                            #endif
                                  line4received = true;
                                  printline4();
                                }
                              }
                            }
                            
                            // Print line1
                            void printline1() {
                              lcd.setCursor(0, 0);
                              lcd.print(line1.substring(0, 20));
                            }
                            
                            // Print line2
                            void printline2() {
                              lcd.setCursor(0, 1);
                              lcd.print(line2.substring(0, 20));
                            }
                            
                            // Print line3
                            void printline3() {
                              lcd.setCursor(0, 2);
                              lcd.print(line3.substring(0, 20));
                            }
                            
                            // Print line4
                            void printline4() {
                              lcd.setCursor(0, 3);
                              lcd.print(line4.substring(0, 20));
                            }
                            
                            // LCD test
                            void LCD_test(void)
                            {
                              // show some output
                              lcd.setCursor(0, 0);
                              lcd.print("hello world, line 1!");
                              lcd.setCursor(0, 1);
                              lcd.print("hello world, line 2!");
                              lcd.setCursor(0, 2);
                              lcd.print("hello world, line 3!");
                              lcd.setCursor(0, 3);
                              lcd.print("hello world, line 4!");
                            }
                            
                            /*
                            On the Domoticz side, this DzVents 2.4.x code will display MySensors devices and Domoticz devices on line 3 of the LCD.
                            Replace MySensorsGW_CH83 with whatever you see in Setup/Devices under the Hardware column for your MySensors devices (i.e. not Domoticz dummy devices ... etc.)
                            
                            ---------------------------------------------------------------------------------------------------------------------
                            return {
                              on = {
                                  timer = {'every minute'}
                              },
                              execute = function(domoticz)
                                  count_mys = domoticz.devices().reduce(function(mys, device)
                                        if (device.hardwareName == 'MySensorsGW_CH83') and (device.deviceSubType ~= 'Text') then
                                            mys = mys + 1 -- increase the accumulator
                                            --domoticz.log(device.hardwareName)
                                        end
                                        return mys -- return count of MySensors devices
                                    end, 0)
                                    
                                    count_domo = domoticz.devices().reduce(function(domo, device)
                                        domo = domo + 1 -- increase the accumulator
                                        --domoticz.log(device.name)
                                        --domoticz.log(device.idx .. " @ " .. device.name)
                                    return domo -- return count of Domoticz devices
                                    end, 0)
                                    domoticz.log("MySDom count " .. count_mys .. "/" .. count_domo)
                                    domoticz.devices('LCD1_LINE3').updateText("MySDom count " .. count_mys .. "/" .. count_domo .. "    ")
                              end
                            }
                            
                            --------------------------------------------------------------------------------------------------------------------------
                            
                             return {
                                on = {
                                    devices = {
                                        'LCD1_TH',
                                        'TERMOSTAT'
                                    }
                                },
                                execute = function(domoticz, LCD1_TH)
                                    domoticz.log(LCD1_TH.name)
                                    domoticz.log(LCD1_TH.state)
                                    domoticz.devices().forEach(function(device)
                                        if (device.name == 'TERMOSTAT') then
                                            domoticz.log(device.name)
                                            domoticz.log(device.state)
                                            domoticz.devices('LCD1_LINE1').updateText("SET " .. device.state .. " ACT " .. LCD1_TH.state .. "`C ")
                                        end
                                    end)
                                end
                            }
                            
                            */
                            J 1 Reply Last reply
                            0
                            • I iahim67

                              Hi @Joe13, I managed to request information from the Domoticz controller and put it on a LCD (LCD2004A in my case). My Arduino code below, not very polished nor optimized as I am not a programmer :smile: but it works nicely so far. This code running on the Arduino Nano will create 4 text devices on the Domoticz side: LCD1_LINE1, LCD1_LINE2, LCD1_LINE3 and LCD1_LINE4 then it will display what ever Domoticz will put (change) in these text devices. At the end of the Arduino sketch there is a DzVents code that will count both Mysensors devices (except text devices) and Domoticz devices (all) and will place this information in the text device LCD1_LINE3 which will be displayed on my LCD accordingly - on the third line. You can create DzVents (or LUA) code that will place in these text devices virtually anything available in Domoticz, temperature included of course.
                              Second DzVents code at the end of my Arduino code will display on the first line on my LCD the temperature set on a virtual TERMOSTAT device and the current temperature measured with a cheap thermistor on the same node as the LCD device.
                              Comment this line if you use the default radion channel: #define MY_RF24_CHANNEL 83
                              Hope it helps ...

                              /*
                                LCD2004A 20x4
                                  - LCD pin 1 --> GND
                                  - LCD pin 2 --> +5V
                                  - LCD pin 3 --> (1K - 10K) POTI
                                  - LCD pin 5 --> GND
                                  - LCD pin 15 --> to +5V in series with 100 OHM (Backlight "+")
                                  - LCD pin 16 --> GND (Backlight "-")
                                  - LCD function:  RS, E, D4, D5, D6, D7
                                  - LCD2004A pins: 4 , 6 ,11 ,12, 13, 14
                                  - NANO pins: 3, 4, 5, 6, 7, 8
                              
                                  Thermistor: 4K7 / B57164K0472J000 in series with 4K7 resistor
                                  TH pin1 to GND
                                  TH pin2 to pin2 of the series resistor and together to A0 on the Arduino side
                                  Series resistor pin1 to +5V
                                  _nominal_resistor adjusted to 4660 (compared to Fluke TK80 thermocouple module + Fluke 87 multimeter)
                                  to get the same temperature as the Fluke thermocouple @ around 25 Celsius - each Thermistor requires individual "calibration"
                              */
                              
                              // Enable debug prints to serial monitor
                              //#define MY_DEBUG
                              
                              #define MY_RADIO_NRF24
                              #define MY_NODE_ID 240
                              // Enable repeater functionality for this node
                              #define MY_REPEATER_FEATURE
                              #define MY_RF24_CHANNEL 83
                              #define DEBUG 1
                              
                              #include <MySensors.h>
                              
                              // Node specific
                              #define SKETCH_NAME "LCD2004A_1_Nano"
                              #define SKETCH_VERSION "1.0_2.2.0"
                              #define SENSOR_DESCRIPTION "LCD1_MySensors"
                              #define LCD_TH "LCD1_TH"
                              #define LCD_LINE1 "LCD1_LINE1"
                              #define LCD_LINE2 "LCD1_LINE2"
                              #define LCD_LINE3 "LCD1_LINE3"
                              #define LCD_LINE4 "LCD1_LINE4"
                              
                              #define LCD_TH_CHILD_ID 241
                              #define LCD_LINE1_CHILD_ID 242
                              #define LCD_LINE2_CHILD_ID 243
                              #define LCD_LINE3_CHILD_ID 244
                              #define LCD_LINE4_CHILD_ID 245
                              // Node specific
                              
                              #include "LiquidCrystal.h"
                              LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
                              
                              
                              int _nominal_resistor = 4660;
                              int _nominal_temperature = 25;
                              int _b_coefficient = 3950;
                              int _series_resistor = 4697;
                              int _pin = 0;
                              
                              String line1 = "line1               ";
                              String line2 = "line2               ";
                              String line3 = "line3               ";
                              String line4 = "line4               ";
                              
                              bool line1received = false;
                              bool line2received = false;
                              bool line3received = false;
                              bool line4received = false;
                              
                              MyMessage msgTemp(LCD_TH_CHILD_ID, V_TEMP);
                              MyMessage msgLine1(LCD_LINE1_CHILD_ID, V_TEXT);
                              MyMessage msgLine2(LCD_LINE2_CHILD_ID, V_TEXT);
                              MyMessage msgLine3(LCD_LINE3_CHILD_ID, V_TEXT);
                              MyMessage msgLine4(LCD_LINE1_CHILD_ID, V_TEXT);
                              
                              void setup() {
                                Serial.begin(115200);
                                // put your setup code here, to run once:
                                // set up the LCD's number of columns and rows:
                                lcd.begin(20, 4);
                                lcd.clear();
                                lcd.home();
                                LCD_test();
                              }
                              
                              void presentation()
                              {
                                // Send the sketch version information to the gateway and Controller
                                sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                              
                                // Register all sensors to gw (they will be created as child devices)
                                present(LCD_TH_CHILD_ID, S_TEMP, LCD_TH);
                                present(LCD_LINE1_CHILD_ID, S_INFO, LCD_LINE1);
                                present(LCD_LINE2_CHILD_ID, S_INFO, LCD_LINE2);
                                present(LCD_LINE3_CHILD_ID, S_INFO, LCD_LINE3);
                                present(LCD_LINE4_CHILD_ID, S_INFO, LCD_LINE4);
                              
                              }
                              
                              void loop()
                              {
                                line1received = false;
                                line2received = false;
                                line3received = false;
                                line4received = false;
                              
                                tempReport();
                              
                                if (!line1received) {
                                  request(LCD_LINE1_CHILD_ID, V_TEXT);
                              #if DEBUG == 1
                                  Serial.println("Requested line1 from gw !");
                              #endif
                                  wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                                }
                              
                                if (!line2received) {
                                  request(LCD_LINE2_CHILD_ID, V_TEXT);
                              #if DEBUG == 1
                                  Serial.println("Requested line1 from gw !");
                              #endif
                                  wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                                }
                              
                                if (!line3received) {
                                  request(LCD_LINE3_CHILD_ID, V_TEXT);
                              #if DEBUG == 1
                                  Serial.println("Requested line1 from gw !");
                              #endif
                                  wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                                }
                              
                                if (!line4received) {
                                  request(LCD_LINE4_CHILD_ID, V_TEXT);
                              #if DEBUG == 1
                                  Serial.println("Requested line1 from gw !");
                              #endif
                                  wait(5000, 2, V_TEXT); // wait for 5s or until a message of type V_TEXT is received
                                }
                              
                                wait(15000);
                              }
                              
                              // Temperature report
                              void tempReport()
                              {
                                wait(100);
                                // read the voltage across the thermistor
                                float adc = analogRead(_pin);
                                // set TH_PIN LOW
                                //digitalWrite(TH_PIN, LOW);
                                // calculate the temperature
                                float reading = (1023 / adc)  - 1;
                                reading = _series_resistor / reading;
                                float temperature;
                                temperature = reading / _nominal_resistor;     // (R/Ro)
                                temperature = log(temperature);                  // ln(R/Ro)
                                temperature /= _b_coefficient;                   // 1/B * ln(R/Ro)
                                temperature += 1.0 / (_nominal_temperature + 273.15); // + (1/To)
                                temperature = 1.0 / temperature;                 // Invert
                                temperature -= 273.15;                         // convert to C
                              #if DEBUG == 1
                                Serial.print(F("THER I="));
                                Serial.print(LCD_TH_CHILD_ID);
                                Serial.print(F(" V="));
                                Serial.print(adc);
                                Serial.print(F(" T="));
                                Serial.println(temperature);
                              #endif
                                // Send temperature to the controller
                                send(msgTemp.set(temperature, 1));
                              }
                              
                              void receive(const MyMessage &message)
                              {
                                int ID = message.sensor;
                              
                                if (ID == LCD_LINE1_CHILD_ID) {
                                  // Receive line1
                                  if (message.type == V_TEXT) {
                                    line1 = message.getString();
                              #if DEBUG == 1
                                    Serial.print("Sensor: ");
                                    Serial.println(ID);
                                    Serial.print("Received line1 from gw: ");
                                    Serial.println(line1);
                              #endif
                                    line1received = true;
                                    printline1();
                                  }
                                }
                              
                                if (ID == LCD_LINE2_CHILD_ID) {
                                  // Receive line2
                                  if (message.type == V_TEXT) {
                                    line2 = message.getString();
                              #if DEBUG == 1
                                    Serial.print("Sensor: ");
                                    Serial.println(ID);
                                    Serial.print("Received line2 from gw: ");
                                    Serial.println(line2);
                              #endif
                                    line2received = true;
                                    printline2();
                                  }
                                }
                              
                                if (ID == LCD_LINE3_CHILD_ID) {
                                  // Receive line3
                                  if (message.type == V_TEXT) {
                                    line3 = message.getString();
                              #if DEBUG == 1
                                    Serial.print("Sensor: ");
                                    Serial.println(ID);
                                    Serial.print("Received line3 from gw: ");
                                    Serial.println(line3);
                              #endif
                                    line3received = true;
                                    printline3();
                                  }
                                }
                              
                                if (ID == LCD_LINE4_CHILD_ID) {
                                  // Receive line4
                                  if (message.type == V_TEXT) {
                                    line4 = message.getString();
                              #if DEBUG == 1
                                    Serial.print("Sensor: ");
                                    Serial.println(ID);
                                    Serial.print("Received line4 from gw: ");
                                    Serial.println(line4);
                              #endif
                                    line4received = true;
                                    printline4();
                                  }
                                }
                              }
                              
                              // Print line1
                              void printline1() {
                                lcd.setCursor(0, 0);
                                lcd.print(line1.substring(0, 20));
                              }
                              
                              // Print line2
                              void printline2() {
                                lcd.setCursor(0, 1);
                                lcd.print(line2.substring(0, 20));
                              }
                              
                              // Print line3
                              void printline3() {
                                lcd.setCursor(0, 2);
                                lcd.print(line3.substring(0, 20));
                              }
                              
                              // Print line4
                              void printline4() {
                                lcd.setCursor(0, 3);
                                lcd.print(line4.substring(0, 20));
                              }
                              
                              // LCD test
                              void LCD_test(void)
                              {
                                // show some output
                                lcd.setCursor(0, 0);
                                lcd.print("hello world, line 1!");
                                lcd.setCursor(0, 1);
                                lcd.print("hello world, line 2!");
                                lcd.setCursor(0, 2);
                                lcd.print("hello world, line 3!");
                                lcd.setCursor(0, 3);
                                lcd.print("hello world, line 4!");
                              }
                              
                              /*
                              On the Domoticz side, this DzVents 2.4.x code will display MySensors devices and Domoticz devices on line 3 of the LCD.
                              Replace MySensorsGW_CH83 with whatever you see in Setup/Devices under the Hardware column for your MySensors devices (i.e. not Domoticz dummy devices ... etc.)
                              
                              ---------------------------------------------------------------------------------------------------------------------
                              return {
                                on = {
                                    timer = {'every minute'}
                                },
                                execute = function(domoticz)
                                    count_mys = domoticz.devices().reduce(function(mys, device)
                                          if (device.hardwareName == 'MySensorsGW_CH83') and (device.deviceSubType ~= 'Text') then
                                              mys = mys + 1 -- increase the accumulator
                                              --domoticz.log(device.hardwareName)
                                          end
                                          return mys -- return count of MySensors devices
                                      end, 0)
                                      
                                      count_domo = domoticz.devices().reduce(function(domo, device)
                                          domo = domo + 1 -- increase the accumulator
                                          --domoticz.log(device.name)
                                          --domoticz.log(device.idx .. " @ " .. device.name)
                                      return domo -- return count of Domoticz devices
                                      end, 0)
                                      domoticz.log("MySDom count " .. count_mys .. "/" .. count_domo)
                                      domoticz.devices('LCD1_LINE3').updateText("MySDom count " .. count_mys .. "/" .. count_domo .. "    ")
                                end
                              }
                              
                              --------------------------------------------------------------------------------------------------------------------------
                              
                               return {
                                  on = {
                                      devices = {
                                          'LCD1_TH',
                                          'TERMOSTAT'
                                      }
                                  },
                                  execute = function(domoticz, LCD1_TH)
                                      domoticz.log(LCD1_TH.name)
                                      domoticz.log(LCD1_TH.state)
                                      domoticz.devices().forEach(function(device)
                                          if (device.name == 'TERMOSTAT') then
                                              domoticz.log(device.name)
                                              domoticz.log(device.state)
                                              domoticz.devices('LCD1_LINE1').updateText("SET " .. device.state .. " ACT " .. LCD1_TH.state .. "`C ")
                                          end
                                      end)
                                  end
                              }
                              
                              */
                              J Offline
                              J Offline
                              Joe13
                              wrote on last edited by Joe13
                              #34

                              @iahim67 Thanks for this. I will definitely give it a try and provide a feedback on this. I am still new to this, but your code is well commented to provide a good guide

                              1 Reply Last reply
                              0
                              • J Offline
                                J Offline
                                Joe13
                                wrote on last edited by
                                #35

                                @iahim67 . Got tied up some stuffs. I gave DzVents a try as I am totally new to it. Ran some basic stuffs and works perfectly. Will gather some more time and do a full run on this

                                1 Reply Last reply
                                0
                                • I Offline
                                  I Offline
                                  iahim67
                                  wrote on last edited by iahim67
                                  #36

                                  @Joe13, I am new to DzVents too ... but it is a great opportunity to learn:smile:
                                  Have a look into the Domoticz installation folder, can't remember now exactly where but there is a sub-folder with interesting examples, when you start reading these examples you may have a better overall understanding of how DzVents works.
                                  Their wiki is also very usefull:
                                  https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting
                                  Have fun @Joe13 ...

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


                                  12

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.0k

                                  Posts


                                  Copyright 2019 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