Serial Monitor of the gateway shows change but no change on the vera



  • On the serial monitor output I see motion being changed. But I can not see the change being made on the vera.

    send: 31-31-0-0 s=255,c=3,t=11,pt=0,l=16,sg=0,st=ok:RGB Led strip 3D
    send: 31-31-0-0 s=255,c=3,t=12,pt=0,l=2,sg=0,st=ok:v1
    send: 31-31-0-0 s=6,c=0,t=4,pt=0,l=17,sg=0,st=ok:present RED light
    send: 31-31-0-0 s=4,c=0,t=4,pt=0,l=19,sg=0,st=ok:present GREEN light
    send: 31-31-0-0 s=5,c=0,t=4,pt=0,l=18,sg=0,st=ok:present BLUE light
    send: 31-31-0-0 s=0,c=0,t=3,pt=0,l=19,sg=0,st=ok:present Show button
    send: 31-31-0-0 s=3,c=0,t=1,pt=0,l=14,sg=0,st=ok:present Motion
    Load from eeprom RED: 0%
    Load from eeprom GREEN: 0%
    Load from eeprom BLUE: 0%
    Send eeprom value to controler
    send: 31-31-0-0 s=6,c=1,t=3,pt=1,l=1,sg=0,st=ok:0
    send: 31-31-0-0 s=4,c=1,t=3,pt=1,l=1,sg=0,st=ok:0
    send: 31-31-0-0 s=5,c=1,t=3,pt=1,l=1,sg=0,st=ok:0
    send: 31-31-0-0 s=0,c=1,t=2,pt=2,l=2,sg=0,st=ok:0
    Ready to receive messages...
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:1
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:0
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:1
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:0
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:1
    send: 31-31-0-0 s=3,c=1,t=1,pt=1,l=1,sg=0,st=ok:0
    

    As seen after Ready to receive messages... that is the motion sensor working but in Vera it shows no difference here is the code used it is a mix of @hek RGB code mixed with a motion sensor. The idea of the motion sensor is just to report if there is motion. It is a presence sensor for the room if I want it to turn on the the LED it will be scripted separate from the arduino code.

    /**
     * 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 - Created by vil1driver
     * 
     * DESCRIPTION
     * RGB led strip controled with three dimmers + one On/Off for run/stop rgb color cycle :p
     * 
     */
     
    #define SN   "RGB Led strip 3D"
    #define SV   "v1"
    
    // Load mysensors library  
    #include <MySensor.h> 
    // Load Serial Peripheral Interface library  
    #include <SPI.h>
    
    // Arduino pin attached to MOSFET Gate pin
    #define RED_PIN 4   
    #define GREEN_PIN 5
    #define BLUE_PIN 6
    // added motion
    #define Motion_PIN 3
    #define INTERRUPT Motion_PIN-2
    uint8_t lastMotion = 0;
    
    
    unsigned long previousMillis = 0; // last time update //see http://stackoverflow.com/questions/10773425/performing-a-function-after-x-time for more details on this
    unsigned long motionDelay = 10000; // interval at which to keep motion sensor trippped (milliseconds).  Used to prevent too frequent updates to Vera. 
    
    
    MySensor gw;  
    
    // Define message name and type to send sensor info
    MyMessage RedStatus(RED_PIN, V_DIMMER);   
    MyMessage GreenStatus(GREEN_PIN, V_DIMMER);
    MyMessage BlueStatus(BLUE_PIN, V_DIMMER);
    MyMessage Status(1, V_DIMMER);
    MyMessage rgbShowState(0, V_LIGHT);
    MyMessage MotionStatus(Motion_PIN, S_MOTION);
        
    // Serial.print translate sensor id to sensor name
    char color[][6] = {"","","","RED","","GREEN","BLUE"}; 
       
    // Vars for rgbShow function
    int redval = 0;
    int greenval = 0;
    int blueval = 0;
    long time=0;
    int isShow;
         
    void setup() 
    {
      //motion setup
      //pinMode(Motion_PIN, INPUT);
      // Initializes the sensor node (Callback function for incoming messages, node id, is repeater)
      gw.begin(incomingMessage, AUTO, true);    
           
      // Present sketch (name, version)
      gw.sendSketchInfo(SN, SV);        
           
      // Register sensors (id, type, description, ack back)
      gw.present(RED_PIN, S_DIMMER, "present RED light", false);
      gw.present(GREEN_PIN, S_DIMMER, "present GREEN light", false);
      gw.present(BLUE_PIN, S_DIMMER, "present BLUE light", false);
      gw.present(0, S_LIGHT, "present Show button", false);
    
      // motion present
      gw.present(Motion_PIN, S_MOTION, "present Motion", false);
      
      // Define pin mode (pin number, type)
      pinMode(RED_PIN, OUTPUT);   
      pinMode(GREEN_PIN, OUTPUT);
      pinMode(BLUE_PIN, OUTPUT);
      pinMode(Motion_PIN, INPUT);
    
      // Correct saved RGB value for first start
      gw.saveState(RED_PIN, constrain((int8_t)gw.loadState(RED_PIN), 0, 100)); 
      gw.saveState(GREEN_PIN, constrain((int8_t)gw.loadState(GREEN_PIN), 0, 100)); 
      gw.saveState(BLUE_PIN, constrain((int8_t)gw.loadState(BLUE_PIN), 0, 100)); 
                 
      // Get value from eeprom and write to output
      analogWrite(RED_PIN, 255 * gw.loadState(RED_PIN) / 100);    
      analogWrite(GREEN_PIN, 255 * gw.loadState(GREEN_PIN) / 100);
      analogWrite(BLUE_PIN, 255 * gw.loadState(BLUE_PIN) / 100);
             
      // Write some debug info
      Serial.print("Load from eeprom RED: "); 
      Serial.print(gw.loadState(RED_PIN)); 
      Serial.println("%"); 
      Serial.print("Load from eeprom GREEN: "); 
      Serial.print(gw.loadState(GREEN_PIN)); 
      Serial.println("%"); 
      Serial.print("Load from eeprom BLUE: "); 
      Serial.print(gw.loadState(BLUE_PIN)); 
      Serial.println("%");  
      
      // Send RGB value to controler (request ack back: true/false)
      Serial.println("Send eeprom value to controler"); 
      gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );    
      gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
      gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
      
      // Correct RGB show state for first start and load it (set to 'On' at first start)
      gw.saveState(0, constrain((int8_t)gw.loadState(0), 0, 1));
      isShow=gw.loadState(0);
           
      // Send RGB show state to controler (request ack back: true/false)
      gw.send( rgbShowState.set(isShow), false);
      
      if (isShow==1){Serial.println("RGB show running..."); }
      Serial.println("Ready to receive messages...");  
    }
    
    void loop()
    {
      // Process incoming messages (like config and light state from controller)
      gw.process();   
          
      // Run RGB show if is set
      if (isShow==1)
      {
          rgbShow();
        analogWrite(RED_PIN, redval);
        analogWrite(GREEN_PIN, greenval);
        analogWrite(BLUE_PIN, blueval);
    
      }
    
        // Read digital motion value
       unsigned long currentMillis = millis();
      
         if(currentMillis - previousMillis > motionDelay){
          uint8_t motionDetect = digitalRead(Motion_PIN);
      
          if(motionDetect != lastMotion){
    //        Serial.print("motionDetect Value: ");
    //        Serial.println(motionDetect);
            gw.send(MotionStatus.set(motionDetect));  // Send tripped value to gw
            
            if(motionDetect == 1){
              previousMillis = currentMillis;  //"Tripped" delay 
            }
            else{
              previousMillis = currentMillis - motionDelay + 1000; //"Not tripped" delay for 1 second to stop rapid "not tripped" and "tripped" updates to Vera
            }
      
             lastMotion = motionDetect; 
          }    
        
         }
    }
    
    void incomingMessage(const MyMessage &message)
    {
      if (message.isAck())
      {
        Serial.println("Got ack from gateway");
      }
      if (message.type == V_LIGHT)
      {
        // Incoming on/off command sent from controller ("1" or "0")
        int lightState = message.getString()[0] == '1';
      
        // if receive RGB Show On commands, start the show
        if (message.sensor==0 && lightState==1){ rgbShowOn(); }
            // if receive RGB Show Off commands, stop the show
        else if (message.sensor==0 && lightState==0){ rgbShowOff(); }
           
        // if receive RGB switch On command
        else if (lightState==1)
        {
          // Write some debug info
                Serial.print("Incoming change for ");
                Serial.print(color[message.sensor]);
                Serial.println(": On");
                Serial.print("Load from eeprom: ");
              
          if ( gw.loadState(message.sensor) == 0)
          {
            // Pick up last saved dimmer level from the eeprom
                    analogWrite(message.sensor, 255 * gw.loadState(10*message.sensor) / 100);
                    // Save loaded value to current
                    gw.saveState(message.sensor, gw.loadState(10*message.sensor));
                    Serial.print(gw.loadState(10*message.sensor)); 
                    Serial.println("%");
                    // Send value to controler
                    Serial.println("Send value to controler");
                    gw.send(Status.setSensor(message.sensor).set(gw.loadState(10*message.sensor)),false);
                }
                else
                {
                    // Pick up last saved dimmer level from the eeprom
                    analogWrite(message.sensor, 255 * gw.loadState(message.sensor) / 100);
                    Serial.print(gw.loadState(message.sensor));
                    Serial.println("%"); 
                    // Send value to controler
                    Serial.println("Send value to controler");
                    gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
                } 
                // Stop the show if it's running
                if (isShow==1){ rgbShowStop(message.sensor); }
            }
        // if recieve switch Off command
        else if (lightState==0)
        {
          // Write output to 0 (Off)
                analogWrite(message.sensor, 0);
                // Save old value to eeprom if it'was not zero
                if ( gw.loadState(message.sensor) != 0 )
                {
                    gw.saveState(10*message.sensor, constrain((int8_t)gw.loadState(message.sensor), 0, 100)); 
                }
                // Save new value to eeprom
                gw.saveState(message.sensor, 0); 
                // Write some debug info
          Serial.print("Incoming change for ");
          Serial.print(color[message.sensor]);
          Serial.print(": ");
          Serial.println("Off");  
                Serial.print("Store old value: ");
                Serial.print(gw.loadState(10*message.sensor));  
                Serial.println("%");
                // Send value to controler
                Serial.println("Send value to controler");
                gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
          // Stop the show if it's running
          if (isShow==1){ rgbShowStop(message.sensor); }
        }
      }
      else if (message.type == V_DIMMER)
      {    
          uint8_t incomingDimmerStatus = message.getByte();
          // limits range of sensor values to between 0 and 100 
          incomingDimmerStatus = constrain((int8_t)incomingDimmerStatus, 0, 100);
          // Change Dimmer level
          analogWrite(message.sensor, 255 * incomingDimmerStatus / 100);
          //Save value to eeprom
          gw.saveState(message.sensor, incomingDimmerStatus); 
          // Write some debug info
          Serial.print("Incoming change for ");
          Serial.print(color[message.sensor]);
          Serial.print(": ");
          Serial.print(incomingDimmerStatus);
          Serial.println("%");
            // Send value to controler
            Serial.println("Send value to controler");
            gw.send(Status.setSensor(message.sensor).set(gw.loadState(message.sensor)),false);
          // Stop the show if it's running
          if (isShow==1){ rgbShowStop(message.sensor); }
        }
    }
       
    void rgbShow()
    {
      time = millis();
      redval = 128+250*cos(2*PI/300000*time);
      greenval = 128+250*cos(2*PI/300000*time-222);
      blueval = 128+250*cos(2*PI/300000*time-111);
      // limits range of sensor values to between 0 and 255 
      redval = constrain(redval, 0, 255);
      greenval = constrain(greenval, 0, 255);
      blueval = constrain(blueval, 0, 255);
    }
    
    void rgbShowOn()
    {
      // define show On
      isShow=1;
      // Save state
      gw.saveState(0, 1); 
      // Write some debug info
      Serial.println("Show must go on");
    }
       
    void rgbShowOff()
    {
      // define show Off
      isShow=0;
      // Save state
      gw.saveState(0, 0);
      // Save RGB value to eeprom
      gw.saveState(RED_PIN, 100 * redval / 255); 
      gw.saveState(GREEN_PIN, 100 * greenval / 255);
      gw.saveState(BLUE_PIN, 100 * blueval / 255);
      // Write some debug info
      Serial.println("Stop the show");
      // Send actual RGB value and state to controler and request ack back (true/false)
      Serial.println("Send eeprom value to controler"); 
      gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );    
      gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
      gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
      gw.send( rgbShowState.set(0), false);
    }
    
    void rgbShowStop(int sensor)
    {
       // define show Off
       isShow=0;
       // Save state
       gw.saveState(0, 0);
       // Write some debug info
       Serial.println("Stop the show");
       // Send actual RGB value and state to controler and request ack back (true/false)
       Serial.println("Send eeprom value to controler"); 
       if (sensor != RED_PIN)
       {
            gw.saveState(RED_PIN, 100 * redval / 255); 
            gw.send( RedStatus.set(gw.loadState(RED_PIN)), false );  
        }
        if (sensor != GREEN_PIN)
        {
            gw.saveState(GREEN_PIN, 100 * greenval / 255); 
            gw.send( GreenStatus.set(gw.loadState(GREEN_PIN)), false );
        }
        if (sensor != BLUE_PIN)
        {
            gw.saveState(BLUE_PIN, 100 * blueval / 255);
            gw.send( BlueStatus.set(gw.loadState(BLUE_PIN)), false );
        }
        gw.send( rgbShowState.set(0), false);
    }
     
     /*
     void motion()   
     {     
      // Read digital motion value
      boolean tripped = digitalRead(Motion_PIN) == HIGH; 
            
      Serial.println(tripped);
      gw.send(MotionStatus.set(tripped?"1":"0"));  // Send tripped value to gw 
     
      // Sleep until interrupt comes in on motion sensor. Send update every two minute. 
      gw.sleep(INTERRUPT,CHANGE, SLEEP_TIME);
    }
    */
    

    Any Ideas of where I'm going wrong?



  • @DrJeff
    What does Vera show when you include this sensor? I am on mobile so it is hard to look through your code but it doesn't appear that you present the motion sensor as a separate child id. As it is presented last under mymessage, it may be overriding the light messages.


  • Admin

    Did you have some other sensor with the same id on the vera side (which you deleted)?
    Once in a while I've seen that Vera just hides deleted devices until rebooted.


 

288
Online

7.5k
Users

8.4k
Topics

90.4k
Posts