MySensors - Get Temperature value from another node through the Gateway



  • Hi Everyone,
    I did search for this in several place, however could not find a solution.
    I have a node that gets the temp and hum in Room1 and sends these data to the Domoticz controller.
    Now i have another node with LCD in Room2. How can i display the temp and hum of Room1 node onto the Room2 LCD.

    So far it I have put the below code, but the value comes in as 0. The Room1 temp child Id is 12

    void loop() 
    {
      delay(10000);
      request(12, V_VAR1, 0);
      Serial.print("Requested temp from gw 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) {
         // Change relay state
       //  digitalWrite(RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
        
         // Write some debug info
         Serial.print("Incoming change for sensor:");
         Serial.print(message.sensor);
         Serial.print(", New status: ");
         Serial.println(message.getInt());
       } 
    }
    

    Serial monitor Output

    517420 TSF:MSG:SEND,1-1-0-0,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
    Requested temp from gw VAR1517427 TSF:MSG:READ,0-0-1,s=12,c=2,t=24,pt=0,l=0,sg=0:
    Incoming change for sensor:12, New status: 0
    

    Hope someone can provide some insight on this.
    thanks


  • Mod

    Hi @joe13, welcome to the MySensors community!
    I haven't tried this myself, but I think the 0 in

    request(12, V_VAR1, 0);
    

    needs to be changed to the id of the node in Room 1. Could you try that?

    Documentation reference: https://www.mysensors.org/download/sensor_api_20#requesting-data



  • Hi @mfalkvidd thanks. Yes my first post.
    I did try that, however, there is no response in the Receive part in the Serial Monitor

    void loop() 
    {
      delay(10000);
      request(12, V_VAR1,3);
      Serial.print("Requested temp from gw 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.getFloat());
       } 
    }
    

    Serial monitor output after setting Node id (3) instead of Gateway(0)

    Requested temp from gw VAR122279 !TSF:MSG:SEND,1-1-0-3,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=NACK:
    Requested temp from gw VAR132287 TSF:MSG:SEND,1-1-0-3,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=1,st=OK:
    Requested temp from gw VAR142296 TSF:MSG:SEND,1-1-0-3,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
    Requested temp from gw VAR152303 TSF:MSG:SEND,1-1-0-3,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
    Requested temp from gw VAR162311 TSF:MSG:SEND,1-1-0-3,s=12,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
    

  • Mod

    I would approach the problem on the opposite direction, I'd send the temperature to gateway and also to the node with display, so if your temperature node is a sleeping node it would just send when it wakes up and you get your temperature displayed



  • @gohan but isn't there a way to get the Temp from the Gateway. I am getting some sort of Receive msg (based on the my initial post) but the value is 0.
    in this way, i can request the temp from the GW whenever required and not ask the node to send the data every few mins


  • Mod

    The gateway doesn't store any data. You could request data from controller if you have one running.



  • @gohan Yes that would be great. i have Domoticz running and the temp shows up there. could you let me know how I can get the temp from the controller.
    I found this link and that is the code that i initially tried https://www.domoticz.com/forum/viewtopic.php?t=9708
    but gives an O/P of 0


  • Mod

    I have never done it myself, but I'd start looking at the pulse energy meter as it has a function to retrieve a sensor value from controller

    The code in that post is for the old mysensors version



  • @gohan i did convert it to the 2.1V but the result is the same. so if you were to do something like this, show all the temps from different rooms(nodes) on a central LCD placed in the hall, how would you go about it. I am just a beginner so an ideal way would be great.
    The Pulse energy meter code tell " Received last pulse count from gw:" so could it be possible to get values from GW.


  • Mod

    As said before I'd go for the node to node communication, so send the temperature also to the lcd node, or you could also use an esp8266 and read the the mqtt messages from topic domoticz/out that domoticz sends every time there is a change in the controller data.



  • @gohan thanks, but i do not have much knowledge on ESP8266 and mqtt but will give the a try to push data from the node to the LCD node



  • anyone who has tried pulling value from GW or controller to a different node, please let me know on how you did it. thanks



  • @joe13
    I think, you must send temperature ( for later resending) to domoticz like V_VAR1 for storing it, and then requested it again like V_VAR1. Do not use V_TEMP for this.
    Look at V_VAR like universal variable for storing anything.
    At your code examples is not evident, what you put to V_VAR1 first, maybe nothing, so do not be disappointed, if you read 0 back.
    At EnergyCounter Sensor you can see:

    MyMessage wattMsg(CHILD_ID,V_WATT);
    MyMessage kwhMsg(CHILD_ID,V_KWH);
    MyMessage pcMsg(CHILD_ID,V_VAR1);    !!!!!!
    ....
    
    send(wattMsg.set(watt));
    send(kwhMsg.set(kwh, 4));  // Send kwh value to gw
    send(pcMsg.set(pulseCount));  // Send pulse count value to gw         !!!!!!
     .....
    
    request(CHILD_ID, V_VAR1);
    
    
    

    So it sends to domoticz not only W and kWh for displaying it, but pulse for storing and reading later too.

    But like wrote gohan, I think better way is sending temperature from node twice - to domoticz and to LCD node. This will work even if domoticz will bee down.



  • @kimot that part i missed. thanks for pointing that out. I will give this option also a try. its just that the other sensors that are in the other rooms are already set in place and I do not want to pluck them out and recode them. So pulling the values from the GW would have been an advantage. But anyways, if that is the way to go, then Ill probably do that.
    Thanks everyone for your inputs



  • Hi all,

    Sorry to jump in. If my post is off-topic please say so and i will start a new thread

    I am in the process of doing the same: a temp/hum node and a node with LCD displaying temp and hum

    Many-many questions :

    • all messages (even node-to-node ones) go through gateway and controller ?
    • sending request(CHILD_ID, V_VAR1) does not mention the node's ID... i just can't get my head round this... there could be many sensors handling the same variable type with the same child id... ? So how do we know we will be getting data from the right node and sensor (child) ?
    • sending request(CHILD_ID, V_VAR1) will actually ask the controller to ask the node to send its data? Or does it request data straight from node?
    • isn't there a simple way for nodes to fetch data (data coming from itself and from other nodes) from controller?

    Thanks for your help



  • @ben999 If you do node-to-node communication, the message does not necessarily need a controller; it is routed through the lowest common repeater node (this might be the gateway). Eg. if you have two nodes 5 and 6 that are communicating over node 4 with the gw, the gw may not even see the message.
    Coding then looks like this:

    send(SisternodeMsg.setDestination(MY_SISTER_NODE_ID).setSensor(CHILD_ID_SISTER_TEMP).set(temperature, 1));
    

    In case you use a controller, you would have to map the values through the controller's functionality (eg. put temperature value #2 from node 5 to value2100 on node 6 so this can be requested from node #6 using it's own ID and child ID 100 - V_VAR2.

    In both cases you have to code appropriate receive()-functionality.



  • If you do node-to-node communication, the message does not necessarily need a controller; it is routed through the lowest common repeater node (this might be the gateway). Eg. if you have two nodes 5 and 6 that are communicating over node 4 with the gw, the gw may not even see the message.
    Coding then looks like this:

    send(SisternodeMsg.setDestination(MY_SISTER_NODE_ID).setSensor(CHILD_ID_SISTER_TEMP).set(temperature, 1));
    

    That makes sense, big thumbs up, thanks a lot

    On the other hand I didn't understant a word of that... sorry...
    Could you please detail a wee bit more? And also please explain who is doing what...

    In case you use a controller, you would have to map the values through the controller's functionality (eg. put temperature value #2 from node 5 to value2100 on node 6 so this can be requested from node #6 using it's own ID and child ID 100 - V_VAR2.

    I should be able to do that 🙂

    In both cases you have to code appropriate receive()-functionality.

    Thanks a lot for your help



  • @ben999 I also had a hard time to sort things out wrt. to node-to-node communication. But in the end, its simple:
    You just have to use appropriate send()- and recieve() commands in the nodes. Example for the temperature part, using the node numbers from above:

    • For the one providing the needed info (node 5): This one is measuring temp and sends this to node 6: In the code for this node use additionally to the "normal" send() the above code and replace "MY_SISTER_NODE_ID" with 6 and "CHILD_ID_SISTER_TEMP" let's say with 101 (or use appropriate #define's).
    • In the receive() part of Node 6 you have to sort things by using the correspondant Child ID as follows:
    if (message.sensor == 101) {...
    

    I personally prefer using "speaking names" like CHILD_ID_SISTER_TEMP and define them in the header, that's what's behind the first send() code-snipplet, but that's just a question of style.



  • @rejoe2 GREAT! You gave sense to all that. Is it what some clever blokes refer to "dummy sensor" method?

    May I ask some more @rejoe2 ?
    How would you retrieve a value DIRECTLY FROM the controller?
    Say that node 5 and 6 sleep most of their time... so they never get to speak directly to each other. Then the controller would be the mail box... I already send temp data to the controller and get it displayed in PaperUI and iOS app (using openHab). How would node 6 fetch this piece of data?

    Once more, thanks a lot for your time and patience (it's not easy eaducating people 😄 )



  • @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 😀

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



  • @rejoe2 Dude!!! It worked! Awesome 😄 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 😄 as i wanted to understand both ways of sharing data between nodes
    Thank you so much for that 👍



  • @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.



  • @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))
    


  • @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.



  • @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
    


  • @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.



  • @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.



  • 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.



  • 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?



  • 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



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



  • @rejoe2 thanks works perfectly now.



  • 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 😄 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
    }
    
    */


  • @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



  • @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



  • @Joe13, I am new to DzVents too ... but it is a great opportunity to learn😄
    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 ...


Log in to reply
 

Suggested Topics

  • 1
  • 6
  • 5
  • 1
  • 3
  • 10

10
Online

11.4k
Users

11.1k
Topics

112.7k
Posts