MySensors - Get Temperature value from another node through the Gateway
-
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.
-
@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 :D )
-
@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 :D )
@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...
-
@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...
@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: -
@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:@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)) -
@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.
-
@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 1MyMessage 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 -
@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 1MyMessage 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. -
@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 1MyMessage 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
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
-
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...
-
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 } */ -
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 } */ -
@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 ...