V_UNIT_PREFIX with SensorBME280.h possible?
-
Hello everyone! I'm working on my first NodeManager sensor and so far so good. NodeManager really made it easy to get all the framework of a node running, allowing me to spend my time working on the actual sensor bit. I have managed to get a (cheap Chinese knockoff) BME280 sensor working using the SensorBME280.h sensor. It took a while to figure out how to get it to see my sensor at address 0x76 (see 'Chinese knockoff') but after a bit of fumbling around I now have my first node talking to my controller (Home Assistant).
Temperature, Humidity, Pressure, Signal Quality and Battery for the node all show up as expected, except for one little niggle that bothers me. Pressure doesn't have a unit_of_measurement associated with it. I know I can just fix that in my controller frontend, but I'd really prefer to have my sensors fully inform my controller of what they are reporting.
In a non-NodeManager mysensors node, I would just send a msgPrefix(CHILD_ID, V_UNIT_PREFIX) as the first message for the child to inform the controller what unit_of_measurement the child will be reporting in. My question is... is it possible to do this with the built-in NodeManager SensorBME280 sensor? If so, can anyone supply an example?
Here's where I am currently...
/********************************** * Sump Pump Monitor * * Report water level in Sump and operation of Pump. * 1) Operates as a MySensors Repeater Node * 2) Ambient Temperature/Pressure/Humidity recorded via BME280 sensor * * ToDo: * 1) Shock sensor triggers when Pump Motor is running * 2) Waterproofed pressure sensor at bottom of sump reports calculated water depth * 3) Waterproofed temperature sensor at bottom of sump reports water temperature * **********************************/ /********************************** * MySensors node configuration **********************************/ // General settings #define SKETCH_NAME "SumpPump" #define SKETCH_VERSION "0.2" #define MY_NODE_ID 1 //#define MY_DEBUG // NRF24 radio settings #define MY_RADIO_NRF24 //#define MY_RF24_ENABLE_ENCRYPTION //#define MY_RF24_CHANNEL 125 //#define MY_RF24_PA_LEVEL RF24_PA_HIGH //#define MY_DEBUG_VERBOSE_RF24 //#define MY_RF24_DATARATE RF24_250KBPS // Message signing settings //#define MY_SIGNING_SOFT //#define MY_SIGNING_SOFT_RANDOMSEED_PIN 7 //#define MY_SIGNING_REQUEST_SIGNATURES //#define MY_SIGNING_ATSHA204 //#define MY_SIGNING_ATSHA204_PIN 4 //#define MY_SIGNING_REQUEST_SIGNATURES // Advanced settings #define MY_BAUD_RATE 115200 //#define MY_SMART_SLEEP_WAIT_DURATION_MS 500 #define MY_SPLASH_SCREEN_DISABLED //#define MY_DISABLE_RAM_ROUTING_TABLE_FEATURE #define MY_SIGNAL_REPORT_ENABLED /********************************** * MySensors gateway configuration **********************************/ // Common gateway settings #define MY_REPEATER_FEATURE /********************************** * NodeManager configuration **********************************/ //#define NODEMANAGER_DEBUG ON #define NODEMANAGER_INTERRUPTS ON //#define NODEMANAGER_RECEIVE ON //#define NODEMANAGER_DEBUG_VERBOSE OFF //#define NODEMANAGER_POWER_MANAGER OFF //#define NODEMANAGER_CONDITIONAL_REPORT OFF //#define NODEMANAGER_EEPROM OFF //#define NODEMANAGER_TIME OFF //#define NODEMANAGER_RTC OFF //#define NODEMANAGER_SD OFF //#define NODEMANAGER_HOOKING OFF //#define NODEMANAGER_OTA_CONFIGURATION OFF //#define NODEMANAGER_SERIAL_INPUT OFF #ifdef MY_REPEATER_FEATURE #define NODEMANAGER_SLEEP OFF // Cannot Sleep if Repeater Node #else #define NODEMANAGER_SLEEP ON #endif // import NodeManager library (a nodeManager object will be then made available) #include <MySensors_NodeManager.h> /********************************** * Add your sensors **********************************/ // Ambient Temperature/Humidty/Pressure via BME280 #include <sensors/SensorBME280.h> #define BME280_ADDRESS (0x76) #define CHILD_ID_AMBIENT 1 SensorBME280 ambient(CHILD_ID_AMBIENT); // Battery Level (default child_id 201) #include <sensors/SensorBattery.h> SensorBattery battery; // Radio Signal Quality (default child_id 202) #include <sensors/SensorSignal.h> SensorSignal signal; /********************************** * Main Sketch **********************************/ // before void before() { /********************************** * Configure your sensors **********************************/ // report ambient measurements every 15 minutes ambient.setReportIntervalMinutes(15); // report battery level every 60 minutes battery.setReportIntervalMinutes(60); // report radio signal level every 10 minutes signal.setReportIntervalMinutes(10); // only a pseudo SR_TX_RSSI and SR_UPLINK_QUALITY are available for NRF24 // radio. All other methods return as INVALID. signal.setSignalCommand(SR_UPLINK_QUALITY); // call NodeManager before routine nodeManager.before(); } // presentation void presentation() { // call NodeManager presentation routine nodeManager.presentation(); } // setup void setup() { // call NodeManager setup routine nodeManager.setup(); } // loop void loop() { // call NodeManager loop routine nodeManager.loop(); } #if NODEMANAGER_RECEIVE == ON // receive void receive(const MyMessage &message) { // call NodeManager receive routine nodeManager.receive(message); } #endif #if NODEMANAGER_TIME == ON // receiveTime void receiveTime(unsigned long ts) { // call NodeManager receiveTime routine nodeManager.receiveTime(ts); } #endif
-
Hi @darknicht66
According to this PR (third point in the list), adding
sensor.children.get()->setUnitPrefix("YourUnit")
should do the trick. You may need to install the current development branch of NodeManager to use this. Hope this helps!
-
@BearWithBeard Awesome! That's exactly what I was looking for. It looks like it'll be in v1.9 so I'll switch over to the dev branch later today and give it a try. Looks simple enough.
I have no idea why I didn't see that PR when I searched the repo, but many thanks for pointing me in the right direction.
-
This worked perfectly. Using the development branch for my NodeManager library and changing my 'void before()' to the following code presented the proper unit_of_measurement to my Home Assistant controller for the pressure sensor. Thanks for the assistance.
void before() { /********************************** * Configure your sensors **********************************/ // send unit prefixes to controller (i.e. V, A, hPa, %, etc.) nodeManager.setSendUnitPrefix(true); // let controller know ambient pressure sensor reports in hPa ambient.children.get(3)->setUnitPrefix("hPa"); // report ambient measurements every 15 minutes ambient.setReportIntervalMinutes(15); // report battery level every 60 minutes battery.setReportIntervalMinutes(60); // report radio signal level every 10 minutes signal.setReportIntervalMinutes(10); // only a pseudo SR_TX_RSSI and SR_UPLINK_QUALITY are available for NRF24 // radio. All other methods return as INVALID. signal.setSignalCommand(SR_UPLINK_QUALITY); // call NodeManager before routine nodeManager.before(); }