Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Dimmer LED with two state

Dimmer LED with two state

Scheduled Pinned Locked Moved My Project
2 Posts 1 Posters 1.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jacek
    wrote on last edited by jacek
    #1

    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 .

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jacek
      wrote on last edited by
      #2

      OK, i think it work's well now:

      } else if (persons == 0){
        if (message.getString() != 0) 
                {gw.send(dimmerMsg.set(0), true);}
         else
                {return;} ```
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      21

      Online

      11.7k

      Users

      11.2k

      Topics

      113.1k

      Posts


      Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • MySensors
      • OpenHardware.io
      • Categories
      • Recent
      • Tags
      • Popular