Dimmer LED with two state



  • I did something like that based on DimmableWithRotaryEncoderButton, I changed only this part :

    void incomingMessage(const MyMessage &message)
    {
      if (digitalRead(8) == 0) { persons = 0;} else {persons = 1;}
      if (message.type == V_LIGHT && persons == 1) {
        // Incoming on/off command sent from controller ("1" or "0")
        int lightState = message.getString()[0] == '1';
        int newLevel = 0;
        if (lightState==LIGHT_ON) {
          // Pick up last saved dimmer level from the eeprom
          newLevel = loadLevelState(EEPROM_DIM_LEVEL_SAVE);
        } 
        // Send dimmer level back to controller with ack enabled
        gw.send(dimmerMsg.set(newLevel), true);
        // We do not change any levels here until ack comes back from gateway 
        return;
      } else if (message.type == V_DIMMER && persons == 1) {
        // Incoming dim-level command sent from controller (or ack message)
        fadeTo = atoi(message.getString(convBuffer));
        // Save received dim value to eeprom (unless turned off). Will be
        // retreived when a on command comes in
        if (fadeTo != 0)
          saveLevelState(EEPROM_DIM_LEVEL_SAVE, fadeTo);
      }
     if (persons == 1){
           saveLevelState(EEPROM_DIM_LEVEL_LAST, fadeTo);
           Serial.print("New light level received: ");
           Serial.println(fadeTo);
         if (!changedByKnob) 
           knob.write(fadeTo); 
           // Cancel send if user turns knob while message comes in
           changedByKnob = false;
           sendDimValue = false;
           // Stard fading to new light level
           startFade();
    } else if (persons == 0){
     
      gw.send(dimmerMsg.set(0), true);   
     return;
      }
    }
    

    What I wanted to get?
    I wanted to achieve the effect such that when the variable persons = 1 ściamniacz operate normally, but the variable persons = 0 despite the switch is turned on in domoticzu it is to be shut down after a while or at all does not turn on . Now, this code works like that sometimes acts like he wants and sometimes not 😞
    Sometimes works well like now:

    read: 0-2-4 s=1,c=1,t=3,pt=0,l=2,sg=0:27
    send: 4-4-2-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
    read: 0-2-4 s=1,c=1,t=3,pt=2,l=2,sg=0:0
    send: 4-4-2-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
    

    but sometimes dont work well:

    read: 0-2-4 s=1,c=1,t=3,pt=2,l=2,sg=0:0
    send: 4-4-2-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
    read: 0-2-4 s=1,c=1,t=3,pt=0,l=2,sg=0:33
    send: 4-4-2-0 s=1,c=1,t=3,pt=2,l=2,sg=0,st=ok:0
    

    and I donot know why 😞
    the point is that in the read is different than 0 in domoticzu button does not become inactive .



  • OK, i think it work's well now:

    } else if (persons == 0){
      if (message.getString() != 0) 
              {gw.send(dimmerMsg.set(0), true);}
       else
              {return;} ```

Log in to reply
 

Suggested Topics

  • 8
  • 2
  • 1
  • 2
  • 1
  • 90

1
Online

11.2k
Users

11.1k
Topics

112.5k
Posts