Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. xydix
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by xydix

    • RE: Curtain Control Node.

      @adds666
      I am still in "testing mode".
      I had some problems with the node, it stoped receiving messages but did always work with the button.
      Yesterday i built a new node and uploaded the sketch and it seems to work better.
      Here is the sketch i use, I changed the pin for the button due to missing digital pins on my pcb.
      And I am back on using digital pins for the stepper driver for the same reason.
      I greyed out buttonpin 2. I don't think it is needed.
      I also greyed out the heartbeat-part as I had problems. Just for testing. Don't know if it is suitable when using Home Assistant.

      /*
       PROJECT: MY Sensors curtain controller
       PROGRAMMER: AWI
       DATE: march 11, 2016
       FILE: AWI stepper1.ino
       LICENSE: Public domain
      
       Hardware: ATMega328p board w/ NRF24l01
        and MySensors 2.0 (Development)
          
      Special:
        uses AccelStepper library
        
      Summary:
        Curtain control with stepper motor. 
        Manual operation with 1 push button 
        Calibration with manual button
      
      Remarks:
        Fixed node-id
        
      Change log:
      20160312 - Cleanup
      */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      #define MY_NODE_ID 8                     // fixed node number
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      #define MY_RF24_PA_LEVEL RF24_PA_HIGH
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensors.h> 
      
      // stepper library
      #include <AccelStepper.h>                   // http://www.airspayce.com/mikem/arduino/AccelStepper/
      #define HALFSTEP 8                        // Stepper uses "Halfstep" mode
      
      // button library
      // used for:
      // - manual open close - single click: close/ stop/ open/ stop
      // - calibration  - after long press: open calibarion- until single press - closed calibration - until single press (stop)
      #include <Button.h>                       // https://github.com/JChristensen/Button - AnvΓ€nd gammal version. testat med V0.9 och det funkar
      
      #define CHILD_ID 1                        // Id of the sensor child
      
      #define SN "Curtain control"
      #define SV "1.0"
      
      #define buttonPin1 A0                        // Arduino pin connected to buttonPin1
      //#define buttonPin2 A0                       // Arduino pin connected to buttonPin2 (fixed to ground)
      
      // Motor pin definitions
      #define motorPin1  2                        // IN1 on the ULN2003 driver 1
      #define motorPin2  3                        // IN2 on the ULN2003 driver 1
      #define motorPin3  5                        // IN3 on the ULN2003 driver 1
      #define motorPin4  6                        // IN4 on the ULN2003 driver 1
      
      //const unsigned long heartbeatInterval = 1 * 3600UL * 1000UL ; // heartbeatinterval
      //unsigned long heartbeatCounter = 0 ;
      
      //
      // helper routines to store and retrieve long in mysensors EEPROM
      union {                             // used to convert long to bytes for EEPROM storage
        long longInt;
        uint8_t LongByte[4];
        } convLongInt ;
      
      void saveStateL(int EEposition, long StateL){
        convLongInt.longInt = StateL ;
        for (int y = 0; y < 4 ; y++){               // convert to bytes
          saveState(EEposition + y , convLongInt.LongByte[y]) ;
          }
        Serial.print("State saved: "); Serial.println(StateL);
        }
          
      long loadStateL(int EEposition){
        for (int y = 0; y < 4 ; y++){               // convert from bytes
          convLongInt.LongByte[y] = loadState(EEposition + y) ;
          }
        Serial.print("State read: "); Serial.println(convLongInt.longInt);
        return convLongInt.longInt ;
        }
        
      
      // Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
      AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
      // Initialize button active low, debounce and internal pull-up
      Button myBtn(buttonPin1, true, true, 40);           // Initiate the button (pin, pull_up, invert, debounce_ms)
      
      MyMessage percentageMsg(CHILD_ID, V_PERCENTAGE);        // used to send updates to controller
      
      const long maxRun = 4000000L ;                  // maximum runway
      long setPosition = 0 ;                      // remembers set position, need to be saved in EEPROM
      const int setPositionEE = 4 ;                 // eeprom location
      long openPosition = 0 ;                     // Position at open, need to be saved in EEPROM?
      const int openPositionEE = setPositionEE + 4 ;          // eeprom location
      long closedPosition = 120000UL ;                // Position at full close, need to be saved in EEPROM
      const int closedPositionEE = openPositionEE + 4 ;       // eeprom location
      
      unsigned long idleTimer = millis() ;              // return to idle timer
      unsigned long idleTime = 100000UL ;               // return to idle after 100 secs
      
      unsigned long printTimer = millis() ;             // print timer
      unsigned long printTime = 1000UL ;                // print after 1 secs
      
      enum position_t {Open, Close, Idle, Running} ;
      position_t lastDirection = Open ;                 // lastDirection only for buttonpress
      position_t runStatus = Idle ;                 // indicates current status for running motor. used for status reporting to controller
      
      enum State_t {sIdle, sCalibrateOpen, sCalibrateClose} ;
      State_t State = sIdle ;
      
      
      void setup() {
        // setup buttons
        pinMode(buttonPin1, OUTPUT);
        stepper1.setMaxSpeed(1000.0);
        stepper1.setAcceleration(1000.0);
        //saveStateL(closedPositionEE, closedPosition) ;      // INIT: save closed position in EEPROM
        closedPosition = loadStateL(closedPositionEE) ;       // need to get last values from EEPROM and assume the current position is correct
        setPosition = loadStateL(setPositionEE) ;
        stepper1.setCurrentPosition(setPosition );
      }//--(end setup )---
      
      void presentation() {
        present(CHILD_ID, S_COVER, "Curtain");            // Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
      
        // Register the LED Dimmable Light with the gateway
        sendSketchInfo(SN, SV);
      }
      
      
      void loop() {
      unsigned int now = millis() ;               // current time for loop
      // simple state machine for button press
        myBtn.read();  
        switch (State) {
              // Idle state, waiting for some action
          // - button press
          // - idleTimer
              case sIdle:                
                  if (myBtn.wasReleased()){           // idle
              Serial.println("Button release") ;
              // if running stop
              if (stepper1.isRunning()){
                setPosition = stepper1.currentPosition();
                stepper1.moveTo(setPosition) ;      // move to current position (was already there..)
              } else if (lastDirection == Open) {
                stepper1.moveTo(closedPosition) ;
                lastDirection = Close ;
              } else {                  // lastDirection == Close
                stepper1.moveTo(openPosition) ;
                lastDirection = Open ;
              } 
            } else if (myBtn.pressedFor(3000)){       // move to calibratete state with long press
              Serial.println("Button press long") ;
              idleTimer = now ;             // return to idle after ...
              State = sCalibrateOpen ;
              stepper1.move(-maxRun) ;          // let the stepper open with maximum
              }
            break ;
          // if not running and last action was open close ;  else open
          // if longpress Calibrate open
              case sCalibrateOpen:                      // calibration going on     
            if (myBtn.wasPressed()){
              stepper1.setCurrentPosition(0 );    // set new 0 position ??
              openPosition = setPosition = 0 ;
              State = sCalibrateClose ;         // next is close calibarion
              stepper1.move(maxRun) ;           // let the stepper close with maximum
            } else if (now > idleTimer + idleTime) {    // timer expired -> abort calibration
              State = sIdle ;
            }
            break ;
              case sCalibrateClose:               // calibrate closed position, end with keypress
            if (myBtn.wasPressed()) {
              closedPosition = setPosition = stepper1.currentPosition() ;
              saveStateL(closedPositionEE, closedPosition) ; // save closed position in EEPROM
              State = sIdle ;
              stepper1.moveTo(openPosition) ;       // return to open after calibration
            } else if (now > idleTimer + idleTime) {    // timer expired -> abort calibration
              State = sIdle ;
            }
            break ;
          default :
            break ;
          }
        // power off stepper if not running (no need to reenable))
        if (!stepper1.isRunning()){
          if (runStatus != Idle){               // there was a change in runningstatus, so report to controller
            setPosition = stepper1.currentPosition() ;    // store in EEPROM and report ready to controller
            saveStateL(setPositionEE, setPosition) ;
            send( percentageMsg.set((100 * setPosition)/(closedPosition - openPosition))) ;
            runStatus = Idle ;
          }
          stepper1.disableOutputs();
        } else {
          runStatus = Running ;
        }
        stepper1.run();
        /*
        if (printTimer++ > now + printTime){
          printTimer = now ;
          Serial.println(stepper1.currentPosition());
          }
        */
      }
      
      // This is called when a message is received 
      void receive(const MyMessage &message) {
      // We only expect few types of messages from controller, check which
        switch (message.type) {
        case V_PERCENTAGE:
        // Curtain should be opened
        stepper1.moveTo(message.getInt() * (closedPosition - openPosition)/100);
        Serial.print("Message: "); Serial.print(message.sensor); Serial.print(" , value: % "); Serial.println( message.getInt());
        Serial.print("Moving to: "); Serial.println(message.getInt() * (closedPosition - openPosition)/100);
        break ;
        case V_STATUS:
        // Curtain should be opened or closed full
        stepper1.moveTo((message.getInt() == HIGH)?openPosition:closedPosition);
        Serial.print("Message - valid: ");
        Serial.print(message.sensor);
        Serial.print(" , value: % ");
        break ;
        default : 
        // not recognizable message
        Serial.print("Message - valid: ");
        Serial.print(message.sensor);
        Serial.print(", Unrecognized ");
        break ;
        }
        }
      
      posted in My Project
      xydix
      xydix
    • RE: Curtain Control Node.

      @adds666 What i can tell it was a long time since @AWI was active here.
      I use this sketch with my first bild since a couple of days.
      For me it works like a charm. But in my case I control the motor from analog pins just to test and it seems OK.
      No problem with the button.
      The only thing I don't like, is the calibration.
      I my case, using this on a blind, when calibrating, first it goes down, then i press the button, the blind stops at once and change it's direction and goes up. But when i reach the top level and want to stop it and save the state, it stops slow and pass the point i pressed the button and then reverse to the right spot. Problem is, the blind can't go further because it is in the top position.
      If it would be the other way around it wouldn't be a problem.
      Maybe i have the motor one the "wrong" side of the blind but when it is down the "downkey" in my HA is greyed out.
      When it i up the "upkey" it greyed out so that seems right.

      What is not working in your case?
      What motor do you use? I use 28BYJ-48 with ULN2003 and had to set stepper1.setMaxSpeed(2000.0); to stepper1.setMaxSpeed(1000.0); because the motor "slipped" at a speed of 2000.
      Like i wrote earlier in the thread I tried to figure out how to "dublicate" the sketch and ute it for two motors.
      I really don't know where to start to get this done. It would be awesome to use one arduino with two blinds.

      posted in My Project
      xydix
      xydix
    • RE: Problem with Wind Speed sensor

      Anyone got a working sketch for a pulse anenometer?
      I printed this. https://www.thingiverse.com/thing:2523343
      I used it with ESPHome as testing it and I got OK values.
      Now i would like to use it with mysensors.
      I tried @AWI s sketch but I get stange readings.
      Sometimes I get a very high value when is turns slow.

      posted in Troubleshooting
      xydix
      xydix
    • RE: Curtain Control Node.

      @xydix
      To answer my own question the stepper runs fine from the analog pins.
      Next step is to find some intersted in the same thing and see if we could get the sketch adjusted to run two steppers.
      I will try when i get some time but I guess I will have problem to clone the calibration and store-to-eerprom-part.

      posted in My Project
      xydix
      xydix
    • RE: Curtain Control Node.

      @ton-rijnaard
      Hi. This was a problem for me to. The reason is the library changed name and updates was made.
      I use the library version 0.9.
      I have like zero skills in arduino. If you use the old library the button will work with the sketch i posted a moth ago.
      Looke here: https://github.com/JChristensen/JC_Button/releases
      Maybe some of the other older releases will work. Don't remember why o choose V0.9
      Look at 2.0.0, "This is a major release that is not backwards-compatible with previous releases."

      posted in My Project
      xydix
      xydix
    • RE: πŸ’¬ MyPulse Sensor

      @scalz
      I guess you have the answer to that questionπŸ‘†?

      posted in OpenHardware.io
      xydix
      xydix
    • RE: Curtain Control Node.

      Okey. This is an old thread but I hope it's ok I keep it alive.
      I just printed som parts for my blinds.
      I use a stepper motor (28BYJ-48 with ULN2003 Driver board) and this sketch found in this thread.
      The sketch is awesome.
      To my quiestion.
      I want to run 2 blinds at the same time from ONE node. Synchronized or maybe individual.
      Is this possible?
      There isn't any digital pins over for this when using button(s).
      I think i saw someone using analog pin connected to the ULN2003 someware.
      Is it possible to run 2 motors on one board?
      Really hope somone can answer som of my question.
      What modifications is needed in the sketch if this is possible.
      This is the sketch I use.

      /*
       PROJECT: MY Sensors curtain controller
       PROGRAMMER: AWI
       DATE: march 11, 2016
       FILE: AWI stepper1.ino
       LICENSE: Public domain
      
       Hardware: ATMega328p board w/ NRF24l01
      	and MySensors 2.0 (Development)
      		
      Special:
      	uses AccelStepper library
      	
      Summary:
      	Curtain control with stepper motor. 
      	Manual operation with 1 push button 
      	Calibration with manual button
      
      Remarks:
      	Fixed node-id
      	
      Change log:
      20160312 - Cleanup
      */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      #define MY_NODE_ID 13											// fixed node number
      // Enable and select radio type attached
      #define MY_RADIO_RF24
      //#define MY_RADIO_RFM69
      
      #include <SPI.h>
      #include <MySensors.h> 
      
      // stepper library
      #include <AccelStepper.h>										// http://www.airspayce.com/mikem/arduino/AccelStepper/
      #define HALFSTEP 8  											// Stepper uses "Halfstep" mode
      
      // button library
      // used for:
      // - manual open close - single click: close/ stop/ open/ stop
      // - calibration  - after long press: open calibarion- until single press - closed calibration - until single press (stop)
      #include <Button.h>												// https://github.com/JChristensen/Button
      
      #define CHILD_ID 1   											// Id of the sensor child
      
      #define SN "Curtain control 13"
      #define SV "1.0"
      
      #define buttonPin1 7  											// Arduino pin connected to buttonPin1
      #define buttonPin2 A0  											// Arduino pin connected to buttonPin2 (fixed to ground)
      
      // Motor pin definitions
      #define motorPin1  3     										// IN1 on the ULN2003 driver 1
      #define motorPin2  4     										// IN2 on the ULN2003 driver 1
      #define motorPin3  5     										// IN3 on the ULN2003 driver 1
      #define motorPin4  6     										// IN4 on the ULN2003 driver 1
      
      const unsigned long heartbeatInterval = 1 * 3600UL * 1000UL ;	// heartbeatinterval
      unsigned long heartbeatCounter = 0 ;
      
      //
      // helper routines to store and retrieve long in mysensors EEPROM
      union {															// used to convert long to bytes for EEPROM storage
      	long longInt;
      	uint8_t LongByte[4];
      	} convLongInt ;
      
      void saveStateL(int EEposition, long StateL){
      	convLongInt.longInt = StateL ;
      	for (int y = 0; y < 4 ; y++){								// convert to bytes
      		saveState(EEposition + y , convLongInt.LongByte[y]) ;
      		}
      	Serial.print("State saved: "); Serial.println(StateL);
      	}
      		
      long loadStateL(int EEposition){
      	for (int y = 0; y < 4 ; y++){								// convert from bytes
      		convLongInt.LongByte[y] = loadState(EEposition + y) ;
      		}
      	Serial.print("State read: "); Serial.println(convLongInt.longInt);
      	return convLongInt.longInt ;
      	}
      	
      
      // Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
      AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
      // Initialize button active low, debounce and internal pull-up
      Button myBtn(buttonPin1, true, true, 40);						// Initiate the button (pin, pull_up, invert, debounce_ms)
      
      MyMessage percentageMsg(CHILD_ID, V_PERCENTAGE);				// used to send updates to controller
      
      const long maxRun = 4000000L ;									// maximum runway
      long setPosition = 0 ; 											// remembers set position, need to be saved in EEPROM
      const int setPositionEE = 4 ;									// eeprom location
      long openPosition = 0 ; 										// Position at open, need to be saved in EEPROM?
      const int openPositionEE = setPositionEE + 4 ;					// eeprom location
      long closedPosition = 120000UL ; 								// Position at full close, need to be saved in EEPROM
      const int closedPositionEE = openPositionEE + 4 ;				// eeprom location
      
      unsigned long idleTimer = millis() ;							// return to idle timer
      unsigned long idleTime = 100000UL ;								// return to idle after 100 secs
      
      unsigned long printTimer = millis() ;							// print timer
      unsigned long printTime = 1000UL ;								// print after 1 secs
      
      enum position_t {Open, Close, Idle, Running} ;
      position_t lastDirection = Open ; 								// lastDirection only for buttonpress
      position_t runStatus = Idle ;									// indicates current status for running motor. used for status reporting to controller
      
      enum State_t {sIdle, sCalibrateOpen, sCalibrateClose} ;
      State_t State = sIdle ;
      
      
      void setup() {
      	// setup buttons
      	pinMode(buttonPin1, OUTPUT);
      	stepper1.setMaxSpeed(2000.0);
      	stepper1.setAcceleration(1000.0);
      	//saveStateL(closedPositionEE, closedPosition) ; 			// INIT: save closed position in EEPROM
      	closedPosition = loadStateL(closedPositionEE) ;				// need to get last values from EEPROM and assume the current position is correct
      	setPosition = loadStateL(setPositionEE) ;
      	stepper1.setCurrentPosition(setPosition );
      }//--(end setup )---
      
      void presentation() {
        present(CHILD_ID, S_COVER, "Curtain");						// Window Cover sub-type, commands: V_UP, V_DOWN, V_STOP
      
        // Register the LED Dimmable Light with the gateway
        sendSketchInfo(SN, SV);
      }
      
      
      void loop() {
      unsigned int now = millis() ;								// current time for loop
      // simple state machine for button press
      	myBtn.read();  
      	switch (State) {
              // Idle state, waiting for some action
      		// - button press
      		// - idleTimer
              case sIdle:                
                  if (myBtn.wasReleased()){						// idle
      				Serial.println("Button release") ;
      				// if running stop
      				if (stepper1.isRunning()){
      					setPosition = stepper1.currentPosition();
      					stepper1.moveTo(setPosition) ;			// move to current position (was already there..)
      				} else if (lastDirection == Open) {
      					stepper1.moveTo(closedPosition) ;
      					lastDirection = Close ;
      				} else {									// lastDirection == Close
      					stepper1.moveTo(openPosition) ;
      					lastDirection = Open ;
      				}	
      			} else if (myBtn.pressedFor(3000)){				// move to calibratete state with long press
      				Serial.println("Button press long") ;
      				idleTimer = now ;							// return to idle after ...
      				State = sCalibrateOpen ;
      				stepper1.move(-maxRun) ;					// let the stepper open with maximum
      				}
      			break ;
      		// if not running and last action was open close ;  else open
      		// if longpress Calibrate open
              case sCalibrateOpen:           						// calibration going on     
      			if (myBtn.wasPressed()){
      				stepper1.setCurrentPosition(0 );		// set new 0 position ??
      				openPosition = setPosition = 0 ;
      				State = sCalibrateClose ;					// next is close calibarion
      				stepper1.move(maxRun) ;						// let the stepper close with maximum
      			} else if (now > idleTimer + idleTime) {		// timer expired -> abort calibration
      				State = sIdle ;
      			}
      			break ;
              case sCalibrateClose:								// calibrate closed position, end with keypress
      			if (myBtn.wasPressed())	{
      				closedPosition = setPosition = stepper1.currentPosition() ;
      				saveStateL(closedPositionEE, closedPosition) ; // save closed position in EEPROM
      				State = sIdle ;
      				stepper1.moveTo(openPosition) ;				// return to open after calibration
      			} else if (now > idleTimer + idleTime) {		// timer expired -> abort calibration
      				State = sIdle ;
      			}
      			break ;
      		default :
      			break ;
      		}
      	// power off stepper if not running (no need to reenable))
      	if (!stepper1.isRunning()){
      		if (runStatus != Idle){								// there was a change in runningstatus, so report to controller
      			setPosition = stepper1.currentPosition() ;		// store in EEPROM and report ready to controller
      			saveStateL(setPositionEE, setPosition) ;
      			send( percentageMsg.set((100 * setPosition)/(closedPosition - openPosition))) ;
      			runStatus = Idle ;
      		}
      		stepper1.disableOutputs();
      	} else {
      		runStatus = Running ;
      	}
      	stepper1.run();
      	/*
      	if (printTimer++ > now + printTime){
      		printTimer = now ;
      		Serial.println(stepper1.currentPosition());
      		}
      	*/
      }
      
      // This is called when a message is received 
      void receive(const MyMessage &message) {
      // We only expect few types of messages from controller, check which
        switch (message.type) {
      	case V_PERCENTAGE:
      	// Curtain should be opened
      	stepper1.moveTo(message.getInt() * (closedPosition - openPosition)/100);
      	Serial.print("Message: "); Serial.print(message.sensor); Serial.print(" , value: % "); Serial.println( message.getInt());
      	Serial.print("Moving to: "); Serial.println(message.getInt() * (closedPosition - openPosition)/100);
      	break ;
      	case V_STATUS:
      	// Curtain should be opened or closed full
      	stepper1.moveTo((message.getInt() == HIGH)?openPosition:closedPosition);
      	Serial.print("Message - valid: ");
      	Serial.print(message.sensor);
      	Serial.print(" , value: % ");
      	break ;
      	default : 
      	// not recognizable message
      	Serial.print("Message - valid: ");
      	Serial.print(message.sensor);
      	Serial.print(", Unrecognized ");
      	break ;
      	}
        }
      
      posted in My Project
      xydix
      xydix
    • RE: πŸ’¬ MyPulse Sensor

      Hi. Thank you for sharing your board. It seems awesome. I got a question. When I read the BOM, I think I should use 100 ohm, 330 ohm and 1500 ohm resistor. When I look at the schematic picture it says 100k 330k. What resistor should I use?

      posted in OpenHardware.io
      xydix
      xydix
    • RE: πŸ’¬ Battery operated rain-gauge

      @heizelmann Hi. Sorry if I wake an old thread.
      Do you still have your code?
      I am about to build a rain gauge and want it to run on battery.
      Your way to handle things is what I am looking for.
      Would you like to share your code?

      posted in OpenHardware.io
      xydix
      xydix
    • smartSleep with 2.3.0, missing messages

      Hi.
      I went from 2.1.1 to 2.3.0 hoping I would get a more stable network.
      When i did this I tried some OTA and went from sleep to smartSleep in some sketches.
      My problem. it's a binary sensor node reading a blinking LED.
      But if the LED blink too fast the node won't send the state change.
      I only get:

      718	2018-10-05 21:59:52	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_POST_SLEEP_NOTIFICATION	0
      719	2018-10-05 21:59:52	RX	5 - Pannrum	1 - S_DOOR	C_SET	NO	V_TRIPPED	0
      720	2018-10-05 21:59:52	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_BATTERY_LEVEL	100
      721	2018-10-05 21:59:52	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_PRE_SLEEP_NOTIFICATION	50
      722	2018-10-05 21:59:53	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_POST_SLEEP_NOTIFICATION	0
      723	2018-10-05 21:59:53	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_BATTERY_LEVEL	100
      724	2018-10-05 21:59:53	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_PRE_SLEEP_NOTIFICATION	50
      725	2018-10-05 21:59:54	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_POST_SLEEP_NOTIFICATION	0
      726	2018-10-05 21:59:54	RX	5 - Pannrum	1 - S_DOOR	C_SET	NO	V_TRIPPED	1
      727	2018-10-05 21:59:54	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_BATTERY_LEVEL	100
      728	2018-10-05 21:59:54	RX	5 - Pannrum	INTERNAL	C_INTERNAL	NO	I_PRE_SLEEP_NOTIFICATION	50
      

      This is from MYSController, what the gateway see.
      As you see sometimes i Only get the presleep, postsleep and battery, not the C_SET/ Value.

      Some from serial monitor but not the exact same time as the log above.

      51511 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=2,st=OK:
      53624 !TSM:FPAR:NO REPLY
      53641 TSM:FPAR
      53706 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      55246 TSF:MSG:READ,4-4-5,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      55312 TSF:MSG:FPAR OK,ID=4,D=2
      55803 TSM:FPAR:OK
      55820 TSM:ID
      55836 TSM:ID:OK
      55853 TSM:UPL
      55902 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      56213 !TSF:SND:TNR
      56229 !TSF:SND:TNR
      57999 TSM:UPL
      58032 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      60129 TSM:UPL
      60178 !TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
      61276 !TSF:SND:TNR
      62275 TSM:UPL
      62308 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=OK:1
      64405 !TSM:UPL:FAIL
      64421 TSM:FPAR
      64471 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      64667 TSF:MSG:READ,4-4-5,s=255,c=3,t=8,pt=1,l=1,sg=0:1
      64733 TSF:MSG:FPAR OK,ID=4,D=2
      66322 !TSF:SND:TNR
      66584 TSM:FPAR:OK
      66600 TSM:ID
      66617 TSM:ID:OK
      66633 TSM:UPL
      66682 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      68763 TSM:UPL
      68780 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      70877 TSM:UPL
      70893 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
      70975 TSF:MSG:READ,0-4-5,s=255,c=3,t=25,pt=1,l=1,sg=0:2
      71041 TSF:MSG:PONG RECV,HP=2
      71073 TSM:UPL:OK
      71106 TSM:READY:ID=5,PAR=4,DIS=2
      71368 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=OK:100
      71450 MCO:SLP:MS=0,SMS=1,I1=0,M1=1,I2=1,M2=1
      71516 TSF:MSG:SEND,5-5-4-0,s=255,c=3,t=32,pt=5,l=4,sg=0,ft=0,st=OK:100
      71712 TSF:TDI:TSL
      

      The 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.
      
       *******************************
      
         DESCRIPTION
      
         Interrupt driven binary switch example with dual interrupts
         Author: Patrick 'Anticimex' Fallberg
         Connect one button or door/window reed switch between
         digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
         one in similar fashion on digital I/O pin 2.
         This example is designed to fit Arduino Nano/Pro Mini
      
      */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      #define MY_BAUD_RATE 9600
      #define MY_SMART_SLEEP_WAIT_DURATION_MS 100
      
      #define MY_NODE_ID 5
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <Vcc.h>
      
      #define SKETCH_NAME "Pannrum"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "0"
      
      #define PRIMARY_CHILD_ID 1
      #define SECONDARY_CHILD_ID 2
      
      #define PRIMARY_INPUT_PIN 2   // Arduino Digital I/O pin for button/reed switch
      #define SECONDARY_INPUT_PIN 3
      
      const float VccMin   = 1.9;           // Minimum expected Vcc level, in Volts. (NRF can only go to 1.9V)
      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
      
      Vcc vcc(VccCorrection);
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
      MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
      
      void setup()
      {
      
        // Setup the buttons
        pinMode(PRIMARY_INPUT_PIN, INPUT);
        pinMode(SECONDARY_INPUT_PIN, INPUT);
      
        // Activate internal pull-ups
        //  digitalWrite(INPUT1_PIN, HIGH);
      
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
      
        // Register binary input sensor to sensor_node (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(PRIMARY_CHILD_ID, S_DOOR);
        present(SECONDARY_CHILD_ID, S_DOOR);
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop()
      {
        uint8_t value;
        static uint8_t sentValue = 2;
        static uint8_t sentValue2 = 2;
      
        // Short delay to allow buttons to properly settle
        wait(5);
      
        value = digitalRead(PRIMARY_INPUT_PIN);
      
        if (value != sentValue) {
          // Value has changed from last transmission, send the updated value
          send(msg.set(value == HIGH));
          sentValue = value;
        }
      
        value = digitalRead(SECONDARY_INPUT_PIN);
      
        if (value != sentValue2) {
          // Value has changed from last transmission, send the updated value
          send(msg2.set(value == HIGH));
          sentValue2 = value;
        }
      
      
        float  p = vcc.Read_Perc(VccMin, VccMax);
        sendBatteryLevel((uint8_t)p);
      
      
      // Sleep until something happens with the sensor
      if (isTransportReady()) {
        smartSleep(PRIMARY_INPUT_PIN-2, CHANGE, SECONDARY_INPUT_PIN-2, CHANGE, 0); // transport is OK, node can sleep
      }
      else {
        wait(5000); // transport is not operational, allow the transport layer to fix this
      }
      
      
      } 
      

      I tried This, just replacing all three files in the RF24 folder. Loading this to the sensor but it didn't help.

      posted in Troubleshooting
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      It waswhat I thought too.
      As I said earlier, when I tested this my conclusion was, short blink, almost a flash will counted as a pulse (kWh) but it does something wrong with the calculation of instant power usage.
      A slower blink will correct this.
      My meeter gives a very short blink.

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      I am glad to hear it works for you too.

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      Nothing more.
      I use the same arduino, haven't uploaded anything new to it since i tried it last time.

      What I had to do was lower the sensitivity on the LM393 because at first the signal-LED glowed a bit but when i adjusted it to lower sensitivity and closed the door to get it totaly dark the led blinked exactly as the meeter.

      I have it on a bredboard and connected the cap between GND and to pin 3 so it is connected close to the arduino but i guess it shouldn't matter.

      Have you tried it?

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      Yes. I guess.
      I don't have anything to compare with but i think it is accurate.
      I have a 1000blink/kwh
      Example:
      Node send state every 20 sec.
      pulsecount: 8 pulses every 20 sec.
      Instant power in W is about 1400W

      8 pulses x 3 = pulses /minute =24
      24 pulses x 60 min = pulses /hour = 1440.

      Edit.
      Now I get a new value every 20 sec, before I didn't get any value (W) from the node at all because it was too high. I only received pulse count and kWh earlier.

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      I think i solved this.
      I don't know if it is a good solution.
      Maybe it is possible to solve in the code?
      I added a 0,1uf ceramic capacitor between DO and GND on the LM393.
      Then i tuned the LM393 until i had it blink as expected.

      I think, in my case the LED pulse from my meeter was to short, it gives a very short blink.
      Anyway.
      I tested it all day and it seems fine now.

      posted in Announcements
      xydix
      xydix
    • RE: Reliable communication.

      How about RFM69W? 13dBm And RFM69HW? 20dBm. Wich one for battery nodes? Are there more alternatives? Have i seen a RFM69C somewhere? HW for the gateway?

      posted in Development
      xydix
      xydix
    • RE: Reliable communication.

      @nca78 said in Reliable communication.:

      @xydix this is a good radio from EByte, but if "Gateway is low I think" means you have a lower power setting then you're not making use of the PA/LNA on that radio which is a shame. I have a similar radio, with 25-30cm thick concrete walls and signal manages to go around the walls.
      So I would check the power level of the gateway first, and if it doesn't solve the problem then you have to implement the resend, but no there doesn't seem to be a "right" way to do it. You just need to :

      • make sure ACK is enabled for the node (I think there is an automatic resend implemented in radio in this case)
      • check result of the send command, and if false sleep a little bit and send again, you can do this in a loop to try sending a few more times.

      I had my radio on high or max at first but experience it more stable now. After all, everything i send out from my gateway is ok. I have problem receiving from my nodes.
      Today i do not use ack on any node.
      May it be enough to enable ack to make the node try again if it doesn't receive the ack back?

      @rozpruwacz said in Reliable communication.:

      @xydix I had also problems with reliable comunication using nrf modules. I switched to rfm69 and it is much much better. It is easy to switch to rfm69 using this: https://www.mysensors.org/hardware/nrf2rfm69. But appart from that a good resend algorithm is also necessary. Unfortunately there is no one good resend algorithm for every use case, it depends on the node usage.

      I started with nrf because I was to cheap to buy RFM69, and didn't know if mysensors was something I would like.
      Then there was a lot of different versions, so i went for the NFR because it was easy. I am pretty happy with it but it isn't 100%.
      What should i choose? 433 or 868? Do they both got same features?

      posted in Development
      xydix
      xydix
    • RE: Reliable communication.

      @nca78 said in Reliable communication.:

      Hello, @xydix

      you should not have any problem for such a short distance.
      Before checking acks and retrying to send I would check those:

      • problem with radio quality: what modules do you use on nodes and gateway ? Did you set the TX power to PA_MAX ?
      • problem with interferences: what channel do you use ? have you tried one of the channels outside of the wifi frequency ? (>=100)

      I got som concrete walls that might block the signal a little.
      For my gateway I use this radio. Bought it after watched a YouTube video, a guy compared radios.

      In my nodes I use various radios. Some bought from eBay, aliexpress, electrodragon.
      I tried different capacitors, some antenna mods.
      All nodes us PA_MAX. Gateway is low I think.
      My problem is receiving messages from nodes.
      I haven't changed the channel.
      It is so hard to know when a test/change give results. I might have a missed message once a week or something like that. This is based on when one of my motion sensors showing motion for a long time and there is no motion.
      A resend function solves the problem even if the actual problem is the hardware.

      posted in Development
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      Okay. Really annoying. Check this.

      Received last pulse count from gw:2527
      Watt:121065
      22235 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2539
      22246 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5390
      Watt:121621
      42238 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2551
      42250 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5510
      Watt:121342
      62239 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2563
      62251 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5630
      Watt:121539
      82240 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2575
      82251 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5750
      Watt:121951
      102239 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2589
      102250 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.5890
      Watt:122067
      122243 TSF:MSG:SEND,78-78-0-0,s=3,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:2601
      122254 TSF:MSG:SEND,78-78-0-0,s=2,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:2.6010
      

      The plus count seems OK, right?

      My energy meter is 1000 pluses /kwh

      Here is my sketch. I use Home assistant so i created three sensors for this as I don't think V_VAR1 is supported with S_POWER.
      Otherwise it is the standard example.

      /**
       * 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
       * This sketch provides an example how to implement a distance sensor using HC-SR04
       * Use this sensor to measure KWH and Watt of your house meeter
       * You need to set the correct pulsefactor of your meeter (blinks per KWH).
       * The sensor starts by fetching current KWH value from gateway.
       * Reports both KWH and Watt back to gateway.
       *
       * Unfortunately millis() won't increment when the Arduino is in
       * sleepmode. So we cannot make this sensor sleep if we also want
       * to calculate/report watt-number.
       * http://www.mysensors.org/build/pulse_power
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_NODE_ID 78
      #include <MySensors.h>
      
      #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
      #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
      #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
      #define MAX_WATT 20000          // Max watt value to report. This filetrs outliers.
      #define WATT_CHILD_ID 1              // Id of the sensor child
      #define KWH_CHILD_ID 2
      #define PC_CHILD_ID 3
      
      unsigned long SEND_FREQUENCY =
          20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
      double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
      bool pcReceived = false;
      volatile unsigned long pulseCount = 0;
      volatile unsigned long lastBlink = 0;
      volatile unsigned long watt = 0;
      unsigned long oldPulseCount = 0;
      unsigned long oldWatt = 0;
      double oldKwh;
      unsigned long lastSend;
      MyMessage wattMsg(WATT_CHILD_ID,V_WATT);
      MyMessage kwhMsg(KWH_CHILD_ID,V_KWH);
      MyMessage pcMsg(PC_CHILD_ID,V_VAR1);
      
      
      void setup()
      {
        // Fetch last known pulse count value from gw
        request(PC_CHILD_ID, V_VAR1);
      
        // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
        // If no pullup is used, the reported usage will be too high because of the floating pin
        pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP);
      
        attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
        lastSend=millis();
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Energy Meter", "1.0");
      
        // Register this device as power sensor
        present(WATT_CHILD_ID, S_POWER);
        present(KWH_CHILD_ID, S_POWER);
        present(PC_CHILD_ID, S_CUSTOM);
      }
      
      void loop()
      {
        unsigned long now = millis();
        // Only send values at a maximum frequency or woken up from sleep
        bool sendTime = now - lastSend > SEND_FREQUENCY;
        if (pcReceived && (SLEEP_MODE || sendTime)) {
          // New watt value has been calculated
          if (!SLEEP_MODE && watt != oldWatt) {
            // Check that we dont get unresonable large watt value.
            // could hapen when long wraps or false interrupt triggered
            if (watt<((unsigned long)MAX_WATT)) {
              send(wattMsg.set(watt));  // Send watt value to gw
            }
            Serial.print("Watt:");
            Serial.println(watt);
            oldWatt = watt;
          }
      
          // Pulse cout has changed
          if (pulseCount != oldPulseCount) {
            send(pcMsg.set(pulseCount));  // Send pulse count value to gw
            double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
            oldPulseCount = pulseCount;
            if (kwh != oldKwh) {
              send(kwhMsg.set(kwh, 4));  // Send kwh value to gw
              oldKwh = kwh;
            }
          }
          lastSend = now;
        } else if (sendTime && !pcReceived) {
          // No count received. Try requesting it again
          request(PC_CHILD_ID, V_VAR1);
          lastSend=now;
        }
      
        if (SLEEP_MODE) {
          sleep(SEND_FREQUENCY);
        }
      }
      
      void receive(const MyMessage &message)
      {
        if (message.type==V_VAR1) {
          pulseCount = oldPulseCount = message.getLong();
          Serial.print("Received last pulse count from gw:");
          Serial.println(pulseCount);
          pcReceived = true;
        }
      }
      
      void onPulse()
      {
        if (!SLEEP_MODE) {
          unsigned long newBlink = micros();
          unsigned long interval = newBlink-lastBlink;
          if (interval<10000L) { // Sometimes we get interrupt on RISING
            return;
          }
          watt = (3600000000.0 /interval) / ppwh;
          lastBlink = newBlink;
        }
        pulseCount++;
      }
      
      

      Anyone got any ideas?
      BTW. First i tried the original example sketch, unmodified, with the same result.

      posted in Announcements
      xydix
      xydix
    • Reliable communication.

      I know, there are tons of threads on this subject.
      Most of them are old, back on 1.5.*
      I have some nodes. The messages arrives 95% of the times. I would like 100% πŸ™‚
      I know, more repeaters might help but i have 4-10 meters between my nodes and my gateway.
      Is it possible to acheave reliable communication?
      I've seen examples on resend, but is there a "right" way to do it? It seems you have to do it different depending of what type av node it is?
      I am on 2.1.1 right now. Are there any difference in 2.2.0 in this area?
      Other stuff is often very well explained. Like how to connect stuff and the battery measurement part is so easy with pictures like a child could understand it.

      posted in Development
      xydix
      xydix
    • RE: πŸ’¬ Power Meter Pulse Sensor

      @gohan Did you solve this?
      I get very high watt usage as well. Sometimes like 40 000 - 130 000 watt if I check the serial monitor.
      Of course, those values will never be sent to the controler.

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ Dimmable Led Strip board (MysX)

      FYI...
      12v = Mosfet = irlz44n, Voltage Reg (12 to 5v) = LM2940CT-5
      24v = Mosfet = ???, Voltage reg (24 to 5v) = ???

      I think IRZL44N will handle 24V.

      posted in OpenHardware.io
      xydix
      xydix
    • RE: Smart button / scene controller

      Thank you. It is solved now.
      Here is the new sketch reporting battery level using the vcc library.

      /*
        Mysensors Smart Button
      */
      
      #define MY_DEBUG
      #define MY_RADIO_NRF24
      #define MY_NODE_ID 7
      
      #include "OneButton.h"
      #include <SPI.h>
      #include <MySensors.h>
      #include <Vcc.h>
      
      #define SN "Kitchen Table"
      #define SV "1.0"
      #define CHILD_ID 1
      #define SLEEP_PIN 2
      // Setup a new OneButton on pin D2. true will set pin high (internal pull up), false will set pin low.
      OneButton button(2, true);
      unsigned long previousMillis = 0;
      unsigned long currentMillis = 0;
      const long interval = 5000;
      
      const float VccMin   = 1.9;           // Minimum expected Vcc level, in Volts. (NRF can only go to 1.9V)
      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
      
      Vcc vcc(VccCorrection);
      
      MyMessage on(CHILD_ID, V_SCENE_ON);
      
      // setup code here, to run once:
      void setup() {
      
        // link the doubleclick function to be called on a doubleclick event.
        button.attachClick(click);
        button.attachDoubleClick(doubleclick);
        button.attachPress(press);
      
      } // setup
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
        present(CHILD_ID, S_SCENE_CONTROLLER);
      }
      
      int messageA = 1;
      int messageB = 2;
      int messageC = 3;
      
      
      void loop() {
        currentMillis = millis();
        // keep watching the push button:
        button.tick();
      
        if (currentMillis - previousMillis >= interval) {
      
          previousMillis = currentMillis;
        float p = vcc.Read_Perc(VccMin, VccMax);
          sendBatteryLevel((uint8_t)p);
          Serial.println("Sleep");
          sleep(SLEEP_PIN - 2, CHANGE, 0);
        }
      } // loop
      // this function will be called when the button was pressed one time
      
      void click() {
        send(on.set(messageA));
      }
      // this function will be called when the button was pressed 2 times in a short timeframe.
      void doubleclick() {
        send(on.set(messageB));
      } // doubleclick
      // this function will be called when the button was pressed for about one second
      void press() {
        send(on.set(messageC));
      }
      
      posted in My Project
      xydix
      xydix
    • RE: Smart button / scene controller

      Thank you for your answer.
      I have sensors reporting battery that way.
      It's working fine.
      My smart button sensors is using MYSbootloader and 1,8v bod.
      And my newer nodes I try to build as simple possible.
      Using the vcc library seems to be a simple way to do it.

      But the problem is, it's not working when I add vcc to my sketch. It won't send any value at all.

      posted in My Project
      xydix
      xydix
    • RE: Smart button / scene controller

      I really appreciate if someone would try to help me with battery report.

      posted in My Project
      xydix
      xydix
    • RE: Supercap Solar Powered Mysensors nodes as cheap as possible

      @NeverDie Doesn't matter for me. I have seen your boards on openhardware for solar panels. Interesting.
      In many cases an custom PCB get pretty expensive if you just want 1 or 2 board because buy all components required, these are often is selled in 10 pcs or more.
      In my case, I want something that works, then if i can get away with just an LDO on an protoboard im fine with that.
      I try to build as cheap nodes as possible.
      Then if i can find cheap stuff in aliexpress that is doing the job, thats fine.
      Have you had any good results useing solar panel indoors?

      posted in My Project
      xydix
      xydix
    • RE: Supercap Solar Powered Mysensors nodes as cheap as possible

      Hi guys.
      Im I wrong if I say that both @gohan and @NeverDie discuss a lot of solar/supercap in multipe threads?
      Have some of you come to an conclution?
      Wich supercap is best(good enough)?
      Wich solarpanel the best?
      This is very interesting but im an curious what is the optimal setup?

      posted in My Project
      xydix
      xydix
    • RE: Smart button / scene controller

      I had my node running for a while now.
      I am really happy with it. Nice to not need my phone to start my radio or adjust the volume while i am eating.

      I tried to add vcc.h to the sketch but it causes problems.
      The battery gets reported when the messages arrive but the messages don't get through every time.
      The LED (not the powerLED, i cut that one) on the pro mini just flickers instead of a solid light..

      This is the sketch.
      I searched the forum and copied stuff from the sketch @petewill uses for his chair occupancy sensor.

      /*
        Mysensors Smart Button
      */
      
      #define MY_DEBUG
      #define MY_RADIO_NRF24
      #define MY_NODE_ID 98
      
      #include "OneButton.h"
      #include <SPI.h>
      #include <MySensors.h>
      #include <Vcc.h>
      
      const float VccMin   = 1.0;           // Minimum expected Vcc level, in Volts.
      const float VccMax   = 6.0;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 1.0 / 1.0; // Measured Vcc by multimeter divided by reported Vcc
      
      Vcc vcc(VccCorrection);
      
      #define SN "MySmartButton"
      #define SV "1.0"
      #define CHILD_ID 1
      #define SLEEP_PIN 2
      // Setup a new OneButton on pin D2. true will set pin high (internal pull up), false will set pin low.
      OneButton button(2, true);
      unsigned long previousMillis = 0;
      unsigned long currentMillis = 0;
      const long interval = 5000;
      
      MyMessage on(CHILD_ID, V_SCENE_ON);
      
      // setup code here, to run once:
      void setup() {
      
        // link the doubleclick function to be called on a doubleclick event.
        button.attachClick(click);
        button.attachDoubleClick(doubleclick);
        button.attachPress(press);
      
      } // setup
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
        present(CHILD_ID, S_SCENE_CONTROLLER);
      }
      
      int messageA = 1;
      int messageB = 2;
      int messageC = 3;
      
      
      void loop() {
        currentMillis = millis();
        // keep watching the push button:
        button.tick();
      //  float p = vcc.Read_Perc(VccMin, VccMax);
      
        sendBatteryLevel((uint8_t)p); //Send battery level to gateway
        if (currentMillis - previousMillis >= interval) {
          Serial.println("we go sleep");
          previousMillis = currentMillis;
          sleep(SLEEP_PIN - 2, CHANGE, 0);
        }
      } // loop
      // this function will be called when the button was pressed one time
      
      void click() {
        send(on.set(messageA));
      }
      // this function will be called when the button was pressed 2 times in a short timeframe.
      void doubleclick() {
        send(on.set(messageB));
      } // doubleclick
      // this function will be called when the button was pressed for about one second
      void press() {
        send(on.set(messageC));
      }
      
      posted in My Project
      xydix
      xydix
    • Smart button / scene controller

      The idea started when i bought a flic smart button.
      Today i use it to raise, lower and play/pause my chromecast audio.
      I want more buttons, actually a want more buttons doing the same thing.
      I have my flic in my kitchen. But when i am at my table? or in my couch?
      Of course, i could buy more flics. But..... Mysensors....
      To start with i will put these button under my tables for easy volume control.

      This is a sleeping node presenting it self as a scene controller.

      If someone want to try a sleeping mysensors smart button. Version 2.X compatible.
      Three functions from one button. Single click, double click and hold.
      You will need to install an external library called Onebutton. This is available in the library manager.

      This have been done before by @dakipro but that thread isn't that easy to find it you search and isn't 2.X compatible.
      By finding that very thread i solved the sleep.

      /*
        Mysensors Smart Button
      */
      
      #define MY_DEBUG
      #define MY_RADIO_NRF24
      
      #include "OneButton.h"
      #include <SPI.h>
      #include <MySensors.h>
      
      #define SN "MySmartButton"
      #define SV "1.0"
      #define CHILD_ID 1
      #define SLEEP_PIN 2
      // Setup a new OneButton on pin D2. true will set pin high (internal pull up), false will set pin low.
      OneButton button(2, true);
      unsigned long previousMillis = 0;
      unsigned long currentMillis = 0;
      const long interval = 5000;
      
      MyMessage on(CHILD_ID, V_SCENE_ON);
      
      // setup code here, to run once:
      void setup() {
      
        // link the doubleclick function to be called on a doubleclick event.
        button.attachClick(click);
        button.attachDoubleClick(doubleclick);
        button.attachPress(press);
      
      } // setup
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
        present(CHILD_ID, S_SCENE_CONTROLLER);
      }
      
      int messageA = 1;
      int messageB = 2;
      int messageC = 3;
      
      
      void loop() {
        currentMillis = millis();
        // keep watching the push button:
        button.tick();
      
        if (currentMillis - previousMillis >= interval) {
          Serial.println("Sleep");
          previousMillis = currentMillis;
          sleep(SLEEP_PIN - 2, CHANGE, 0);
        }
      } // loop
      // this function will be called when the button was pressed one time
      
      void click() {
        send(on.set(messageA));
      }
      // this function will be called when the button was pressed 2 times in a short timeframe.
      void doubleclick() {
        send(on.set(messageB));
      } // doubleclick
      // this function will be called when the button was pressed for about one second
      void press() {
        send(on.set(messageC));
      }
      

      It isn't reporting battery state yet.
      I will add that to the sketch later when i build my button node.
      Maybe i update this thread later when that is done if someone is interested.

      EDIT 2017-06-26
      Some pics.
      0_1498514681220_IMG_20170619_234627.jpg
      0_1498514728022_IMG_20170622_225859.jpg
      0_1498514691129_IMG_20170622_225651.jpg
      0_1498514754436_IMG_20170622_225715.jpg

      posted in My Project
      xydix
      xydix
    • RE: Presentation fails for one sensor but works for another

      Do you use some kind of battery booster / step up regulator?

      posted in Troubleshooting
      xydix
      xydix
    • RE: New nodes, new problems :/ Motion sensor [Solved]

      I guess this thread should be in the hardware forum.
      But if someone find this thread i can share some pictures and the idea with this node.
      I built it as a USB-stick with a USB-connector on a prototype PCB.
      Not good looking but when i get my TV up on the wall you can't see it.
      I use it to turn on light in the bathroom at night if my kids visit the toilet.
      0_1491467736631_IMG_20170406_102320.jpg
      0_1491467746038_IMG_20170406_102342.jpg

      posted in Home Assistant
      xydix
      xydix
    • RE: New nodes, new problems :/ Motion sensor [Solved]

      Thank you @martinhjelmare for that answer. It explains it. i Can confirm this is the issue.
      The pir i am using is this one, the mini pir.
      http://www.ebay.com/itm/121880058682?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

      I tried another pir, the HC-SR501 (http://www.ebay.com/itm/201414880948?rmvSB=true)
      This pir is working ok with the node as it is.
      First i tried an 100uF capacitor as @gohan suggested, but it didn't help.
      Now i tried an 470uF capacitor and it seems to be fine with the mini pir.

      @Vladimir-Dobrikov my radio already got an 100uF for the 3,3V circuit.
      Im am still testing but the node it seems fine for now.
      Thank you all for the help.

      posted in Home Assistant
      xydix
      xydix
    • RE: New nodes, new problems :/ Motion sensor [Solved]

      Just tried it but still same problem.
      I am suspecting hardware issues but always same time stamp makes me wonder.

      posted in Home Assistant
      xydix
      xydix
    • New nodes, new problems :/ Motion sensor [Solved]

      I have a new node, a motion sensor node with repeater.
      Sometimes, when another node change state and communicates through my new repeating node or if another node searching for a new parent, the new repeating node triggers the motion sensor.
      Another strange thing is, 3 times an hour the node triggers the motion.

      This is when i am not home.
      Check time stamp
      19:01 Motion Sensor TV 4 1 turned off
      19:01 Motion Sensor TV 4 1 turned on
      18:41 Motion Sensor TV 4 1 turned off
      18:41 Motion Sensor TV 4 1 turned on
      18:21 Motion Sensor TV 4 1 turned off
      18:21 Motion Sensor TV 4 1 turned on
      18:06 VΓ€der changed to 2
      18:01 Motion Sensor TV 4 1 turned off
      18:01 Motion Sensor TV 4 1 turned on
      17:41 Motion Sensor TV 4 1 turned off
      17:41 Motion Sensor TV 4 1 turned on
      17:21 Motion Sensor TV 4 1 turned off
      17:21 Motion Sensor TV 4 1 turned on
      Just can't figure what makes it trigger on exact times.
      Even if i reset the node it triggers on same times.

      This is the 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 create a node thay repeates messages
       * from nodes far from gateway back to gateway. 
       * It is important that nodes that has enabled repeater mode calls  
       * process() frequently. Repeaters should never sleep. 
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      // Enabled repeater feature for this node
      #define MY_REPEATER_FEATURE
      #define MY_NODE_ID 4
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      #include <SPI.h>
      #include <MySensors.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 CHILD_ID 1   // Id of the sensor child
      
      boolean previousTripped = LOW;
      
      // Initialize motion message
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup() {
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input  
      }
      
      void presentation()  
      {  
        //Send the sensor node sketch version information to the gateway
        sendSketchInfo("Motion Sensor TV", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_MOTION);
      }
      
      void loop() 
      {
        boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
        //Serial.println(tripped);
        // Sensor must be HIGH and not yet sent the status of the sensor
        if ((tripped == HIGH) && (tripped != previousTripped) ) {     
          send(msg.set(tripped ? "1" : "0")); // Send tripped value to gw
          previousTripped = tripped;   
        }  
        
        // Is sensor low and not sent? Then send LOW to gateway
        if ((tripped == LOW) && (tripped != previousTripped)) {    
            send(msg.set(tripped ? "1" : "0")); // Send tripped value to gw
            previousTripped = tripped;
        }
      }
      

      Even tried this sketch but i get the same result.

      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      #define MY_NODE_ID 4
      #define MY_REPEATER_FEATURE
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      #include <SPI.h>
      #include <MySensors.h>
      
      #define CHILD_ID 1   // Id of the sensor child
      #define DIGITAL_INPUT_SENSOR 3   // The digital input you attached your motion sensor.  (Only 2 and 3 generates interrupt!)
      
      int oldTripped = 0;
      int tripped = 0;
      
      // Initialize motion message
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup()  
      {  
        pinMode(DIGITAL_INPUT_SENSOR, INPUT);      // sets the motion sensor digital pin as input
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Motion Sensor TV", "1.0");
      
        // Register all sensors to gw (they will be created as child devices)
        present(CHILD_ID, S_MOTION);
      }
      
      void loop()     
      {
           
      //Read digital motion value
      tripped = digitalRead(DIGITAL_INPUT_SENSOR);
      
      if (tripped != oldTripped){
        Serial.println("Motion");
        send(msg.set(tripped?"1":"0"));  // Send tripped value to gw
        oldTripped = tripped;
      }}
      
      posted in Home Assistant
      xydix
      xydix
    • RE: Arduino UNO R3 maximum current?

      0_1485424008444_IMG_20170125_205415.jpg
      Not so fancy but this is how I did. It will do for now.
      This is the 5V pin under the USB connector.
      Now I get 5V directly from my USB power supply.

      posted in Hardware
      xydix
      xydix
    • Arduino UNO R3 maximum current?

      Hi.
      I am about to add some stuff to my gateway.
      It is an UNO with ethernet sheild powered through USB.

      I will add:
      Relay. measured around 80mA when relay is on.
      lightsensor. ?mA. read somewhere around 0,5mA but let's say atleast 3mA to be sure?

      Replace my cheap nrf radio against a 2.4G 22dBm 100mW NRF24L01P+PA+LNA from icstation.com

      From icstation webpage:

      Maximum power:20dBm(about 100mWοΌ‰
      Gbps:250k,1M,2M, Adjustable
      Emission current:95mA
      Sinks current:20mA

      I am planning to connect these directly to my uno on 3.3V pin and 5V pin.

      I don't know the consumption of the ethernetshield but i read somewhere around 150- 200mA

      Will this work? Will i overload my UNO?

      Any thoughts?

      posted in Hardware
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      When i change

      #define RELAY_ON 1
      #define RELAY_OFF 0
      

      to

      #define RELAY_ON 0
      #define RELAY_OFF 1
      

      The relay stops working.
      Seems strange, but I tried this even before I discovered the problem with node 2.

      When I change it back, the relay works.

      If i want to present my relay as light,
      Should i use S_DIMMER and V_LIGHT?

      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      EDIT!!!!!!!!
      I am sorry. I had several sketches on my computer, trying different stuff.
      When i added && message.sender == 0) { I did this in a sketch where i tried to switch the ON / OFF

      #define RELAY_ON 0
      #define RELAY_OFF 1
      

      This is the error.
      The reason i did this is that I am controlling a wall outlet and want it to be ON even if I remove my GW or if it fails.
      I changed this and got it working now.
      The relay changes state and keep this even if i turn node 2 on or off.
      Sorry for this and thank you for all help.
      I read the serial protocol and the API in the MySensors site but couldn't find anything about message.sender stuff.

      ------ Original Post-------
      Hi.

      At first, the gateway switch was turning on when i tuned node 2 on, then off when i turned node 2 off.

      Then i updated node 2 to 2.1.1 as it was still on 2.0.0.
      I added MY_REPEATER_FEATURE to node2 as it was planned.
      After this i behaivs as i said in post 11.
      Before i did this gateway switch "followed" the state of node 2.
      Now it will only turn off if it is 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
       * Contribution by a-lurker and Anticimex,
       * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
       * Contribution by Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      
      #define CHILD_ID_LIGHT 0
      #define CHILD_ID_RELAY 1
      #define LIGHT_SENSOR_ANALOG_PIN 4
      #define SN "Gateway"
      #define SV "1.0"
      #define RELAY_PIN 3
      #define RELAY_ON 0
      #define RELAY_OFF 1
      
      bool state = false;
      bool initialValueSent = false;
      
      unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
      
      MyMessage msg2(CHILD_ID_RELAY, V_STATUS);
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      int lastLightLevel;
      
      void setup()
      {
        digitalWrite(RELAY_PIN, RELAY_OFF);
        pinMode(RELAY_PIN, OUTPUT);
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        present(CHILD_ID_RELAY, S_BINARY);
      }
      
      void loop()
      {
      
        if (!initialValueSent) {
      //    Serial.println("Sending initial value");
          send(msg2.set(state?RELAY_ON:RELAY_OFF));
      //    Serial.println("Requesting initial value from controller");
          request(CHILD_ID_RELAY, V_STATUS);
          wait(2000, C_SET, V_STATUS);
      
        }  
      
        int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
      //  Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
          send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
        }
        wait(WAIT_TIME);
      }
      
      void receive(const MyMessage &message) {
      
        if (message.type == V_STATUS && message.sender == 0) {
          if (!initialValueSent) {
      //      Serial.println("Receiving initial value from controller");
            initialValueSent = true;
          }
          // Change relay state
          state = (bool)message.getInt();
          digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
          send(msg2.set(state?RELAY_ON:RELAY_OFF));
        }
      }
      

      This is my gateway sketchright now with

       if (message.type == V_STATUS && message.sender == 0) {
      

      With && message.sender == 0 I can't change the state of the relay at all

      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      Tried it.
      Now i can't change the state of the relay anymore.

      I am checking my log again (Post 11 i think.)
      I added an "arrow" in the log below. Is that right?

      17-01-22 23:31:08 mysensors.mysensors: Sending 2;0;1;0;2;1
      
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-20>
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-19>
      17-01-22 23:31:10 mysensors.mysensors: Received 2;0;1;0;2;1
      0;1;1;0;2;0   <<<--------- Is this right????? Where does it come from?
      2;0;1;0;3;100
      
      
      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      Okay. I Think i understand.
      Didn't find much about Message.sender
      But after searching the forum I found something I hope.

      Shall I change this ?

      if (message.type == V_STATUS) {
       
      

      To this?

        if (message.type == V_STATUS && Message.sender == 0) {
       
      
      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      Hi, again.
      I did the changes you suggested and it seem to work ok when i flip the switch.
      But now i have a strange thing happening.

      I have a MySensors dimmer node (Node 2).
      If i turn on my relay in the GW on.
      And then, i change the state of the dimmer (turn on or off)
      it will turn my relay in the GW off.

      In this log i turn my relay on, turn my dimmer on or off.
      and my relay get turned off.
      I repeat these steps a couple of times.

      17-01-22 23:30:51 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
      17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-11, service=turn_on>
      17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-12, service=turn_on>
      17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-12>
      17-01-22 23:30:51 mysensors.mysensors: Sending 2;0;1;0;2;1
      
      17-01-22 23:30:51 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-11>
      17-01-22 23:30:53 mysensors.mysensors: Received 2;0;1;0;2;1
      0;1;1;0;2;0
      2;0;1;0;3;100
      
      17-01-22 23:30:53 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>>
      17-01-22 23:30:53 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:30:53 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:53.836521+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:49.700881+01:00>>
      17-01-22 23:30:53 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
      17-01-22 23:30:53 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:53.919363+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:49.765215+01:00>>
      17-01-22 23:30:54 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:30:54 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:54.040689+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:14.156158+01:00>>
      17-01-22 23:30:54 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:54.126221+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:14.266930+01:00>>
      17-01-22 23:30:57 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=switch.gateway_0_1, service_call_id=3051336336-13, service=turn_on>
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event call_service[L]: domain=switch, service_data=entity_id=['switch.gateway_0_1'], service_call_id=3051336336-14, service=turn_on>
      17-01-22 23:30:57 mysensors.mysensors: Sending 0;1;1;0;2;1
      
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-14>
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-13>
      17-01-22 23:30:57 mysensors.mysensors: Received 0;1;1;0;2;1
      
      17-01-22 23:30:57 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:30:57 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:57.222167+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:53.836521+01:00>>
      17-01-22 23:30:57 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 1
      17-01-22 23:30:57 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:57.303626+01:00>, old_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:53.919363+01:00>>
      17-01-22 23:30:59 homeassistant.components.http: Serving /api/services/homeassistant/turn_off to 192.168.1.8 (auth: True)
      17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-15, service=turn_off>
      17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-16, service=turn_off>
      17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-16>
      17-01-22 23:30:59 mysensors.mysensors: Sending 2;0;1;0;2;0
      
      17-01-22 23:30:59 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-15>
      17-01-22 23:31:00 homeassistant.components.device_tracker.netgear: Scanning
      17-01-22 23:31:00 pynetgear: Get attached devices
      17-01-22 23:31:01 mysensors.mysensors: Received 2;0;1;0;2;0
      0;1;1;0;2;0
      2;0;1;0;3;0
      
      17-01-22 23:31:01 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:01 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:54.040689+01:00>>
      17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:02.060892+01:00>, old_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:30:54.126221+01:00>>
      17-01-22 23:31:02 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:31:02 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:02.205818+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:30:57.222167+01:00>>
      17-01-22 23:31:02 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
      17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:02.299902+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:30:57.303626+01:00>>
      17-01-22 23:31:02 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:02 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
      17-01-22 23:31:05 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=switch.gateway_0_1, service_call_id=3051336336-17, service=turn_on>
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event call_service[L]: domain=switch, service_data=entity_id=['switch.gateway_0_1'], service_call_id=3051336336-18, service=turn_on>
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-18>
      17-01-22 23:31:05 mysensors.mysensors: Sending 0;1;1;0;2;1
      
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-17>
      17-01-22 23:31:05 mysensors.mysensors: Received 0;1;1;0;2;1
      
      17-01-22 23:31:05 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:31:05 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:05.320905+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:02.205818+01:00>>
      17-01-22 23:31:05 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 1
      17-01-22 23:31:05 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:05.384134+01:00>, old_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:02.299902+01:00>>
      17-01-22 23:31:07 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-19, service=turn_on>
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-20, service=turn_on>
      17-01-22 23:31:08 mysensors.mysensors: Sending 2;0;1;0;2;1
      
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-20>
      17-01-22 23:31:08 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-19>
      17-01-22 23:31:10 mysensors.mysensors: Received 2;0;1;0;2;1
      0;1;1;0;2;0
      2;0;1;0;3;100
      
      17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
      17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:31:10 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.311148+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:05.320905+01:00>>
      17-01-22 23:31:10 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
      17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=switch.gateway_0_1, new_state=<state switch.gateway_0_1=off; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=off, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:10.407123+01:00>, old_state=<state switch.gateway_0_1=on; friendly_name=Gateway 0 1, battery_level=0, node_id=0, V_STATUS=on, description=, device=192.168.1.66, child_id=1 @ 2017-01-22T23:31:05.384134+01:00>>
      17-01-22 23:31:10 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.508762+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:01.989013+01:00>>
      17-01-22 23:31:10 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:10.570169+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:02.060892+01:00>>
      17-01-22 23:31:12 homeassistant.components.device_tracker.netgear: Scanning
      17-01-22 23:31:12 pynetgear: Get attached devices
      17-01-22 23:31:13 homeassistant.components.http: Serving /api/services/homeassistant/turn_off to 192.168.1.8 (auth: True)
      17-01-22 23:31:13 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-21, service=turn_off>
      17-01-22 23:31:13 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-22, service=turn_off>
      17-01-22 23:31:14 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-22>
      17-01-22 23:31:14 mysensors.mysensors: Sending 2;0;1;0;2;0
      
      17-01-22 23:31:14 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-21>
      17-01-22 23:31:16 mysensors.mysensors: Received 2;0;1;0;2;0
      0;1;1;0;2;0
      2;0;1;0;3;0
      
      17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.508762+01:00>>
      17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:16.236923+01:00>, old_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:10.570169+01:00>>
      17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:31:16 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.321401+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:10.311148+01:00>>
      17-01-22 23:31:16 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
      17-01-22 23:31:16 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:16 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=100, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
      17-01-22 23:31:18 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.8 (auth: True)
      17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service_data=entity_id=light.kallarvaggen_2_0, service_call_id=3051336336-23, service=turn_on>
      17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event call_service[L]: domain=light, service_data=entity_id=['light.kallarvaggen_2_0'], service_call_id=3051336336-24, service=turn_on>
      17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-24>
      17-01-22 23:31:18 mysensors.mysensors: Sending 2;0;1;0;2;1
      
      17-01-22 23:31:18 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=3051336336-23>
      17-01-22 23:31:20 mysensors.mysensors: Received 2;0;1;0;2;1
      0;1;1;0;2;0
      2;0;1;0;3;100
      
      17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=off, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
      17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 0
      17-01-22 23:31:20 homeassistant.components.mysensors: Gateway 0 0: value_type 23, value = 0
      17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=sensor.gateway_0_0, new_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:20.335924+01:00>, old_state=<state sensor.gateway_0_0=0; friendly_name=Gateway 0 0, battery_level=0, node_id=0, V_LIGHT_LEVEL=0, unit_of_measurement=%, description=, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.321401+01:00>>
      17-01-22 23:31:20 homeassistant.components.mysensors: Gateway 0 1: value_type 2, value = 0
      17-01-22 23:31:20 homeassistant.components.mysensors: Update sensor_update: node 2
      17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=light.kallarvaggen_2_0, new_state=<state light.kallarvaggen_2_0=on; brightness=255, V_PERCENTAGE=100, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:20.488962+01:00>, old_state=<state light.kallarvaggen_2_0=off; V_PERCENTAGE=0, V_STATUS=on, friendly_name=KΓ€llarvΓ€ggen 2 0, battery_level=0, node_id=2, description=, supported_features=145, device=192.168.1.66, child_id=0 @ 2017-01-22T23:31:16.136777+01:00>>
      17-01-22 23:31:20 homeassistant.core: Bus:Handling <Event state_changed[L]: entity_id=group.all_lights, new_state=<state group.all_lights=on; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:20.548609+01:00>, old_state=<state group.all_lights=off; friendly_name=all lights, hidden=True, order=5, entity_id=('light.toan_nere', 'light.kallarvaggen_2_0'), assumed_state=True, auto=True @ 2017-01-22T23:31:16.236923+01:00>>
      17-01-22 23:31:24 homeassistant.components.http: Serving /api/error_log to 192.168.1.8 (auth: True)
      
      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      Now i think i did as you said.
      I did some copy, paste and got it working. I hope i did, hadn't had the time to physical add the relay yet but now it's showing i hass and i can change the state..

      /**
       * 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
       * Contribution by a-lurker and Anticimex,
       * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
       * Contribution by Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      
      #define CHILD_ID_LIGHT 0
      #define CHILD_ID_RELAY 1
      #define LIGHT_SENSOR_ANALOG_PIN 4
      #define SN "Gateway"
      #define SV "1.0"
      #define RELAY_PIN 3
      #define RELAY_ON 1
      #define RELAY_OFF 0
      
      bool state = false;
      bool initialValueSent = false;
      
      unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
      
      MyMessage msg2(CHILD_ID_RELAY, V_STATUS);
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      int lastLightLevel;
      
      void setup()
      {
        digitalWrite(RELAY_PIN, RELAY_OFF);
        pinMode(RELAY_PIN, OUTPUT);
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
        present(CHILD_ID_RELAY, S_BINARY);
      }
      
      void loop()
      {
      
        if (!initialValueSent) {
      //    Serial.println("Sending initial value");
          send(msg2.set(state?RELAY_ON:RELAY_OFF));
      //    Serial.println("Requesting initial value from controller");
          request(CHILD_ID_RELAY, V_STATUS);
          wait(2000, C_SET, V_STATUS);
          send(msg2.set(state?RELAY_ON:RELAY_OFF), true);
        }  
      
        int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
      //  Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
          send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
        }
        wait(WAIT_TIME);
      }
      
      void receive(const MyMessage &message) {
        if (message.isAck()) {
      //     Serial.println("This is an ack from gateway");
        }
      
        if (message.type == V_STATUS) {
          if (!initialValueSent) {
      //      Serial.println("Receiving initial value from controller");
            initialValueSent = true;
          }
          // Change relay state
          state = (bool)message.getInt();
          digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
          send(msg2.set(state?RELAY_ON:RELAY_OFF));
        }
      }
      

      Is the sketch OK?
      Anything i could remove or should add?

      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      Thank you for your answears.
      I will try to modify the sketch when i have the time.
      Can i just add

          request(CHILD_ID, V_STATUS);
          wait(2000, C_SET, V_STATUS);
      

      In the loop?

      Isn't it possible to add a WAIT in the setup?
      My hass is at the moment running on an Raspberry Pi Zero so startup is pretty slow.

      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      I do not have access to my GW right now so i haven't removed

      bool initialValueSent = false;
      

      But i guess this won't cause this problem?

      Here is my log after restartof hass

      https://hastebin.com/enutahepac.php

      I can't find anything, but i am a noob πŸ˜„

      posted in Home Assistant
      xydix
      xydix
    • RE: My first relay. connected to GW 2.1.0

      In hass i get this during startup.

      mysensors.mysensors: child_id 0 already exists in children of node 0, cannot add child
      17-01-15 20:48:49 mysensors.mysensors: child_id 1 already exists in children of node 0, cannot add child

      I'm not sure child 1 is in my mysensors.json

      {"0": {"sensor_id": 0, "battery_level": 0, "type": 18, "sketch_name": "Ljus Uppe", "children": {"0": {"values": {"23": "3"}, "type": 16, "id": 0, "description": ""}, "sketch_version": "1.0", "protocol_version": "2.1.0"}
      

      I think this is all for node 0

      posted in Home Assistant
      xydix
      xydix
    • My first relay. connected to GW 2.1.0

      My first relay....
      I am about to update my gateway to 2.1.0.
      While i am doing this i want to add a light sensor and a relay to it.
      I know i have a lot to learn about arduino and MySensors and now i am stuck.

      /**
       * 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
       * Contribution by a-lurker and Anticimex,
       * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
       * Contribution by Tomas Hozza <thozza@gmail.com>
       *
       *
       * DESCRIPTION
       * The EthernetGateway sends data received from sensors to the ethernet link.
       * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
       *
       * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
       *
       * LED purposes:
       * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
       * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve crc error
       *
       * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
       *
       */
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable gateway ethernet module type
      #define MY_GATEWAY_W5100
      
      // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
      //#define MY_W5100_SPI_EN 4
      
      // Enable Soft SPI for NRF radio (note different radio wiring is required)
      // The W5100 ethernet module seems to have a hard time co-operate with
      // radio on the same spi bus.
      #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 14
      #define MY_SOFT_SPI_MISO_PIN 16
      #define MY_SOFT_SPI_MOSI_PIN 15
      #endif
      
      // When W5100 is connected we have to move CE/CSN pins for NRF radio
      #ifndef MY_RF24_CE_PIN
      #define MY_RF24_CE_PIN 5
      #endif
      #ifndef MY_RF24_CS_PIN
      #define MY_RF24_CS_PIN 6
      #endif
      
      // Enable to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 192,168,1,66   // If this is disabled, DHCP is used to retrieve address
      // Renewal period if using DHCP
      //#define MY_IP_RENEWAL_INTERVAL 60000
      // The port to keep open on node server mode / or port to contact in client mode
      #define MY_PORT 5003
      
      // Controller ip address. Enables client mode (default is "server" mode).
      // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
      //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
      
      // The MAC address can be anything you want but should be unique on your network.
      // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
      // Note that most of the Ardunio examples use  "DEAD BEEF FEED" for the MAC address.
      #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
      
      // Enable inclusion mode
      #define MY_INCLUSION_MODE_FEATURE
      // Enable Inclusion mode button on gateway
      //#define MY_INCLUSION_BUTTON_FEATURE
      // Set inclusion mode duration (in seconds)
      #define MY_INCLUSION_MODE_DURATION 60
      // Digital pin used for inclusion mode button
      //#define MY_INCLUSION_MODE_BUTTON_PIN  3
      
      // Set blinking period
      #define MY_DEFAULT_LED_BLINK_PERIOD 300
      
      // Flash leds on rx/tx/err
      // Uncomment to override default HW configurations
      //#define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
      //#define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
      //#define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
      
      
      #if defined(MY_USE_UDP)
      #include <EthernetUdp.h>
      #endif
      #include <Ethernet.h>
      #include <MySensors.h>
      
      #define CHILD_ID_LIGHT 0
      #define LIGHT_SENSOR_ANALOG_PIN 4
      #define SN "Ljus Uppe"
      #define SV "1.0"
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      bool initialValueSent = false;
      unsigned long WAIT_TIME = 30000; // Wait time between reads (in milliseconds)
      
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      int lastLightLevel;
      
      void before()
      {
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
          // Then set relay pins in output mode
          pinMode(pin, OUTPUT);
          // Set relay to last known state (using eeprom storage)
          digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
      }
      
      
      void setup()
      {
      
           if (!initialValueSent) {
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS;sensor++, pin++) {
          MyMessage msg2(sensor, V_STATUS);
          Serial.println("Sending initial value");
          send(msg2.set(0));
          wait(1000);
          }
        initialValueSent = true;
        }
      
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SN, SV);
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      
      
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
          // Register all sensors to gw (they will be created as child devices)
          present(sensor, S_BINARY);
        }
      
      }
      
      void loop()
      {
        
        int16_t lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
      //  Serial.println(lightLevel);
        if (lightLevel != lastLightLevel) {
          send(msg.set(lightLevel));
          lastLightLevel = lightLevel;
        }
        wait(WAIT_TIME);
      }
      
      void receive(const MyMessage &message)
      {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
          // Change relay state
          digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_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());
        }
      }
      
      

      The lightsensor seems to work.
      I can't get the relay working. It is not showing in hass.
      Anyone want to check my sketch and gice me any tips.

      posted in Home Assistant
      xydix
      xydix
    • RE: Dual mode for battery powered sensors

      Is there any progress in this area?
      I guess this is not the same as smart sleep?

      posted in Feature Requests
      xydix
      xydix
    • RE: πŸ’¬ FOTA (Wireless Programming)

      Sorry for asking stupid questions but, "USBtinyISP AVR ISP Programmer" from the shopping guide. Is this able to do the same as "usbasp (clone, USBASP 2.0 LC Technology)" in this guide.

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ FOTA (Wireless Programming)

      Can i even have it powered during the process?

      posted in Announcements
      xydix
      xydix
    • RE: πŸ’¬ FOTA (Wireless Programming)

      Is it possible to flash bootloader to a pro mini with the radio attached?
      I want OTA but have some nodes with not-so-easy-to-remove radios πŸ˜ƒ

      posted in Announcements
      xydix
      xydix
    • RE: Battery booster / voltage regulator

      Thank you for answer @scalz
      While the node sleep it consumes 0,2uA. Transmitting is around 20mA when it try to present itself.
      0,7V will give me 3-3,1V for this node i measring right now.
      Isn't that a little low? What do you think?
      I dont know how sensitive the pro mini and nrf-radio is if the voltage drop under 3.3V.
      Will the diode consume power?
      Looked at schottky diode on eBay. Any specific i should choose?

      posted in Hardware
      xydix
      xydix
    • Battery booster / voltage regulator

      Hi guys.
      On my battery powered sensors, pro minis with voltage regulator removed, with battery booster i have a problem.
      My battery booster give about 3,6V-3,8V.
      With Mysensors 2.0 this cause a problem under presentation. I don't know why.
      Is there a way to get my boosters closer to 3,3V without replacing them?
      I guess a resistor is a bad idea? Would probably cause unstable voltage when the power consumption changes?
      Any thouhts on this.

      This is the booster i use:
      http://www.ebay.com/itm/181612513907?rmvSB=true

      posted in Hardware
      xydix
      xydix
    • RE: Communication problems v2.0.0 between GW and nodes.

      @bisschopsr
      Have you solved your problem?
      I have nodes running fine on 1.5 but i have problem with 2.0
      I get the same as you in my serial monitor from my GW and nodes.
      My issue was (still is) that i use pro minis with voltage regulator removed and a battery booster.
      My battery booster give me 3,36V -3,38V.
      This cause problems under the presentation on 2.0.
      If i get lower voltage, closer to 3,3V the problem is gone.
      It turns out that i little to high voltage can cause this.

      posted in Hardware
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      Okay, i think i found a solution.
      On my sensors i removed the onboard voltage regulator.
      By coincidence i powered my sensor from only one AA battery when i was testing. I use battery booster and 2 AA otherwise.
      Sudenly it worked. Presentation happend and sensor is working.
      I measured again with a better multimeter. With one AA battery: 3,34V, with two AA batteries: 3,38V.
      I tested several times and this is really the issue. I guess the pro mini or the radio is sensitive when it comes to higher voltage than 3.3V
      After presentation i added the second battery without disconnecting and now it works.
      This was never a problem with Mysensors 1.5.
      Is the presentation more "sensitive" in 2.0?
      Can anyone explain why this happend? Someone said that the NRF24-radio can handle up to 3,6V.
      Anyone know how to "fix" a batterybooster?

      Please, if someone know. Tell me/us.

      BUT! If you have problems with a sensor and use batterybooster/ removed onboard voltage regulator. Check voltage.

      posted in Troubleshooting
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      I had it working like one day.
      Now i have problems again. πŸ‘Ž
      Right now i am only using 2 nodes, batterypowered doorswitches.
      I did a small change in one of my sketches, after that it didn't present itself to the GW/controller I guess.
      I use Home Assistant as controller, and i deleted my "mysensors.json-file" to do a fresh start.
      After this i can't get any node working.
      Side by side log from serial monitor:
      0_1473238590913_upload-d9867691-1703-476d-b2b4-509fd60e799d

      @tekka GW recive messages, right? But node don't receive it?

      @martinhjelmare
      I hope you are the right person to ask because i use Home Assistant.
      Can you please check my sketch.
      Like i said, earlier it woked.
      No error in HA log.

      /**
       * 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.
       *
       *******************************
       *
       * DESCRIPTION
       *
       * Interrupt driven binary switch example with dual interrupts
       * Author: Patrick 'Anticimex' Fallberg
       * Connect one button or door/window reed switch between 
       * digitial I/O pin 3 (BUTTON_PIN below) and GND and the other
       * one in similar fashion on digital I/O pin 2.
       * This example is designed to fit Arduino Nano/Pro Mini
       * 
       */
      
      
      // Enable debug prints to serial monitor
      #define MY_DEBUG 
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      #define MY_RF24_PA_LEVEL RF24_PA_MAX
      
      #include <SPI.h>
      #include <MySensors.h>
      
      #define SKETCH_NAME "Basementdoor"
      #define SKETCH_MAJOR_VER "1"
      #define SKETCH_MINOR_VER "0"
      
      int BATTERY_SENSE_PIN = A0;  // select the input pin for the battery sense point
      int oldBatteryPcnt = 0;
      #define CHILD_ID 3
      
      
      #define BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
      
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      
      void setup()  
      {  
        
             // use the 1.1 V internal reference
      #if defined(__AVR_ATmega2560__)
         analogReference(INTERNAL1V1);
      #else
         analogReference(INTERNAL);
      #endif
        
        // Setup the buttons
        pinMode(BUTTON_PIN, INPUT);
        
      
        // Activate internal pull-ups
      //  digitalWrite(PRIMARY_BUTTON_PIN, HIGH);
      
      }
      
      void presentation() {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER);
      
        // Register binary input sensor to sensor_node (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        present(CHILD_ID, S_DOOR);  
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop() 
      {
        uint8_t value;
        static uint8_t sentValue=2;
        
        // Short delay to allow buttons to properly settle
        sleep(5);
        
        value = digitalRead(BUTTON_PIN);
        
        if (value != sentValue) {
           // Value has changed from last transmission, send the updated value
           send(msg.set(value==HIGH ? 0 : 1));
           sentValue = value;
        }
      
            // get the battery Voltage
         int sensorValue = analogRead(BATTERY_SENSE_PIN);
         #ifdef MY_DEBUG
         Serial.println(sensorValue);
         #endif
         
         // 1M, 470K divider across battery and using internal ADC ref of 1.1V
         // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
         // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
         // 3.44/1023 = Volts per bit = 0.003363075
         
         int batteryPcnt = sensorValue / 10;
      
         #ifdef MY_DEBUG
         float batteryV  = sensorValue * 0.003363075;
         Serial.print("Battery Voltage: ");
         Serial.print(batteryV);
         Serial.println(" V");
      
         Serial.print("Battery percent: ");
         Serial.print(batteryPcnt);
         Serial.println(" %");
         #endif
      
         if (oldBatteryPcnt != batteryPcnt) {
           // Power up radio after sleep
           sendBatteryLevel(batteryPcnt);
           oldBatteryPcnt = batteryPcnt;
         }
        
        // Sleep until something happens with the sensor
        if(isTransportOK()){
          sleep(BUTTON_PIN-2, CHANGE, 0);  // transport is OK, node can sleep
        } 
        else {
          wait(5000); // transport is not operational, allow the transport layer to fix this
        }
        
        
      } 
      

      I read this:
      Send at least one initial value per V_TYPE. In version 2.0 of MySensors this has to be done in the loop function. See below for an example in 2.0 of how to make sure the initial value has been received by the controller.
      But not sure if it is needed here and how to put that in my sketch. Please help a Newbe.
      Edit:
      BTW. I guess many had problem like this due to powering problems. When i measure, it's steady 3,36V on VCC and on my radio.

      posted in Troubleshooting
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      I searched the forum and found a thread about this.
      @tekka you posted this:

      replace

      sleep(30000);
      

      with

      if(isTransportOK()){
          sleep(30000);  // transport is OK, node can sleep
        } 
        else {
          wait(5000); // transport is not operational, allow the transport layer to fix this
        }
      

      And this will do it.
      Now my node reconnect.
      Is this the best way to do it?
      I use battery powered sensors. Will this drain my batteries?
      Will my node sleep as it should?
      Haven't hade the time to measure this yet.

      posted in Troubleshooting
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      @tekka I left it running with the serial montor for about an hour but it didn't reconnect. Only !TSP:SEND:TNR
      I guess i have to set a static parent.
      What is the point of this? Was it the same in 1.5?

      posted in Troubleshooting
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      Thank you guys for answers.
      @tekka
      What i want here is to know my sensors won't get in a state when i have to reset them.
      I have one door sensor that is to far away and sometimes it won't reach the gateway. I will fix this later.
      But still, i want to be sure my sensors reconnect to my GW.
      If i for some reason have to disconnect my GW and open some doors, this will result in that i have to reset them later when my GW is up.
      Thanks for reminding me to define PA level. Totally forgot about that.

      posted in Troubleshooting
      xydix
      xydix
    • RE: From 1.5 to 2.0. Can't get it running

      Yeah i saw this after i got in bed so i was about to try this in the morning.
      But thank you for your answer.
      Now i got my GW running but i got a new problem.

      If my node fail to deleiver a message for the last 6 tries i "gives up"

      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:1
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:0
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:1
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=fail:0
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=1,st=fail:1
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=2,st=ok:0
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:1
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:0
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:1
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:0
      TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:1
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=fail:0
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=1,st=fail:1
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=2,st=fail:0
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=3,st=fail:1
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=4,st=fail:0
      !TSP:MSG:SEND 3-3-0-0 s=4,c=1,t=16,pt=2,l=2,sg=0,ft=5,st=fail:1
      !TSM:UPL FAIL, SNP
      TSM:FPAR
      TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      !TSP:SEND:TNR
      

      After this i can't get it to transmit any more and i have to push the resetbutton.
      In this example i use a binary switch, pushing my button and when i hold my hand over the radio so the signal won't reach my GW this happends.
      Any thoughts?
      Thanks.

      posted in Troubleshooting
      xydix
      xydix
    • From 1.5 to 2.0. Can't get it running

      Hi.
      Decided to go for 2.0.

      I use an ethernet gateway (an uno with w5100 sheild. The same i used with 1.5) and my sensors can't find the gateway.
      I use the NRF radio wired just lite i had before. That i right, yes?
      I downloded a fresh library from arduino library manager today.
      Loaded the sketch to my gateway. I didn't change anything in MyConfig.h or MySensors.h
      The only thing i changed in the sketch was the IP.

      Serial monitor gateway:

      0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSM:RADIO:OK
      0;255;3;0;9;TSM:GW MODE
      0;255;3;0;9;TSM:READY
      IP: 192.168.1.66
      0;255;3;0;9;Starting gateway (RNNGA-, 2.0.0)
      0;255;3;0;9;TSM:INIT
      0;255;3;0;9;TSM:RADIO:OK
      0;255;3;0;9;TSM:GW MODE
      0;255;3;0;9;TSM:READY
      IP: 192.168.1.66
      

      Serial monitor node:

      Starting sensor (RNNNA-, 2.0.0)
      TSM:INIT
      TSM:RADIO:OK
      TSP:ASSIGNID:OK (ID=3)
      TSM:FPAR
      TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
      TSM:FPAR
      TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
      TSM:FPAR
      TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
      TSM:FPAR
      TSP:MSG:SEND 3-3-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
      !TSM:FPAR:FAIL
      !TSM:FAILURE
      TSM:PDT
      

      I tried different sketches from the examples and tried to set ID manually.
      I tried to switch radios. I use a capacitor on the radios.
      I tried different power supplys
      Please help. I going crazy.

      posted in Troubleshooting
      xydix
      xydix
    • RE: Powering a sensor with digital out

      This sounds like a really good idea.
      Can I use this to power like a DS18B20 tempsensor. Would this save power and give my battery powered sensors extended battery life?

      posted in Development
      xydix
      xydix
    • RE: Is this completely wrong?

      Thank you. That will get it right.
      But now I get the delay when the door open.
      I guess I need a pull down resistor for this to work. 4.7k? 10k?
      I guess it's the internal pull up that consumes power?
      Another thing.
      I changed digitalWrite = HIGH (original example)
      to
      Pinmode INPUT_PULLUP
      in my first sketch

      Wich option is best if I want low power consumption?

      posted in Development
      xydix
      xydix
    • Is this completely wrong?

      Hi.
      I am about to set up a battery-switch-node with Home Assistant as controller.
      It's a mini pro 3V3 with led and regulator removed.
      I am trying two different sketches and will try to get low power consumption .

      Here i use pin 3 and ground.

      #include <MySensor.h>
      #include <SPI.h>
      
      #define SN "TestSleepSensor"
      #define SV "1.0"
      
      #define CHILD_ID 3
      
      #define BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
      
       
      MySensor sensor_node;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup()  
      {  
        sensor_node.begin();
      
        // Setup the buttons
        pinMode(BUTTON_PIN, INPUT_PULLUP);
        
        // Send the sketch version information to the gateway and Controller
        sensor_node.sendSketchInfo(SN, SV);
      
        // Register binary input sensor to sensor_node (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        sensor_node.present(CHILD_ID, S_DOOR);  
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop() 
      {
        uint8_t value;
        static uint8_t sentValue=2;
      
        // Short delay to allow buttons to properly settle
        sensor_node.sleep(5);
        
        value = digitalRead(BUTTON_PIN);
        
        if (value != sentValue) {
           // Value has changed from last transmission, send the updated value
           sensor_node.send(msg.set(value==LOW ? 1 : 0));
           sentValue = value;
        }
      
        // Sleep until something happens with the sensor
        sensor_node.sleep(BUTTON_PIN-2, CHANGE, 0);
      }
      

      This seems to work. I can't tell if it's good or not. Its my first, a example i chaged.
      It consumes about 0.09mA when the connector is closed witch it will be most of the time.
      When switch is open it consumes less.

      Here i use pin 3 and VCC

      #include <MySensor.h>
      #include <SPI.h>
      
      #define SN "TestSleepSensor"
      #define SV "1.0"
      
      #define CHILD_ID 3
      
      #define BUTTON_PIN 3   // Arduino Digital I/O pin for button/reed switch
      
       
      MySensor sensor_node;
      
      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID, V_TRIPPED);
      
      void setup()  
      {  
        sensor_node.begin();
      
        // Setup the buttons
        pinMode(BUTTON_PIN, INPUT);
        
        // Send the sketch version information to the gateway and Controller
        sensor_node.sendSketchInfo(SN, SV);
      
        // Register binary input sensor to sensor_node (they will be created as child devices)
        // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage. 
        // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
        sensor_node.present(CHILD_ID, S_DOOR);  
      }
      
      // Loop will iterate on changes on the BUTTON_PINs
      void loop() 
      {
        uint8_t value;
        static uint8_t sentValue=2;
      
        // Short delay to allow buttons to properly settle
        sensor_node.sleep(5);
        
        value = digitalRead(BUTTON_PIN);
        
        if (value != sentValue) {
           // Value has changed from last transmission, send the updated value
           sensor_node.send(msg.set(value==HIGH ? 1 : 0));
           sentValue = value;
        }
      
        // Sleep until something happens with the sensor
        sensor_node.sleep(BUTTON_PIN-2, CHANGE, 0);
      }
      

      This consumes less when the switch is closed, approx 1.2uA according to my multimeter. it seems very low but anyway, it's much lower than the other sketch.
      One thing with this. When door is open it shows closed in the controller and the other way around. Can i fix it?
      Another thing. When i open my switch, it takes about 2-3 seconds before it send the changed state. Not a problem but i guess it is since i feed the pin directly from VCC?

      Is this stupid? I am New to this.

      posted in Development
      xydix
      xydix
    • Radios -Again

      Hi i am still very new to all this. Havent received my ethernet sheild yet but did some testing with a serial gateway and IDE serial monitor.
      I read several threads about radios.
      I bought some NRF24l01+ (from ebay link in mysensors store) and seems to get i range about 10-13 meters indoor but no walls between.
      If i have walls and about 7 meters between the signal is lost.
      What can i expect?
      I was thinking about buying a NRF24L01+PA+LNA for my gateway but in the comments on Aliexpress people doesn't seem to get that much improvement.
      Of course, genuine Nordic radios would be nice but i am to cheep for that.
      I want good copies. But where? How will i find a seller that sell good low price radios.
      And next question, is NRF24l01+ still the way to go?

      posted in Hardware
      xydix
      xydix
    • RE: Pro mini

      But if i want to save battery, shall i cut the regulator on the pro mini even if i am planning to feed it with 3v (2 AA) to VCC?
      Or is it better with a 9V to the RAW and keep the onboard regulator?

      posted in Hardware
      xydix
      xydix
    • RE: Pro mini

      @Oitzu
      Thanks for the quick reply.
      Nice to got that sorted out.
      Thank you.

      posted in Hardware
      xydix
      xydix
    • Pro mini

      Hi guys.
      I recently discovered mysensors and arduino.
      Im still waiting for stuff to build my gateway but today i recieved my first pro mini bought on ebay
      This is in the mysensors store.
      In the description on ebay it say 3.3V
      On the back on the board it say
      *8Mhz
      *16Mhz
      *20mhZ
      *3V3
      *5V
      in a comment on ebay someone say "3.3 or 5v flexibility"
      Can i feed this with 5v on the VCC?

      posted in Hardware
      xydix
      xydix