Damn; I think I may have just fixed it. Changed USB ports......
drock1985
Posts
-
MySensors lights not functioning correctly since upgrade to 0.61.1 -
MySensors lights not functioning correctly since upgrade to 0.61.1Is there any logs I can look through to find a solution?
-
MySensors lights not functioning correctly since upgrade to 0.61.1@martinhjelmare Hi,
The last version that worked correctly was 0.60.1; no issues at all. All other actuators seem to work fine too (Hue, ESP8266, Wemo, etc)
-
MySensors lights not functioning correctly since upgrade to 0.61.1Hi,
I've been using MySensors for a while now in their present hardware/software configuration with no problems running lights (relays), temp sensors, etc up until recently. I upgrade my HASS.IO install of home-assistant to 0.61.1 and ever since then I have not been able to get any of my light actuators to respond to commands from the UI. I do not know what is going on; and having not changed anything I do not think it's on my end. Was wondering what it could be? I connect to MySensors using a USB-Serial gateway.
Thanks
-
How to build an overridable MySensors relay based device (e.g. lamp with manual switch)I know this may sound weird, but I would recommend just going with the basic Sonoff switch and skip the MySensors part.
I build a lamp controlled by MySensors a long time ago, has external Tact button for on/off. Works great, took a while to build and I have an ugly box screwed to my lamp now that houses it all.
I wanted to build another, but didn't want it be be aesthetically displeasing. I ended up using these (https://www.itead.cc/sonoff-wifi-wireless-switch.html) and they are everything in one small package. You have wifi, a tact button for manual on/off, and it will report to any home automation system using MQTT after flashing some customer firmware (https://github.com/arendst/Sonoff-Tasmota). Just cut the power cable, screw into appropriate terminals and it's all good to go.
As much as I love MySensors; for this type of project I think there is a better solution.
-
Need help adding MySensors items to sitemapHi,
I'm new to OpenHab2, and have a rather newbie question.
I have OpenHab2 installed on my Raspberry Pi 2 with the MySensors plug-in installed and working with an Wifi-Gateway. I can add devices easily using discovery, and have gotten things like relays and temperature to show in the Paper UI easily. I'm not trying to work on creating the .sitemap and .item files in Notepad so I can build the UI the way I want for the iOS app. I'm stuck now on trying to get any data taht displays form text or number in the Basic UI part. Ex. I have a temperature and barometic pressure sensor that works fine in PaperUI, but not when I try to add it manually to the Basic UI.
Here is my weather.items and default.sitemap file
Number temp_living "Living Room Temperature [%.1f]" <temperature> { mysensors:temperature:ca1e2cbb:Temperature_5_1:temp } Number baro_living "Living Room Pressure [%.1f]" <temperature> { mysensors:baro:ca1e2cbb:Baro_5_0:pressure } Number upstairs_humidity "Upstairs Humidity [%.1f %%]" <temperature> { mysensors:humidity:ca1e2cbb:Humidity_1_0:hum } Number upstairs_temp "Upstairs Temperature [%.1f °C]" <temperature> { mysensors:temperature:ca1e2cbb:Temperature_1_1:temp }default.sitemap
sitemap default label="My first sitemap" { Switch item=light_mancave_1 label="Man Cave Lamp 1" Switch item=light_mancave_2 label="Man Cave Lamp 2" Text item=temp_living Text item=baro_living Switch item=NestSmoke_is_online label="Nest Online?" }Thanks,
-
Need some help with a Multi-Sensor NodeHi,
I'm working on making a multi-sensornode (PIR, Light, Temp and V_LIGHT (for night-light)), as well as a repeater node. So far though, I am having problems with the system reporting all the variables every second, instead of on change/every 10 seconds like I have in my sketch. I'm not sure where I am going wrong,. I need the device to only report changes, specifically on motion when it is detected, as well as to receive the V_STATUS message. Would someone please look over this and point me in the right direction? I've been looking at this off and on for a while now and I can't find anything that is majorly wrong.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Derrick Rockwell (@Drock1985) * * DESCRIPTION * * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 21 #include <SPI.h> #include <MySensors.h> #include <DallasTemperature.h> #include <OneWire.h> #include <BH1750.h> #include <Wire.h> unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds) #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No #define ONE_WIRE_BUS 4 // Pin where dallase sensor is connected #define LED_ARRAY_1 5 // Pin that controls the LED Light array (does not need to be a PWM pin) #define LED_ARRAY_2 6 #define MAX_ATTACHED_DS18B20 2 // #define MY_REPEATER_FEATURE //Enables Repeater feature for non-battery powered nodes. OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. int lastTemperature = 0; int numSensors=0; boolean receivedConfig = false; boolean metric = true; #define CHILD_ID_MOTION 1 // ID of the sensor child #define CHILD_ID_TEMP 2 // ID of Temperature Sensor #define CHILD_ID_LUX 3 // ID of Lux Sensor #define CHILD_ID_LIGHT 4 // ID of LED light array #define LIGHT_ON 1 #define LIGHT_OFF 0 BH1750 lightSensor; // Initialize messages MyMessage msgMotion(CHILD_ID_MOTION, V_TRIPPED); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); MyMessage msgLux(CHILD_ID_LUX, V_LEVEL); //Sets up custom units (this case LUX for Light) MyMessage msgPrefix(CHILD_ID_LUX, V_UNIT_PREFIX); // Sends controller the LUX value instead of % MyMessage msgLight(CHILD_ID_LIGHT, V_STATUS); uint16_t lastlux = 0; int compareMotion = LOW; bool stateLight = 0; // Place holders for the loop function to register nodes in Home-Assistant bool initialValueSentLight = 0; void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(LED_ARRAY_1, OUTPUT); // sets the LED Array as an output pinMode(LED_ARRAY_2, OUTPUT); // sets the LED Array as an output lightSensor.begin(); // Startup up the OneWire library sensors.begin(); // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); send(msgPrefix.set("lux")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("LuxMotionTempSensor", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOTION, S_MOTION); wait(150); present(CHILD_ID_TEMP, S_TEMP); wait(150); present(CHILD_ID_LUX, S_LIGHT_LEVEL); wait(150); present(CHILD_ID_LIGHT, S_LIGHT); } void loop() { if (!initialValueSentLight) { Serial.println("Sending initial value"); send(msgLight.set(stateLight?LIGHT_ON:LIGHT_OFF)); Serial.println("Requesting initial value from controller"); request(CHILD_ID_LIGHT, V_STATUS); wait(2000, C_SET, V_STATUS); } { uint16_t lux = lightSensor.readLightLevel();// Get Lux value if (lux != lastlux) { Serial.println(lux); Serial.println("Sending lux value"); send(msgLux.set(lux)); send(msgPrefix.set("lux")); lastlux = lux; } } // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); // Fetch and round temperature to one decimal int temperature = (((sensors.getTempCByIndex(0)) * 10.)) / 10.; if (lastTemperature != temperature && temperature != -127.00 && temperature != 85.00) Serial.println(temperature); Serial.println("Sending temperature");{ // Send in the new temperature send(msgTemp.set(temperature)); // Save new temperatures for next compare lastTemperature = temperature; } // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; // if (compareMotion != tripped) { Serial.println("Sending motion status"); Serial.println(tripped); send(msgMotion.set(tripped?"1":"0")); // Send tripped value to gw // compareMotion = tripped; // } // sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME); } void receive(const MyMessage &message) { if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_STATUS && message.sensor == CHILD_ID_LIGHT) { if (!initialValueSentLight) { Serial.println("Receiving initial value from controller"); initialValueSentLight = true; } // Change relay state stateLight = (bool)message.getInt(); digitalWrite(LED_ARRAY_1, stateLight?LIGHT_ON:LIGHT_OFF); digitalWrite(LED_ARRAY_2, stateLight?LIGHT_ON:LIGHT_OFF); send(msgLight.set(stateLight?LIGHT_ON:LIGHT_OFF)); } }Thanks,
-
Need a refresher on presentation and HAThanks, i finally got it. I went to the example you have on home-assistant.io and removed the button and added a second actuator. Works like it should now. You are the king!
Final code for anyone whom it may help/want it.
/* * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * http://www.mysensors.org/build/relay * * *Holiday LED Lights MySensors Module, for MySensors v2.0 * Nothing fancy, just a two actuator (on/off) virtual switch for small * low powred LED strings that normally run from a battery pack. * * */ #define MY_DEBUG #define MY_RADIO_NRF24 #define MY_REPEATER_FEATURE #define MY_NODE_ID 24 // or comment out for auto #include <SPI.h> #include <MySensors.h> #define MULTI_PIN 3 // Pin that Multi-Coloured LED string is connected to #define WHITE_PIN 5 // Pin that White LED string is connected to #define CHILD_ID_MULTI 1 // Child ID for Multi-Coloured LED String #define CHILD_ID_WHITE 2 // Child ID for White LED String #define MULTI_ON 1 #define MULTI_OFF 0 #define WHITE_ON 1 #define WHITE_OFF 0 bool stateMULTI = false; // Place holders for the loop function to register nodes in Home-Assistant bool initialValueSentMULTI = false; bool stateWHITE = false; bool initialValueSentWHITE = false; MyMessage msgMULTI(CHILD_ID_MULTI, V_STATUS); //Presentation of Switch for Multi-Coloured LEDS MyMessage msgWHITE(CHILD_ID_WHITE, V_STATUS); //Presentation of Switch for White LEDS void setup() { // Make sure relays are off when starting up digitalWrite(MULTI_PIN, MULTI_OFF); pinMode(MULTI_PIN, OUTPUT); digitalWrite(WHITE_PIN, WHITE_OFF); pinMode(WHITE_PIN, OUTPUT); } void presentation() { sendSketchInfo("HolidayDeskLights", "1.0"); present(CHILD_ID_MULTI, S_LIGHT); present(CHILD_ID_WHITE, S_LIGHT); } void loop() { if (!initialValueSentMULTI) { Serial.println("Sending initial value"); send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF)); Serial.println("Requesting initial value from controller"); request(CHILD_ID_MULTI, V_STATUS); wait(2000, C_SET, V_STATUS); } if (!initialValueSentWHITE) { Serial.println("Sending initial value"); send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF)); Serial.println("Requesting initial value from controller"); request(CHILD_ID_WHITE, V_STATUS); wait(2000, C_SET, V_STATUS); } } void receive(const MyMessage &message) { if (message.isAck()) { Serial.println("This is an ack from gateway"); } if (message.type == V_STATUS && message.sensor == CHILD_ID_MULTI) { if (!initialValueSentMULTI) { Serial.println("Receiving initial value from controller"); initialValueSentMULTI = true; } // Change relay state stateMULTI = (bool)message.getInt(); digitalWrite(MULTI_PIN, stateMULTI?MULTI_ON:MULTI_OFF); send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF)); } if (message.type == V_STATUS && message.sensor == CHILD_ID_WHITE) { if (!initialValueSentWHITE) { Serial.println("Receiving initial value from controller"); initialValueSentWHITE = true; } // Change relay state stateWHITE = (bool)message.getInt(); digitalWrite(WHITE_PIN, stateWHITE?WHITE_ON:WHITE_OFF); send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF)); } } -
Need a refresher on presentation and HAI added a wait into the presentation, and that got rid of the fail message. Now I am trying to send the initial value (so that HA will register it) and it does not seem to be working. I also added the sending of the status in the receive message, here is an updated sketch and my debug log. What could I be missing?
Thanks again!
Starting repeater (RNNRA-, 2.0.0) TSM:INIT TSM:RADIO:OK TSP:ASSIGNID:OK (ID=24) TSM:FPAR TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSM:FPAR TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSP:MSG:READ 4-4-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1 TSP:MSG:FPAR RES (ID=4, dist=1) TSP:MSG:PAR OK (ID=4, dist=2) TSP:MSG:READ 0-0-24 s=255,c=3,t=8,pt=1,l=1,sg=0:0 TSP:MSG:FPAR RES (ID=0, dist=0) TSP:MSG:PAR OK (ID=0, dist=1) TSP:MSG:READ 2-2-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1 TSP:MSG:FPAR RES (ID=2, dist=1) TSM:FPAR:OK TSM:ID TSM:CHKID:OK (ID=24) TSM:UPL TSP:PING:SEND (dest=0) TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1 TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1 TSP:MSG:PONG RECV (hops=1) TSP:CHKUPL:OK TSM:UPL:OK TSM:READY TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100 TSP:MSG:SEND 24-24-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0 TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0 TSP:MSG:READ 0-0-24 s=255,c=3,t=15,pt=6,l=2,sg=0:0100 TSP:MSG:READ 0-0-24 s=255,c=3,t=6,pt=0,l=1,sg=0:M TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Holiday Desk Light TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0 TSP:MSG:SEND 24-24-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok: TSP:MSG:SEND 24-24-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok: NODE:!REG NODE:!REG Request registration... TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2 TSP:MSG:READ 0-0-24 s=255,c=3,t=27,pt=1,l=1,sg=0:1 Node registration=1 Init complete, id=24, parent=0, distance=1, registration=1 TSP:SANCHK:OK TSP:MSG:READ 1-1-255 s=255,c=3,t=7,pt=0,l=0,sg=0: TSP:MSG:BC TSP:MSG:FPAR REQ (sender=1) TSP:PING:SEND (dest=0) TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1 TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1 TSP:MSG:PONG RECV (hops=1) TSP:CHKUPL:OK TSP:MSG:GWL OK TSP:MSG:SEND 24-24-1-1 s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=ok:1 TSP:SANCHK:OKsketch
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #define LIGHTS_MULTI 3 #define LIGHTS_WHITE 5 #define CHILD_ID_MULTI 1 #define CHILD_ID_WHITE 2 #define LIGHTS_MULTI_ON 1 // GPIO value to write to turn on attached relay #define LIGHTS_MULTI_OFF 0 // GPIO value to write to turn off attached relay #define LIGHTS_WHITE_ON 1 // GPIO value to write to turn on attached relay #define LIGHTS_WHITE_OFF 0 // GPIO value to write to turn off attached relay MyMessage msgMULTI(CHILD_ID_MULTI, V_LIGHT); MyMessage msgWHITE(CHILD_ID_WHITE, V_LIGHT); void before() { // Then set relay pins in output mode pinMode(LIGHTS_MULTI, OUTPUT); pinMode(LIGHTS_WHITE, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(LIGHTS_MULTI, loadState(CHILD_ID_MULTI)?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF); digitalWrite(LIGHTS_WHITE, loadState(CHILD_ID_WHITE)?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF); } void setup() { // present(255, 18); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Holiday Desk Light", "1.0"); present(CHILD_ID_MULTI, S_LIGHT); wait(150); present(CHILD_ID_WHITE, S_LIGHT); wait(150); send(msgMULTI.set(1)); wait(150); send(msgWHITE.set(1)); } void loop() { } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT && message.sensor == CHILD_ID_MULTI) { // Change relay state digitalWrite(LIGHTS_MULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF); send(msgMULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } if (message.type==V_LIGHT && message.sensor == CHILD_ID_WHITE) { // Change relay state digitalWrite(LIGHTS_WHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF); send(msgWHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
Need a refresher on presentation and HAHi,
I took a bit of a hiatus from this site/Arduino and now can't for the life of me debug a presentation on a node with two LED lights.
Here is the errors I am getting during presentation:
Starting repeater (RNNRA-, 2.0.0) TSM:INIT TSM:RADIO:OK TSP:ASSIGNID:OK (ID=24) TSM:FPAR TSP:MSG:SEND 24-24-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc: TSP:MSG:READ 4-4-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1 TSP:MSG:FPAR RES (ID=4, dist=1) TSP:MSG:PAR OK (ID=4, dist=2) TSP:MSG:READ 0-0-24 s=255,c=3,t=8,pt=1,l=1,sg=0:0 TSP:MSG:FPAR RES (ID=0, dist=0) TSP:MSG:PAR OK (ID=0, dist=1) TSP:MSG:READ 2-2-24 s=255,c=3,t=8,pt=1,l=1,sg=0:1 TSP:MSG:FPAR RES (ID=2, dist=1) TSM:FPAR:OK TSM:ID TSM:CHKID:OK (ID=24) TSM:UPL TSP:PING:SEND (dest=0) TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1 TSP:MSG:READ 0-0-24 s=255,c=3,t=25,pt=1,l=1,sg=0:1 TSP:MSG:PONG RECV (hops=1) TSP:CHKUPL:OK TSM:UPL:OK TSM:READY TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100 TSP:MSG:SEND 24-24-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0 TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0 TSP:MSG:READ 0-0-24 s=255,c=3,t=15,pt=6,l=2,sg=0:0100 TSP:MSG:READ 0-0-24 s=255,c=3,t=6,pt=0,l=1,sg=0:M TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=ok:Holiday Desk Light TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0 TSP:MSG:SEND 24-24-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok: !TSP:MSG:SEND 24-24-0-0 s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=fail: NODE:!REG NODE:!REG Request registration... TSP:MSG:SEND 24-24-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=1,st=ok:2 TSP:MSG:READ 0-0-24 s=255,c=3,t=27,pt=1,l=1,sg=0:1 Node registration=1 Init complete, id=24, parent=0, distance=1, registration=1and here is my sketch
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Example sketch showing how to control physical relays. * This example will remember relay state after power failure. * http://www.mysensors.org/build/relay */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // Enable repeater functionality for this node #define MY_REPEATER_FEATURE #include <SPI.h> #include <MySensors.h> #define LIGHTS_MULTI 3 #define LIGHTS_WHITE 5 #define CHILD_ID_MULTI 1 #define CHILD_ID_WHITE 2 #define LIGHTS_MULTI_ON 1 // GPIO value to write to turn on attached relay #define LIGHTS_MULTI_OFF 0 // GPIO value to write to turn off attached relay #define LIGHTS_WHITE_ON 1 // GPIO value to write to turn on attached relay #define LIGHTS_WHITE_OFF 0 // GPIO value to write to turn off attached relay MyMessage msgMULTI(CHILD_ID_MULTI, V_LIGHT); MyMessage msgWHITE(CHILD_ID_WHITE, V_LIGHT); void before() { // Then set relay pins in output mode pinMode(LIGHTS_MULTI, OUTPUT); pinMode(LIGHTS_WHITE, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(LIGHTS_MULTI, loadState(1)?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF); digitalWrite(LIGHTS_WHITE, loadState(2)?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF); } void setup() { // present(255, 18); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Holiday Desk Light", "1.0"); present(CHILD_ID_MULTI, S_LIGHT); present(CHILD_ID_WHITE, S_LIGHT); send(msgMULTI.set(1)); send(msgWHITE.set(1)); } void loop() { } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT && message.sensor == CHILD_ID_MULTI) { // Change relay state digitalWrite(LIGHTS_MULTI, message.getBool()?LIGHTS_MULTI_ON:LIGHTS_MULTI_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } if (message.type==V_LIGHT && message.sensor == CHILD_ID_WHITE) { // Change relay state digitalWrite(LIGHTS_WHITE, message.getBool()?LIGHTS_WHITE_ON:LIGHTS_WHITE_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } }Anyone help a born-again newb? :{
Thanks
-
💬 MySensors Stable Node V2Loving the addons.
Would it be possible to add an optional hole mount and amplifier to make this the equivalent of the PA+LNA version?
-
Alternative to ArduinoIDEThis is a good thread; been recently contemplating changing IDE's myself.
Visual Studio seems to be the most complete - I think I will give this one a try. Anyone have any tips for how to use this coming from the Arduino IDE (with no previous programming experience?)
Thanks,
-
Help with Switch/Case/Break statementThanks for the help. I see now where I was going wrong. I have everything working as expected. The only thing I needed to do was add some special commands to the message statement. For some reason, the relay would not turn off when the water low level was reached; used this below as a counter for now.
Thanks again.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Automated Sump-Pump for De-Humidifier * * PURPOSE: * To automatically when water is at a pre-set level, have small * sump pump engage and empty water until it hits the desired * level. Uses the NewPING Library with Ultrasonic Sensor HC-SR04 * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 22 //or comment out for automatic // #define MY_REPEATER_FEATURE // Enabled repeater feature for this node #include <SPI.h> #include <MySensors.h> #include <NewPing.h> #define RELAY_PIN 3 // To control the sump pump, define relay pin here. #define TRIGGER_PIN 4 //HC-SR04 Trgger Pin (Transmit) #define ECHO_PIN 5 //HC-SR04 Echo Pin (Receive) #define MAX_DISTANCE 100 //Maximum Distance for Sensor scan (tank depth) no more than 297f int LOW_WATER = 2; // int HIGH_WATER = 20; // int RADIUS = 15; //Radius of cylindrical bucket. Used for Flow calculations int bucketDepth = 30; int waterDepth = 5; unsigned long SEND_VOLUME = 0; // Trigger to send flow values to HA controller unsigned long WATER_VOLUME = 0; // Just a place holder.... unsigned long previousMillis = 0; //Tracks time list last depth report. unsigned long reportMillis = 10000; //How often to do depth report unsigned long manualWait = 20000; //Time for manual pump on action. 20 seconds default (to avoid pump dryout) long unsigned int Distance = 5; long unsigned int oldDepth = 0; //used to track transmission of water level on change only. #define CHILD_ID_RELAY 0 //To allow manual control of the sump pump from HA controller #define CHILD_ID_DEPTH 1 // Used to show water depth. #define CHILD_ID_VOLUME 2 // Sensor to send Water Volume info NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum depth // MySensors Message Initialization MyMessage msgRelay(CHILD_ID_RELAY, V_LIGHT); MyMessage msgDepth(CHILD_ID_DEPTH, V_DISTANCE); MyMessage msgPrefix(CHILD_ID_DEPTH, V_UNIT_PREFIX); //Adds SI unit (CM) for depth measurement. MyMessage msgVolume(CHILD_ID_VOLUME, V_VOLUME); // Water volume info. In Metres cubed unsigned long previousReport = 0; // For tracking report time void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); send(msgPrefix.set("CM")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("DeHumidifierSumpPump", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_DEPTH, S_DISTANCE); present(CHILD_ID_VOLUME, S_WATER); send(msgPrefix.set("CM")); } void loop() { unsigned long currentMillis = millis(); Distance = sonar.ping_cm(); waterDepth = (bucketDepth - Distance); if (waterDepth >= HIGH_WATER && SEND_VOLUME == 0){ digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); SEND_VOLUME = 1; } else if ( (waterDepth <= LOW_WATER) && SEND_VOLUME == 1 ) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); SEND_VOLUME = 0; } if ( (currentMillis - previousMillis) >= reportMillis) { send(msgDepth.set(Distance)); send(msgPrefix.set("CM")); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (waterDepth)) / 1000); send(msgVolume.set(WATER_VOLUME)); previousMillis = currentMillis; } wait(reportMillis); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if ((message.type==V_LIGHT) && (waterDepth >= LOW_WATER)) { // Change pump state for 20 seconds. digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); wait(manualWait); digitalWrite(RELAY_PIN, LOW); send(msgRelay.set(0)); } } -
Help with Switch/Case/Break statementOk, did a bit more digging. I think I finally got this.
Mixed up in my mind how I wanted to measure the water level. Think I have the logic finally figured out in my illogical head.
Thanks for all the help guys; good to network brains every once in while :)
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Automated Sump-Pump for De-Humidifier * * PURPOSE: * To automatically when water is at a pre-set level, have small * sump pump engage and empty water until it hits the desired * level. Uses the NewPING Library with Ultrasonic Sensor HC-SR04 * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 22 //or comment out for automatic // #define MY_REPEATER_FEATURE // Enabled repeater feature for this node #include <SPI.h> #include <MySensors.h> #include <NewPing.h> #define RELAY_PIN 3 // To control the sump pump, define relay pin here. #define TRIGGER_PIN 4 //HC-SR04 Trgger Pin (Transmit) #define ECHO_PIN 5 //HC-SR04 Echo Pin (Receive) #define MAX_DISTANCE 100 //Maximum Distance for Sensor scan (tank depth) no more than 297f int LOW_WATER = 2; // int HIGH_WATER = 20; // int RADIUS = 15; //Radius of cylindrical bucket. Used for Flow calculations int bucketDepth = 30; int waterDepth = 5; unsigned long SEND_FLOW = 0; // Trigger to send flow values to HA controller unsigned long WATER_VOLUME = 0; // Just a place holder.... unsigned long previousMillis = 0; //Tracks time list last depth report. unsigned long reportMillis = 10000; //How often to do depth report long unsigned int Distance = 5; long unsigned int oldDepth = 0; //used to track transmission of water level on change only. #define CHILD_ID_RELAY 0 //To allow manual control of the sump pump from HA controller #define CHILD_ID_DEPTH 1 // Used to show water depth. #define CHILD_ID_FLOW 2 // Sensor to send flow/water volume info NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum depth // MySensors Message Initialization MyMessage msgRelay(CHILD_ID_RELAY, V_LIGHT); MyMessage msgDepth(CHILD_ID_DEPTH, V_DISTANCE); MyMessage msgPrefix(CHILD_ID_DEPTH, V_UNIT_PREFIX); //Adds SI unit (CM) for depth measurement. MyMessage msgVolume(CHILD_ID_FLOW, V_VOLUME); // Water flow info. In METRES! unsigned long previousReport = 0; // For tracking report time void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); send(msgPrefix.set("CM")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("DeHumidifierSumpPump", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_DEPTH, S_DISTANCE); present(CHILD_ID_FLOW, S_WATER); send(msgPrefix.set("CM")); } void loop() { unsigned long currentMillis = millis(); Distance = sonar.ping_cm(); waterDepth = (bucketDepth - Distance); if (waterDepth >= HIGH_WATER && SEND_FLOW == 0){ digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); SEND_FLOW = 1; } else if ( (waterDepth <= LOW_WATER) && SEND_FLOW == 1) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (bucketDepth - waterDepth)) / 1000); send(msgVolume.set(WATER_VOLUME)); SEND_FLOW = 0; } else if ( (currentMillis - previousMillis) >= reportMillis) { send(msgDepth.set(Distance)); send(msgPrefix.set("CM")); previousMillis = currentMillis; } else if ((RELAY_PIN == HIGH) && (waterDepth <= LOW_WATER)) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); Distance = sonar.ping_cm(); waterDepth = (bucketDepth - Distance); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (bucketDepth - waterDepth)) / 1000); send(msgVolume.set(WATER_VOLUME)); } wait(100); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if ((message.type==V_LIGHT) && (waterDepth != LOW_WATER)) { // Change relay state digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); // Store state in eeprom // saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
Help with Switch/Case/Break statementI think i've got it; but for some reason my sensor is a lot more sensitive when using my sketch versus the example one that came with the library. I can go to a reliable resolution of up to 2-5CM using the example sketch; and only ~10 (the cutoff limit I was using in the sketch) when all combined.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Automated Sump-Pump for De-Humidifier * * PURPOSE: * To automatically when water is at a pre-set level, have small * sump pump engage and empty water until it hits the desired * level. Uses the NewPING Library with Ultrasonic Sensor HC-SR04 * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 22 //or comment out for automatic // #define MY_REPEATER_FEATURE // Enabled repeater feature for this node #include <SPI.h> #include <MySensors.h> #include <NewPing.h> #define RELAY_PIN 3 // To control the sump pump, define relay pin here. // #define RELAY_ON HIGH // #define RELAY_OFF LOW #define TRIGGER_PIN 4 //HC-SR04 Trgger Pin (Transmit) #define ECHO_PIN 5 //HC-SR04 Echo Pin (Receive) #define MAX_DISTANCE 100 //Maximum Distance for Sensor scan (tank depth) no more than 297f int LOW_WATER = 2; // Distance from face of sensor to top of water at low level (where pump will disengage) int HIGH_WATER = 30; // Distance from face of sensor to top of water at high point (when pump will engage) int RADIUS = 15; //Radius of cylindrical bucket. Used for Flow calculations int bucketDepth = 30; int waterDepth = 5; unsigned long SEND_FLOW = 0; // Trigger to send flow values to HA controller unsigned long WATER_VOLUME = 0; // Just a place holder.... unsigned long previousMillis = 0; //Tracks time list last depth report. unsigned long reportMillis = 10000; //How often to do depth report long unsigned int Distance = 5; long unsigned int oldDepth = 0; //used to track transmission of water level on change only. #define CHILD_ID_RELAY 0 //To allow manual control of the sump pump from HA controller #define CHILD_ID_DEPTH 1 // Used to show water depth. #define CHILD_ID_FLOW 2 // Sensor to send flow/water volume info NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum depth // MySensors Message Initialization MyMessage msgRelay(CHILD_ID_RELAY, V_LIGHT); MyMessage msgDepth(CHILD_ID_DEPTH, V_DISTANCE); MyMessage msgPrefix(CHILD_ID_DEPTH, V_UNIT_PREFIX); //Adds SI unit (CM) for depth measurement. MyMessage msgVolume(CHILD_ID_FLOW, V_VOLUME); // Water flow info. In METRES! unsigned long previousReport = 0; // For tracking report time void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); send(msgPrefix.set("CM")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("DeHumidifierSumpPump", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_DEPTH, S_DISTANCE); present(CHILD_ID_FLOW, S_WATER); send(msgPrefix.set("CM")); } void loop() { unsigned long currentMillis = millis(); Distance = sonar.ping_cm(); waterDepth = (bucketDepth - Distance); if (waterDepth == HIGH_WATER && SEND_FLOW == 0){ digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); SEND_FLOW = 1; } else if ( (waterDepth <= LOW_WATER) && SEND_FLOW == 1) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (bucketDepth - waterDepth)) / 1000); send(msgVolume.set(WATER_VOLUME)); SEND_FLOW = 0; } else if ( (currentMillis - previousMillis) >= reportMillis) { send(msgDepth.set(Distance)); send(msgPrefix.set("CM")); previousMillis = currentMillis; } else if ((RELAY_PIN == HIGH) && (waterDepth == LOW_WATER)) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (bucketDepth - waterDepth)) / 1000); send(msgVolume.set(WATER_VOLUME)); } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if ((message.type==V_LIGHT) && (waterDepth != LOW_WATER)) { // Change relay state digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); // Store state in eeprom // saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
Help with Switch/Case/Break statementYes, high stats it low stops it.
I have been working with the IF statements but I am still having an issue. I'm getting some weird behaviour with the code. When it first starts up and the ultrasonic sensor is more than ~5cm from an object, it works ok and the relay stays off. If I put something close in front of the sensor, the relay turns on but it keeps spamming the message to the gateway (even when it should not). Also, if you move that object away from the front of the ultrasonic sensor, the relay stays on.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Automated Sump-Pump for De-Humidifier * * PURPOSE: * To automatically when water is at a pre-set level, have small * sump pump engage and empty water until it hits the desired * level. Uses the NewPING Library with Ultrasonic Sensor HC-SR04 * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 22 //or comment out for automatic // #define MY_REPEATER_FEATURE // Enabled repeater feature for this node #include <SPI.h> #include <MySensors.h> #include <NewPing.h> #define RELAY_PIN 3 // To control the sump pump, define relay pin here. // #define RELAY_ON HIGH // #define RELAY_OFF LOW #define TRIGGER_PIN 4 //HC-SR04 Trgger Pin (Transmit) #define ECHO_PIN 5 //HC-SR04 Echo Pin (Receive) #define MAX_DISTANCE 100 //Maximum Distance for Sensor scan (tank depth) no more than 297f #define LOW_WATER 30 // Distance from face of sensor to top of water at low level (where pump will disengage) #define HIGH_WATER 5 // Distance from face of sensor to top of water at high point (when pump will engage) #define RADIUS 15 //Radius of cylindrical bucket. Used for Flow calculations unsigned long SEND_FLOW = 0; // Trigger to send flow values to HA controller unsigned long WATER_VOLUME = 0; // Just a place holder.... unsigned long previousMillis = 0; //Tracks time list last depth report. unsigned long reportMillis = 10000; //How often to do depth report long unsigned int Depth = 5; long unsigned int oldDepth = 0; //used to track transmission of water level on change only. #define CHILD_ID_RELAY 0 //To allow manual control of the sump pump from HA controller #define CHILD_ID_DEPTH 1 // Used to show water depth. #define CHILD_ID_FLOW 2 // Sensor to send flow/water volume info NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum depth // MySensors Message Initialization MyMessage msgRelay(CHILD_ID_RELAY, V_LIGHT); MyMessage msgDepth(CHILD_ID_DEPTH, V_DISTANCE); MyMessage msgPrefix(CHILD_ID_DEPTH, V_UNIT_PREFIX); //Adds SI unit (CM) for depth measurement. MyMessage msgVolume(CHILD_ID_FLOW, V_VOLUME); // Water flow info. In METRES! unsigned long previousReport = 0; // For tracking report time void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); send(msgPrefix.set("CM")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("DeHumidifierSumpPump", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_DEPTH, S_DISTANCE); present(CHILD_ID_FLOW, S_WATER); send(msgPrefix.set("CM")); } void loop() { unsigned long currentMillis = millis(); Depth = sonar.ping_cm(); if (Depth == HIGH_WATER){ digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); SEND_FLOW = 1; } if ( (Depth == LOW_WATER) && SEND_FLOW == 1) { digitalWrite(RELAY_PIN, LOW); send(msgRelay.set (0)); WATER_VOLUME = ((((sq(RADIUS)) * 3.14) * (LOW_WATER - Depth)) / 1000); send(msgVolume.set(WATER_VOLUME)); SEND_FLOW = 0; } if ( (currentMillis - previousMillis) >= reportMillis) { send(msgDepth.set(Depth)); send(msgPrefix.set("CM")); previousMillis = currentMillis; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { // Change relay state digitalWrite(RELAY_PIN, HIGH); send(msgRelay.set(1)); // Store state in eeprom // saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
Help with Switch/Case/Break statementI'm trying to set it up so that if the depth changes, it will report the new one back to the HA controller.
I was working with the IF/Else statemetns at first, but my Arduino kept running the code and clogging my serial console and sending reports to my HA controller. I was going to use a sleep command to make it only check once every X seconds/minutes, but I wanted to be able to add a manual empty switch for emergency use. Since the If/Else was clogging the console, thought Switch/Case would work better.
I'll keep looking into this. Thanks for the help.
-
Help with Switch/Case/Break statementHi,
I'm working on building a pump to empty my De-humidifier for me automatically. I have the components connected, but I cannot get the Switch/Case statement to work/compile for me. I'm not sure where i'm going wrong. The compiler complains about a duplicate case, but i'm not sure why. I know it's in the LOW_WATER statement. This is the first time i've used this form of statement; i'm probably missing something small. Any help is appreciated.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * * DESCRIPTION * Automated Sump-Pump for De-Humidifier * * PURPOSE: * To automatically when water is at a pre-set level, have small * sump pump engage and empty water until it hits the desired * level. Uses the NewPING Library with Ultrasonic Sensor HC-SR04 * */ // Enable debug prints #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 22 //or comment out for automatic // #define MY_REPEATER_FEATURE // Enabled repeater feature for this node #include <SPI.h> #include <MySensors.h> #include <NewPing.h> unsigned long REPORT_TIME = 60000; // Sleep time between sensor readings #define RELAY_PIN 3 // To control the sump pump, define relay pin here. #define RELAY_ON HIGH #define RELAY_OFF LOW #define TRIGGER_PIN 4 //HC-SR04 Trgger Pin (Transmit) #define ECHO_PIN 5 //HC-SR04 Echo Pin (Receive) #define MAX_DISTANCE 50 //Maximum Distance for Sensor scan (tank depth) no more than 297fu #define RADIUS 15 //Radius of cylindrical bucket. Used for Flow calculations unsigned long SEND_FLOW = 0; // Trigger to send flow values to HA controller unsigned long WATER_VOLUME = 0; unsigned int Depth = 5; unsigned int HIGH_WATER = 5; // Distance from face of sensor to top of water at high point (when pump will engage) unsigned int LOW_WATER = 30; // Distance from face of sensor to top of water at low level (where pump will disengage) #define CHILD_ID_RELAY 0 //To allow manual control of the sump pump from HA controller #define CHILD_ID_DEPTH 1 // Used to show water depth. #define CHILD_ID_FLOW 2 // Sensor to send flow/water volume info NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum depth // MySensors Message Initialization MyMessage msgRelay(CHILD_ID_RELAY, V_LIGHT); MyMessage msgDepth(CHILD_ID_DEPTH, V_DISTANCE); MyMessage msgPrefix(CHILD_ID_DEPTH, V_UNIT_PREFIX); //Adds SI unit (CM) for depth measurement. MyMessage msgFlow(CHILD_ID_FLOW, V_VOLUME); // Water flow info. In METRES! unsigned long previousDepth = 0; // For tracking report time void setup() { pinMode(RELAY_PIN, OUTPUT); digitalWrite(RELAY_PIN, LOW); send(msgPrefix.set("CM")); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("DeHumidifierSumpPump", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_RELAY, S_LIGHT); present(CHILD_ID_DEPTH, S_DISTANCE); present(CHILD_ID_FLOW, S_WATER); send(msgPrefix.set("CM")); } void loop() { // put your main code here, to run repeatedly: Depth = sonar.ping_cm(); switch (Depth) { case '= LOW_WATER': digitalWrite(RELAY_PIN. RELAY_OFF); send(msgRelay.set (0)); SEND_FLOW = 1; break; case '= HIGH_WATER': digitalWrite(RELAY_PIN, RELAY_ON); send(msgRelay.set(1)); break; case '!= Depth': send(msgDepth.set(Depth)); previousDepth = Depth; break; } if (RELAY_PIN == RELAY_OFF && Depth == LOW_WATER && SEND_FLOW == 1) { WATER_VOLUME = (((sq(RADIUS)) * 3.14) * (LOW_WATER - Depth) / 1000); send(msgFlow.set(WATER_VOLUME)); SEND_FLOW = 0; } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { // Change relay state digitalWrite(RELAY_PIN, RELAY_ON); send(msgRelay.set(1)); // Store state in eeprom // saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); } } -
unable to open USB portNo problem; just glad to hear you got it working. Everyone is new sometime.
FYI I made quite a few mistakes in the configuration.yaml file - took me a while to realize spaces were important ;)
Let us know if you have any other problems.
-
unable to open USB portNot sure what else to tell you. Like Martin said, for a node to appear at all in HA; it must do two things. 1) send the full presentation on the node start. Easiest way to do that is to start HA, and after HA is fully started put power to your motion sensor. 2) It must send a valid sensor status. In the case of a motion sensor, I believe it is either 1 or 0 (1 being motion detected, 0 being none).
The only thing I can see is maybe the / needs to be in front of home. Can't see it causing this many issues though.
mysensors: gateways: - device: '/dev/ttyUSB0' persistence_file: '/home/pi/.homeassistant/mysensors.json' baud_rate: 115200 debug: false persistence: trueOther than that i'm not sure what else to suggest. If everything is configured right, it should see it. You may also want to check out the debug part of MySensors config and HA to better determine your issue. @martinhjelmare help me with that issue some time ago.