@dbemowsk Any progress I want to do this as well?
DrJeff
Posts
-
Ceiling fan/light node -
RGB LED strip@maghac Oh yes by the way the code above works great just added some code for Motion sensor and Now I have a much better light.
/** * 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. * * LED STRIP sketch for Mysensors ******************************* * * REVISION HISTORY * 1.0 * Based on the example sketch in mysensors * 1.1 * fadespeed parameter (send as V_VAR1 message) * HomeAssistant compatible (send status to ack) * 1.2 * OTA support * 1.3 * Power-on self test * 1.4 * Bug fix * 1.5 * Other default values * 1.6 * Repeater feature * 1.7 * Multitasking. Alarm, Relax and normal modes. */ #define MY_OTA_FIRMWARE_FEATURE #define MY_REPEATER_FEATURE #define MY_NODE_ID 31 // added all the motion stuff DrJeff September 10, 2017 #define MOTION_1 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define MOTION_ID 90 // Id of the sensor child uint8_t lastMotion_1 = 0; unsigned long previousMillis1 = 0; unsigned long motionDelay1 = 10000; // interval at which to keep motion sensor trippped (milliseconds). Used to prevent too frequent updates to Vera. /// #define MY_RADIO_NRF24 #define MY_DEBUG #include <MySensors.h> #define CHILD_ID_LIGHT 1 #define SN "LED Strip" #define SV "1.7" MyMessage lightMsg(CHILD_ID_LIGHT, V_LIGHT); MyMessage rgbMsg(CHILD_ID_LIGHT, V_RGB); MyMessage dimmerMsg(CHILD_ID_LIGHT, V_DIMMER); // added all the motion stuff DrJeff September 10, 2017 MyMessage motion(MOTION_ID, V_TRIPPED); // int current_r = 255; int current_g = 255; int current_b = 255; int target_r = 255; int target_g = 255; int target_b = 255; int save_r; int save_g; int save_b; float delta_r = 0.0; float delta_g = 0.0; float delta_b = 0.0; char rgbstring[] = "ffffff"; int on_off_status = 0; int dimmerlevel = 100; int fadespeed = 20; unsigned long last_update = 0; int tick_length = 10; int fade_step = 0; int program_timer; int program_cycle; #define REDPIN 6 #define GREENPIN 4 #define BLUEPIN 5 #define LIGHT_NORMAL 0 #define LIGHT_FADING 1 #define PROGRAM_NORMAL 0 #define PROGRAM_ALARM 1 #define PROGRAM_RELAX 2 int light_mode = LIGHT_NORMAL; int program_mode = PROGRAM_NORMAL; #define RELAX_SPEED 50 #define MAX_CYCLES_RELAX 7 const int program_param_RELAX[MAX_CYCLES_RELAX][3] = { {255, 32, 0}, {255, 32, 16}, {255, 16, 32}, {255, 128, 0}, {255, 32, 00}, {255, 32, 32}, {255, 0, 32} }; void setup() { // Fix the PWM timer. Without this the LEDs will flicker. TCCR0A = _BV(COM0A1) | _BV(COM0B1) | _BV(WGM00); // Output pins pinMode(REDPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BLUEPIN, OUTPUT); // added all the motion stuff DrJeff September 10, 2017 pinMode(MOTION_1, INPUT); // } void presentation() { // Send the Sketch Version Information to the Gateway sendSketchInfo(SN, SV); present(CHILD_ID_LIGHT, S_RGB_LIGHT); // added all the motion stuff DrJeff September 10, 2017 present(MOTION_ID, S_MOTION); // } void selftest() { on_off_status = 1; current_r = 255; current_g = 0; current_b = 0; set_hw_status(); wait(100); current_r = 0; current_g = 255; set_hw_status(); wait(100); current_g = 0; current_b = 255; set_hw_status(); wait(100); current_r = 255; current_g = 255; set_hw_status(); wait(100); on_off_status = 0; } void loop() { static bool first_message_sent = false; if ( first_message_sent == false ) { selftest(); set_hw_status(); send_status(1, 1, 1); first_message_sent = true; } // added all the motion stuff DrJeff September 10, 2017//loop for motion unsigned long currentMillis = millis(); if(currentMillis - previousMillis1 > motionDelay1) { uint8_t motionDetect1 = digitalRead(MOTION_1); if(motionDetect1 != lastMotion_1) { Serial.print("Motion 1 = "); Serial.println(motionDetect1); // gw.send(motionStatus_1.set(motionDetect1 ? "1" : "0")); // Send tripped value to gw send(motion.set(motionDetect1)); if(motionDetect1 == 1) { previousMillis1 = currentMillis; //"Tripped" delay } else { previousMillis1 = currentMillis - motionDelay1 + 1000; //"Not tripped" delay for 1 second to stop rapid "not tripped" and "tripped" updates to Vera } lastMotion_1 = motionDetect1; } } //end of motion loop unsigned long now = millis(); if (now - last_update > tick_length) { last_update = now; if (light_mode == LIGHT_FADING) { calc_fade(); } if (program_mode > PROGRAM_NORMAL) { handle_program(); } } set_hw_status(); } void receive(const MyMessage &message) { int val; if (message.type == V_RGB) { Serial.print( "V_RGB: " ); Serial.println(message.data); long number = (long) strtol( message.data, NULL, 16); // Save old value strcpy(rgbstring, message.data); // Split it up into r, g, b values int r = number >> 16; int g = number >> 8 & 0xFF; int b = number & 0xFF; init_fade(fadespeed, r, g, b); send_status(0, 0, 1); } else if (message.type == V_LIGHT || message.type == V_STATUS) { Serial.print( "V_LIGHT: " ); Serial.println(message.data); val = atoi(message.data); if (val == 0 or val == 1) { on_off_status = val; send_status(1, 0, 0); } } else if (message.type == V_DIMMER || message.type == V_PERCENTAGE) { Serial.print( "V_DIMMER: " ); Serial.println(message.data); val = atoi(message.data); if (val >= 0 and val <=100) { dimmerlevel = val; send_status(0, 1, 0); } } else if (message.type == V_VAR1 ) { Serial.print( "V_VAR1: " ); Serial.println(message.data); val = atoi(message.data); if (val >= 0 and val <= 2000) { fadespeed = val; } } else if (message.type == V_VAR2 ) { Serial.print( "V_VAR2: " ); Serial.println(message.data); val = atoi(message.data); if (val == PROGRAM_NORMAL) { stop_program(); } else if (val == PROGRAM_ALARM || val == PROGRAM_RELAX) { init_program(val); } } else { Serial.println( "Invalid command received..." ); return; } } void set_rgb(int r, int g, int b) { analogWrite(REDPIN, r); analogWrite(GREENPIN, g); analogWrite(BLUEPIN, b); } void init_program(int program) { program_mode = program; program_cycle = 0; save_rgb(); if (program == PROGRAM_ALARM) { light_mode = LIGHT_NORMAL; current_r = 255; current_g = 255; current_b = 255; program_timer = 50; } else if (program == PROGRAM_RELAX) { program_timer = 300; init_fade(fadespeed, program_param_RELAX[program_cycle][0], program_param_RELAX[program_cycle][1], program_param_RELAX[program_cycle][2]); } } void handle_program() { program_timer--; if (program_mode == PROGRAM_ALARM) { if (program_timer == 0) { program_timer = 50; if (program_cycle == 0) { program_cycle = 1; current_r = 0; current_g = 0; current_b = 0; } else { program_cycle = 0; current_r = 255; current_g = 255; current_b = 255; } } } else if (program_mode == PROGRAM_RELAX) { if (light_mode == LIGHT_NORMAL) { program_cycle = (program_cycle+1) % MAX_CYCLES_RELAX; Serial.print("Next cycle step "); Serial.println(program_cycle); init_fade(fadespeed * RELAX_SPEED, program_param_RELAX[program_cycle][0], program_param_RELAX[program_cycle][1], program_param_RELAX[program_cycle][2]); } } } void stop_program() { restore_rgb(); light_mode = LIGHT_NORMAL; program_mode = PROGRAM_NORMAL; } void save_rgb() { save_r = current_r; save_g = current_g; save_b = current_b; } void restore_rgb() { current_r = save_r; current_g = save_g; current_b = save_b; } void init_fade(int t, int r, int g, int b) { Serial.print( "Init fade" ); light_mode = LIGHT_FADING; target_r = r; target_g = g; target_b = b; fade_step = t; delta_r = (target_r - current_r) / float(fade_step); delta_g = (target_g - current_g) / float(fade_step); delta_b = (target_b - current_b) / float(fade_step); } void calc_fade() { if (fade_step > 0) { fade_step--; current_r = target_r - delta_r * fade_step; current_g = target_g - delta_g * fade_step; current_b = target_b - delta_b * fade_step; } else { Serial.println( "Normal mode" ); light_mode = LIGHT_NORMAL; } } void set_hw_status() { int r = on_off_status * (int)(current_r * dimmerlevel/100.0); int g = on_off_status * (int)(current_g * dimmerlevel/100.0); int b = on_off_status * (int)(current_b * dimmerlevel/100.0); set_rgb(r, g, b); } void send_status(int send_on_off_status, int send_dimmerlevel, int send_rgbstring) { if (send_rgbstring) send(rgbMsg.set(rgbstring)); if (send_on_off_status) send(lightMsg.set(on_off_status)); if (send_dimmerlevel) send(dimmerMsg.set(dimmerlevel)); } -
RGB LED strip@maghac Wow! I guess I haven't been around here for a while.
Thanks
-
RGB LED strip@maghac What board is that?
-
How To: Make a Simple/Cheap Scene Controller (with video)Never mind part of the code was commented out. I wasn't sure because I just started to use OTA. But it's all good now its working fine. Here it is:
#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_OTA_FIRMWARE_FEATURE #include <SPI.h> #include <MySensors.h> #include <Keypad.h> #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you. #define SN "Scene Controller" #define SV "2.0" #define KEYPAD_CHILD_ID 95 MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF const byte ROWS = 4; //four rows const byte COLS = 1; //one column char keys[ROWS][COLS] = { {'1'}, {'2'}, {'3'}, {'4'} }; byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); byte lastState; void setup() { sendSketchInfo(SN, SV); present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER); keypad.addEventListener(keypadEvent); } void loop() { char key = keypad.getKey(); } void keypadEvent(KeypadEvent key) { switch (keypad.getState()) { case PRESSED: lastState = 1; break; case HOLD: lastState = 2; break; case RELEASED: int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller if (lastState == 2) { keyInt = keyInt + 4; //If button is held, add 4. If using more than 4 buttons this number will need to be changed send(scene2.set(keyInt)); } else { send(scene.set(keyInt)); } break; } } -
How To: Make a Simple/Cheap Scene Controller (with video)Not getting the Hold on buttons working, everything else works. Any ideas why the long press doesn't work?
-
How To: Make a Simple/Cheap Scene Controller (with video)@hek
Yes I read but was soooo lazy! I just wanted it already done :grimacing:I just update one of my old sensors it was a simple single relay. My others are way more complicated! I will give this a try.
-
How To: Make a Simple/Cheap Scene Controller (with video)@petewill Have you updated this code to 2.0 yet? What is different?
-
💬 Building a Raspberry Pi GatewayThe line above
./examples_linux/mysGatewaymsyGateway -h
needs to be corrected to
./examples_linux/mysGateway -h
Thanks for all the hard work! Awesome! -
Wateringsystem@Lars65
Good times! :satisfied:
Yes I meant "saw" thanks for the good laugh. Did you finish yet? -
WateringsystemPut your pants back on! No working Naked!!
I laughed when I say the jeans in the picture. Have fun building! -
Internet of Poultry - Fully automated chicken shed@stefaanv said:
OTA updates
If I could only make time to get this working also! :smile:
Great project!
-
2.0 Gateway with 1.5 sensorsRunning a newly upgraded 2.0 Gateway with old Nodes so far so good. I will be updating as I get to them.
-
MySensors 2.0.0 Released@tante-ju
Jumped onto my ESXi server with a windows VM windows setup and the problem you are describing for the mac went away. I have El Cap on my mac with the same type of problems. Don't have an answers but windows worked fine. Wasted a couple of hours trying to fix also. -
Temps rounded to whole numbers?@Yveaux said:
float temperature = round(gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)));
I will try this Thanks for the help.
-
Temps rounded to whole numbers?Trying to get the DS18B20 to round to a whole number no decimal point. I'm using this and getting the temps down to .1 decimal point.
// Fetch and round temperature to one decimal float temperature = static_cast<float>(static_cast<int>((gw.getConfig().isMetric ? sensors.getTempCByIndex(i) : sensors.getTempFByIndex(i)) * 10.)) / 10.;What do I do next to get a whole number only, I don't like all the minor changes flooding my controller.
complete node code is below.
-
Problem with DS18b20@lcarlier try moving your resistor to the same pins but closer to the DS18B20, right now it's not limiting the power to it. The row between the DS18B20 and the wires. :)
-
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta@tekka , Time to try Thanks! :)
-
MYSBootloader 1.3 pre-release & MYSController 1.0.0beta@tekka Cool thanks, can I use Arduino as ISP to program bootloader?
-
MYSBootloader 1.3 pre-release & MYSController 1.0.0betaDoes the gateway need the OTA firmware (flashed) written to it as well as the Nodes?