2nd sensor in sketch not showing up in HA
-
I am trying to modify my working moisture sensor sketch to present 2 child Ids instead of one. Arduino serial monitor shows the data from both sensors and HA sees it but the 2nd sensor does not show up in unused entities. I am confident I am erring in my sketch somehow but not sure where.
/* AnalogReadSerial Reads an analog input on pin 0, prints the result to the Serial Monitor. Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. This example code is in the public domain. http://www.arduino.cc/en/Tutorial/AnalogReadSerial */ // Enable debug prints // #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_NRF5_ESB //#define MY_RADIO_RFM69 //#define MY_RADIO_RFM95 #define CHILD_ID_A0 0 #define CHILD_ID_A1 1 #include <MySensors.h> MyMessage msg(CHILD_ID_A0, V_LEVEL); MyMessage msg2(CHILD_ID_A1, V_LEVEL); // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } void presentation() { sendSketchInfo("Analog Soil Moisture Sensor", "1c.0"); present(CHILD_ID_A0, S_MOISTURE); present(CHILD_ID_A1, S_MOISTURE); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); int sensorValueA1 = analogRead(A1); // print out the value you read: Serial.println(sensorValue); Serial.println(sensorValueA1); send(msg.set(sensorValue)); send(msg.set(sensorValueA1)); delay(10000); // delay in between reads for stability }
HA logs:
2020-03-16 15:56:04 WARNING (MainThread) [mysensors.sensor] child_id 0 already exists in children of node 105, cannot add child 2020-03-16 15:56:04 WARNING (MainThread) [mysensors.sensor] child_id 1 already exists in children of node 105, cannot add child
-
@mrhutchinsonmn I think the error indicates the child already exist, so you could try to change the node id, or modify the persistence file manually:
https://forum.mysensors.org/topic/10901/manual-adjust-the-persistence-file-instead-of-adjust-the-node-s/3
-
@mrhutchinsonmn said in 2nd sensor in sketch not showing up in HA:
MyMessage msg(CHILD_ID_A0, V_LEVEL); MyMessage msg2(CHILD_ID_A1, V_LEVEL); [...] void loop() { [...] send(msg.set(sensorValue)); send(msg.set(sensorValueA1)); [...] }
You are sending both sensor values with the same message, so they both get reported to child ID 0 and child ID 1 will never show up.
Change the second send function from
send(msg.set(sensorValueA1));
to
send(msg2.set(sensorValueA1));
-
@BearWithBeard You beat me to it by a minute!
-
@BearWithBeard said in 2nd sensor in sketch not showing up in HA:
send(msg2.set(sensorValueA1));
Yes, that was it!! Thank you!!
Suggested Topics
-
Hi,
Home Assistant • • diltech