ASL board for stair lightning meets fhem by using my sensor



  • Hello guys,

    I am a totally newbie about my senor. It would be nice if I could get a little support/help with my problems.

    I am trying to use this ASL board: link

    It would be great if I can get some infos how the code on the nano sketch and fhem should look like, that I can can trigger/change functions from fhem to the nano/sketch and how can I get an info, when a pir changes a value of a varible in the sketch. Here is the existing code from the ardunio sktech:

    #define MY_RADIO_NRF24
    #define MY_REPEATER_FEATURE
    #include <SPI.h>
    #include <MySensors.h>
    boolean sensor;
    boolean MysenSor;
    
    
    #define SHIFTPWM_NOSPI                            
    const int ShiftPWM_dataPin = 6;                   //  Do not change!!!
    const int ShiftPWM_clockPin = 7;                  //  Do not change!!!
    const int ShiftPWM_latchPin = 8;                  //  Do not change!!!
    #include <ShiftPWM.h>
    const bool ShiftPWM_invertOutputs = false;         
    const bool ShiftPWM_balanceLoad = false;         
    #define sensorLight_PIN A0                        // Light sensor  Do not change!!!
    #define sensorBottom_PIN A1                       // Bottom sensor Do not change!!!                     
    #define sensorUpper_PIN A2                        // Upper sensor  Do not change!!!
    unsigned char maxBrightness = 100;                // Here you set the number of brightness levels. Adjust(0-255)!!
    unsigned char pwmFrequency = 75;                  // These values affect the load of ShiftPWM 
    unsigned int numRegisters = 3;                    // Number of shift registers Do not change!!!
    unsigned int numOutputs = numRegisters * 8;
    unsigned int numRGBLeds = numRegisters * 8 / 3;
    boolean sensorUpperActive;
    boolean sensorBottomActive;
    int numberOfstairs=6;                           // Setup Number of Your stairs. Adjust up to 24 !!!!
    int pause=30000;                                    // Setup delay ON/OFF  Adjust!!! 
    byte faidoutSpeed=5;                              // How fast to fadeout     Adjust!!!
    byte faidinSpeed=5;                               // How fast to fadein      Adjust!!!
    
    
    void before() {
        MysenSor=loadState(sensor);                   // Set relay to last known state (using eeprom storage) 
     }
      
    void presentation() { 
         present(sensor, S_LIGHT);
     }
    
    void receive(const MyMessage &message) {          // We only expect one type of message from controller. But we better check anyway.
                                                         
      if (message.type==V_LIGHT) {
        MysenSor=message.getBool();
         // Store state in eeprom
         saveState(message.sensor, message.getBool());
      }
    }
    void setup() {
    
    
      
      ShiftPWM.SetAmountOfRegisters(numRegisters);
      ShiftPWM.Start(pwmFrequency, maxBrightness);
      pinMode(sensorBottom_PIN, INPUT);
      pinMode(sensorUpper_PIN, INPUT);
      pinMode(sensorLight_PIN, INPUT);
    
        Serial.begin(9600);
      Serial.println("setup");
      
    }
    
    
    void loop() {
    
                                   
      if  ( MysenSor!=0) {                             
                                                       
        BottomTriggerFire();                           //Checking bottom sensor
        UpperTrigerFire();                             //Checking upper sensor
        switchONOFFfromdown();                         //Stairs on/off from down to up
        switchONOFFfromUp();                           //Stairs on/off from up to down
      }
    }
    
    void BottomTriggerFire() {
    
      if (analogRead (sensorBottom_PIN) >= 550 ) {      //Depend of the sensor type, if 0 when triggered ,than change the comparison to opposite value.
        sensorBottomActive = true;
      }
    }
    
    void UpperTrigerFire() {
    
      if (analogRead(sensorUpper_PIN) >= 550) {          //Depend of the sensor type, if 0 when triggered ,than change the comparison to opposite value.
        sensorUpperActive = true;
      }
    }
    
    
    void switchONOFFfromdown() {
      if (sensorBottomActive==true && sensorUpperActive==false){
        
     
            for(int i=0; i<numberOfstairs; i++){
              for(int a=0; a<maxBrightness; a++){
              ShiftPWM.SetOne(i,a);
              delay(faidoutSpeed);
               }
              }
              
            delay(pause); 
    
            for(int i=0; i<numberOfstairs; i++){
              for(int a=maxBrightness;a>=0;a--){
              ShiftPWM.SetOne(i,a);
              if(a==0){
              ShiftPWM.SetOne(i,0);  
              }
              delay(faidinSpeed);
               }
              }
            sensorBottomActive = false ;  
      }
    }
             
     void switchONOFFfromUp () {
        if ( sensorUpperActive==true && sensorBottomActive==false) {
    
    
            for(int i=numberOfstairs; i>=0; i--){
              Serial.print(i);
              for(int a=0; a<maxBrightness; a++){
              ShiftPWM.SetOne(i,a);
              delay(faidoutSpeed);
               }
              }
              
            delay(pause); 
    
              
            for(int i=numberOfstairs; i>=0; i--){
              //Serial.print(i);
              for(int a=maxBrightness;a>=0;a--){
              ShiftPWM.SetOne(i,a);
              if(a==0){
              ShiftPWM.SetOne(i,0);  
              }
              delay(faidinSpeed);
               }
              }
            sensorUpperActive= false ;  
      }
    }
    

    Here are my FHEM listings:

    defmod MySensor MYSENSORS 192.168.0.68:5003
    attr MySensor autocreate 1
    attr MySensor group Sensorik
    attr MySensor icon cul
    attr MySensor room Actions,MySensor,System
    attr MySensor stateFormat connection
    attr MySensor verbose 4
    
    setstate MySensor startup complete
    setstate MySensor 2019-08-17 20:25:49 connection startup complete
    setstate MySensor 2019-08-17 20:30:50 heartbeat alive
    setstate MySensor 2019-08-17 20:25:49 state opened
    

    Next:

    defmod MYSENSOR_0 MYSENSORS_DEVICE 0
    attr MYSENSOR_0 IODev MySensor
    attr MYSENSOR_0 mode repeater
    attr MYSENSOR_0 requestAck 1
    attr MYSENSOR_0 room MySensor
    attr MYSENSOR_0 version 2.2.0-beta
    
    setstate MYSENSOR_0 2019-08-17 20:30:50 heartbeat alive
    

    and last:

    defmod MYSENSOR_1 MYSENSORS_DEVICE 1
    attr MYSENSOR_1 IODev MySensor
    attr MYSENSOR_1 mapReading_power 0 power
    attr MYSENSOR_1 mapReading_status 0 status
    attr MYSENSOR_1 mode repeater
    attr MYSENSOR_1 requestAck 1
    attr MYSENSOR_1 room MySensor
    attr MYSENSOR_1 setReading_.+ luxwert
    attr MYSENSOR_1 setReading_power 1
    attr MYSENSOR_1 setReading_status off,on
    attr MYSENSOR_1 version 2.1.1
    
    setstate MYSENSOR_1 routingtable cleared
    setstate MYSENSOR_1 2017-06-18 11:22:01 parentId 0
    setstate MYSENSOR_1 2017-06-17 19:09:48 power 1
    setstate MYSENSOR_1 2017-06-17 19:11:22 state routingtable cleared
    setstate MYSENSOR_1 2017-06-18 11:59:13 status on
    

    It would be great if I can some help/support 🙂

    Greetings
    Thomas


 

261
Online

8.7k
Users

9.5k
Topics

99.9k
Posts