Requesting value from Domoticz
-
You are going to use 2 things. message.type and message.data. The message.type in my scenario is V_TEXT, and message.data is the payload, which in my case is O, H, C or A, but can be whatever you pass from Domoticz. The code in your receive function would look something like this:
if (message.type == V_TEXT) { Serial.println("Received data" + String(message.data)); //Here you would do something with message.data }If you have more than one child sensor sending V_TEXT data, you would then use an if statement or a switch/case to check message.sensor for the child ID of the sensor and process each as above.
if (message.type == V_TEXT) { if (message.sensor == 1) { Serial.println("Received data from child 1" + String(message.data)); //Here you would do something with message.data for the first child } else if (message.sensor == 2) { Serial.println("Received data from child 2" + String(message.data)); //Here you would do something with message.data for the second child } }Let us know if you have trouble.
-
You are going to use 2 things. message.type and message.data. The message.type in my scenario is V_TEXT, and message.data is the payload, which in my case is O, H, C or A, but can be whatever you pass from Domoticz. The code in your receive function would look something like this:
if (message.type == V_TEXT) { Serial.println("Received data" + String(message.data)); //Here you would do something with message.data }If you have more than one child sensor sending V_TEXT data, you would then use an if statement or a switch/case to check message.sensor for the child ID of the sensor and process each as above.
if (message.type == V_TEXT) { if (message.sensor == 1) { Serial.println("Received data from child 1" + String(message.data)); //Here you would do something with message.data for the first child } else if (message.sensor == 2) { Serial.println("Received data from child 2" + String(message.data)); //Here you would do something with message.data for the second child } }Let us know if you have trouble.
-
I pull the thermostat mode from my thermostat bridge node like this:
request( CHILD_ID_MODE, V_TEXT );I have never used the destination attribute, so I can't speak to it's use, but using the childSensorId and variableType works for me. You still need to use the technique I described to set the MySensors child node from the dummy sensor though.
At the moment I'm trying to send a text value from Domoticz with MySensors Gateway to one of my nodes.
I need to implement the "request" function in this node. So here's my question: what value did you assign to "CHILD_ID_MODE". I presume that's the ID of the dummy selector described in another topic on this forum? How did you obtain this value? Is it available somewhere in Domoticz UI?
Now I request a text value, but all I get is a blank message, cause I don't know what I should insert as "uint8_t childSensorId".
-
@gohan Yes, I understand, but when I create a dummy text sensor I can't define its child ID. Can I find it somewhere?
-
You have to create a sensor in the sensor node sketch, assign a child ID to it and present it like the others sensors during setup, then it should show on the controller. I can't be more specific because I haven't worked on text sensors yet
@gohan Dummy sensors are created in Domoticz, they don't use the MySensors library, so one doesn't upload any sketches to Arduino :)
What I want to achieve specifically is to send outside temperature received from WeatherUnderground to one of my MySensors nodes.
-
I know, but if you don't create a sensor able to receive the value, you can't send anything to it through the mysensors network
@gohan hey, now I get it!
got it working the way I wanted, thank you so much :D
-
Just for my curiosity, why are you using the temperature from weather underground? Is it just displayed on a screen?
@gohan I'm doing a project for my master's thesis.
There's a mathematical thermal model of a building running on MySensors node. I wanted to supply it with an information about actual outside temperature to have accurate results.
-
A real mysensors project would require an external node with temperature and humidity sensor 😁
@gohan This model is just a small part of my project. But I get your concept.
There's already a DHT11 node running inside my house, measuring quantities that you've mentioned.
-
@gohan hey, now I get it!
got it working the way I wanted, thank you so much :D
-
@tomek_olo
Sorry what is the way for send from domoticz child -node to other node through lua script for example Tanks@mar.conte I don't understand your question. Can you clarify, please?
-
@mar.conte I don't understand your question. Can you clarify, please?
-
@tomek_olo
Sorry what is the way for send from domoticz child -node to other node through lua script for example TanksOK, I'll try to describe everything I've done to get it working:
- I'm presenting MySensors node to Domoticz as S_INFO: "present(CHILD_ID, S_INFO);"
- Next step is to add this node in your Domoticz. It should be visible at first in "Devices" as a "Text" device. After you add it it will be present in the "Utility" tab.
- Now you have to edit a text value of this device in Domoticz. (I think that's what interests you but in reverse) I'm using a "Device" script that updates this text value with outside temperature every time the weather is updated:
commandArray = {}
local tempOut = devicechanged["Outside_Temperature"]
local tempOutIdx = 25if ( devicechanged["Outside"]) then
commandArray['UpdateDevice'] = otherdevices_idx['TextNode']..'|1|'..tempOut
end- Now when I want to download this new value to my node I use "request( CHILD_ID, V_TEXT );" and inside "receive()" function:
if (message.type == V_TEXT) {
if (message.sensor == CHILD_ID) {
outTemp = message.getFloat();
}
}That's all, it's complicated. If you have any questions feel free to ask. I'll do my best to help.
-
Hi,
I've been trying to modify the sketch of Solar Powered Plant moisture sensor so that I can remotely control the sleep time from Domoticz.. But so far I failed.. ;-(
Sorry for the long post below, but I try to provide all details, as I don't understand what I did wrong..I tried to understand several contributions including the ones above from dbemowsk (thank you also for your chat messages!) and tomek_olo, as well as the Water Pulse meter sensor , but I still don't succeed having the sensor receiving data from Domoticz.
Here's what I tried to do.
In Sensor, I reused the code from solar powered moisture sensor from other post (and that code is working on another sensor) then I modified it to:- present an additional child to Domoticz (CHILD_ID_SLEEP 2 with S_INFO) in setup
- send a value (here 11) of V_VAR1 in setup as per the advise from dbemowsk so that domotic recognize that data field
- then in Loop(), I have (apart the code for moisture sensor) a loop for requesting V_VAR1 (copied that from the water pulse meter sensor code)
- outside Loop() (at bottom of script), I created the receive(const MyMessage &message) procedure (in code below, I tried to print to serial several debugging messages...)
Here's below the whole code:
#include <SPI.h> #define MY_RADIO_NRF24 #define MY_DEBUG #include <MySensors.h> #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define N_ELEMENTS(array) (sizeof(array)/sizeof((array)[0])) #define CHILD_ID_MOISTURE 0 #define CHILD_ID_BATTERY 1 #define CHILD_ID_SLEEP_S 2 // #define SLEEP_TIME_S 100 // Sleep time between reads (in seconds) #define THRESHOLD 1.1 // Only make a new reading with reverse polarity if the change is larger than 10%. #define STABILIZATION_TIME 1000 // Let the sensor stabilize before reading default BOD settings. const int SENSOR_ANALOG_PINS[] = {A4, A5}; // Sensor is connected to these two pins. Avoid A3 if using ATSHA204. A6 and A7 cannot be used because they don't have pullups. // MySensor gw; MyMessage msg(CHILD_ID_MOISTURE, V_HUM); MyMessage voltage_msg(CHILD_ID_BATTERY, V_VOLTAGE); MyMessage sleep_msg(CHILD_ID_SLEEP_S, V_VAR1); unsigned long SLEEP_TIME_S = 10; unsigned long SLEEP_TIME = 10000; long oldvoltage = 0; byte direction = 0; int oldMoistureLevel = -1; float batteryPcnt; float batteryVolt; int LED = 5; bool pcReceived = false; void setup() { pinMode(LED, OUTPUT); digitalWrite(LED, HIGH); delay(200); digitalWrite(LED, LOW); delay(200); digitalWrite(LED, HIGH); delay(200); digitalWrite(LED, LOW); SLEEP_TIME=SLEEP_TIME_S*1000; sendSketchInfo("Plant moisture solar proto", "1.0"); // request(CHILD_ID_SLEEP_S, V_VAR1); present(CHILD_ID_MOISTURE, S_HUM); delay(250); present(CHILD_ID_BATTERY, S_MULTIMETER); for (int i = 0; i < N_ELEMENTS(SENSOR_ANALOG_PINS); i++) { pinMode(SENSOR_ANALOG_PINS[i], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[i], LOW); } present(CHILD_ID_SLEEP_S, S_INFO); send(sleep_msg.set(11)); } void loop() { pcReceived = false; int moistureLevel = readMoisture(); // Send rolling average of 2 samples to get rid of the "ripple" produced by different resistance in the internal pull-up resistors // See http://forum.mysensors.org/topic/2147/office-plant-monitoring/55 for more information if (oldMoistureLevel == -1) { // First reading, save current value as old oldMoistureLevel = moistureLevel; } if (moistureLevel > (oldMoistureLevel * THRESHOLD) || moistureLevel < (oldMoistureLevel / THRESHOLD)) { // The change was large, so it was probably not caused by the difference in internal pull-ups. // Measure again, this time with reversed polarity. moistureLevel = readMoisture(); } send(msg.set((moistureLevel + oldMoistureLevel) / 2.0 / 10.23, 1)); oldMoistureLevel = moistureLevel; int sensorValue = analogRead(A0); Serial.println(sensorValue); float voltage=sensorValue*(3.3/1023); Serial.println(voltage); batteryPcnt = (sensorValue - 248) * 0.72; batteryVolt = voltage; sendBatteryLevel(batteryPcnt); resend((voltage_msg.set(batteryVolt, 3)), 10); if (!pcReceived) { //Last sleept time not yet received from controller, request it again request(CHILD_ID_SLEEP_S, V_VAR1); Serial.print("Requested time sleep from gw VAR1"); return; } digitalWrite(LED, HIGH); delay(200); digitalWrite(LED, LOW); SLEEP_TIME=SLEEP_TIME_S*1000; sleep(SLEEP_TIME); } void resend(MyMessage &msg, int repeats) { int repeat = 1; int repeatdelay = 0; boolean sendOK = false; while ((sendOK == false) and (repeat < repeats)) { if (send(msg)) { sendOK = true; } else { sendOK = false; Serial.print("Error "); Serial.println(repeat); repeatdelay += 500; } repeat++; delay(repeatdelay); } } int readMoisture() { pinMode(SENSOR_ANALOG_PINS[direction], INPUT_PULLUP); // Power on the sensor analogRead(SENSOR_ANALOG_PINS[direction]);// Read once to let the ADC capacitor start charging sleep(STABILIZATION_TIME); int moistureLevel = (1023 - analogRead(SENSOR_ANALOG_PINS[direction])); // Turn off the sensor to conserve battery and minimize corrosion pinMode(SENSOR_ANALOG_PINS[direction], OUTPUT); digitalWrite(SENSOR_ANALOG_PINS[direction], LOW); direction = (direction + 1) % 2; // Make direction alternate between 0 and 1 to reverse polarity which reduces corrosion return moistureLevel; } void receive(const MyMessage &message) { if (message.type==V_TEXT) { // unsigned long infosleep=message.getULong(); String infosleepstr=message.getString(); unsigned long infosleep=infosleepstr.toInt(); Serial.print("Received time sleep as string from gw:"); Serial.println(infosleepstr); Serial.print("fin de msg"); SLEEP_TIME_S = infosleep; pcReceived = true; } if (message.type==V_VAR1) { unsigned long infosleep=message.getULong(); //unsigned long infosleep=message.getString(); Serial.print("Received time sleep as VAR1 ULOng from gw:"); Serial.println(infosleep); Serial.print("fin de msg"); SLEEP_TIME_S = infosleep; pcReceived = true; } }In Domoticz, in hardware I can see this:

The sensor is the "proto" one (ID 1) where I can see the various children (Humidity=0 is normal as I did not attach the soil sensor and voltage is weird as it's not connected either).
In devices view, I have:

where I can see the text sensor of S_INFO which is set to "5" thanks to a user variable (see LUA script below).

I created a user variable "SondeSleep" with a LUA script (type "variables") to update the text sensor whenever the suer variable changes:commandArray = {} if ( uservariablechanged['SondeSleep']) then print ("nouvelle valeur Level1 de SondeSleep:" .. uservariables['SondeSleep']); ttidx=otherdevices_idx['SondeSolProto_Text_Sensor']; commandArray['UpdateDevice']=ttidx..'|1|' .. uservariables['SondeSleep'] end return commandArrayThis script seems working since it replicates properly the vriable value to the text_sensor. I'm just confused by the command
commandArray['UpdateDevice']=ttidx..'|1|' .. uservariables['SondeSleep']where I couldn't understand the meaning of the value between the || (here |1|).
The Domoticz website refers to LUA and JSON page, but I coudn't find the explanation. In 1 script of this post, I saw a 0, in another a 1.. I tried with both and also wit 2 (just in case it refers to Child ID ..) but no better result.
Could someone clarifies the meaning ?When I run the sensor, I can only see (in serial monitor) the message "Requested time sleep from gw VAR1" from the "request" loop. and in Domoticz log, I can see that the sensor updates the humidity and voltage values, but that's all.
I'm also surprised I do'nt see any value in S_INFO child, but maybe it's normal.
I had tried to use V_TEXT instead of V_VAR1 everhwhere, but same result. There's definitely something I misunderstood somewehere.Anyone could help me ?
ricorico94