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. How To: Make a Simple/Cheap Scene Controller (with video)

How To: Make a Simple/Cheap Scene Controller (with video)

Scheduled Pinned Locked Moved My Project
62 Posts 19 Posters 40.1k Views 15 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.
  • hekH Offline
    hekH Offline
    hek
    Admin
    wrote on last edited by
    #46

    @Łukasz-Kostrzewa, paste code within 3 backtick characters, like this:

    ```
    Insert Code Here
    ```

    1 Reply Last reply
    0
    • Łukasz KostrzewaŁ Offline
      Łukasz KostrzewaŁ Offline
      Łukasz Kostrzewa
      wrote on last edited by
      #47

      You could do that but it is not a great solution.
      Add to Domoticz all 8 switches (4 when pressed and 4 when hold).
      In first switch (pressed switch) add Slave device (first hold switch). Do it for all 4 switches.
      To 5,6,7,8 switches add Slave Device (1,2,3,4 switch).
      It works like that:
      When You press First number on keyboard it change state to ON and 5 to OFF
      When You Hold first number on keybord it change state of 5 switch to ON and first to OFF.
      Next You have to make some events to trigger some scenes or lights
      I have hope I managed to explain what I mean :)
      Best regards

      1 Reply Last reply
      0
      • Łukasz KostrzewaŁ Offline
        Łukasz KostrzewaŁ Offline
        Łukasz Kostrzewa
        wrote on last edited by Łukasz Kostrzewa
        #48

        The 2.0 version code:

        #define MY_DEBUG
        #define MY_RADIO_NRF24
        
        #include <SPI.h>
        #include <MySensors.h>
        #include <Keypad.h>
        
        #define NODE_ID 14 // or set to AUTO if you want gw to assign a NODE_ID for you.
        #define SN "Scene Controller"
        #define SV "1.0"
        #define KEYPAD_CHILD_ID 95
        
        MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); 
        MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); 
        
        const byte ROWS = 4; //four rows
        const byte COLS = 1; //three columns
        char keys[ROWS][COLS] = {
          {'1'},
          {'2'},
          {'3'},
          {'4'}
        };
        
        byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
        byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
        
        Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
        byte lastState;
        
        
        void setup() {
          
          sendSketchInfo(SN, SV);
          present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
          keypad.addEventListener(keypadEvent);
        }
        
        void loop() {
          char key = keypad.getKey();
        }
        
        void keypadEvent(KeypadEvent key) {
          switch (keypad.getState()) {
        
            case PRESSED:
              lastState = 1;
              break;
        
            case HOLD:
              lastState = 2;
              break;
        
            case RELEASED:
              int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
              if (lastState == 2) {
                keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
              }
              send(scene.set(keyInt));
              break;
         }
        }       
        
        1 Reply Last reply
        0
        • dvr123D Offline
          dvr123D Offline
          dvr123
          wrote on last edited by
          #49

          That's actually much easier! But how do we manage to get it working more than one time? Because I can add the button but after that I can't control it. I can't see the button presses in the Domoticz log either.

          1 Reply Last reply
          0
          • Łukasz KostrzewaŁ Offline
            Łukasz KostrzewaŁ Offline
            Łukasz Kostrzewa
            wrote on last edited by Łukasz Kostrzewa
            #50

            @Łukasz-Kostrzewa said:

            send(scene.set(keyInt));

            Hi
            After
            send(scene.set(keyInt));
            Add
            send(scene2.set(keyInt));
            Write this code to arduino (now You can OFF all the switches) Next delete code You added and write it to Arduino once again but now in Domoticz make modifications I writed couple post higher. When You do that You will be able to control 4 scenes and another 4 will bo halpefull to OFF the first4 (when You hold the buttons)

            1 Reply Last reply
            0
            • rechin304R Offline
              rechin304R Offline
              rechin304
              wrote on last edited by
              #51

              Complete code version 2 with short press ON long press OFF.

              #define MY_DEBUG
              #define MY_RADIO_NRF24
              
              
              #include <SPI.h>
              #include <MySensors.h>
              #include <Keypad.h>
              
              #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you.
              #define SN "Scene Controller"
              #define SV "2.0"
              #define KEYPAD_CHILD_ID 95
              
              MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
              MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
              
              const byte ROWS = 4; //four rows
              const byte COLS = 1; //one column
              char keys[ROWS][COLS] = {
                {'1'},
                {'2'},
                {'3'},
                {'4'}
              };
              
              byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
              byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
              
              Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
              byte lastState;
              
              
              void setup() {
                
                sendSketchInfo(SN, SV);
                present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
                keypad.addEventListener(keypadEvent);
              }
              
              void loop() {
                char key = keypad.getKey();
              }
              
              void keypadEvent(KeypadEvent key) {
                switch (keypad.getState()) {
              
                  case PRESSED:
                    lastState = 1;
                    break;
              
                  case HOLD:
                    lastState = 2;
                    break;
              
                  case RELEASED:
                    int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
                    if (lastState == 2) {
                      //keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
                      send(scene2.set(keyInt));
                    } else {
                    send(scene.set(keyInt));
                    }
                    //break;
               }
              }```
              DrJeffD 1 Reply Last reply
              0
              • Łukasz KostrzewaŁ Offline
                Łukasz KostrzewaŁ Offline
                Łukasz Kostrzewa
                wrote on last edited by
                #52

                Hi rechin304
                Thank You for Your code...It's working great!!!
                Best regards

                rechin304R 1 Reply Last reply
                0
                • Łukasz KostrzewaŁ Łukasz Kostrzewa

                  Hi rechin304
                  Thank You for Your code...It's working great!!!
                  Best regards

                  rechin304R Offline
                  rechin304R Offline
                  rechin304
                  wrote on last edited by
                  #53

                  @Łukasz-Kostrzewa you are welcome, all thanks goes to @petewill for initial code.

                  1 Reply Last reply
                  0
                  • Matt PittsM Offline
                    Matt PittsM Offline
                    Matt Pitts
                    wrote on last edited by
                    #54

                    Hi Guys,

                    I'm so glad that have updated the sketch which i have now been able to compile and get running :-)

                    But this is the message I get in the serial monitor and I only get these messages when I press button 3?? I am using a single row of four buttons as in the original sketch.

                    Am I missing something here? I was assuming the message with either be a 1 for a short press and 0 for a long press? I would be really grateful if someone who knows more about this than me is able to help me figure out what's going on?

                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                    
                    
                    rechin304R 1 Reply Last reply
                    0
                    • Matt PittsM Matt Pitts

                      Hi Guys,

                      I'm so glad that have updated the sketch which i have now been able to compile and get running :-)

                      But this is the message I get in the serial monitor and I only get these messages when I press button 3?? I am using a single row of four buttons as in the original sketch.

                      Am I missing something here? I was assuming the message with either be a 1 for a short press and 0 for a long press? I would be really grateful if someone who knows more about this than me is able to help me figure out what's going on?

                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:7
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      TSP:MSG:SEND 11-11-0-0 s=95,c=1,t=19,pt=2,l=2,sg=0,ft=0,st=ok:3
                      
                      
                      rechin304R Offline
                      rechin304R Offline
                      rechin304
                      wrote on last edited by
                      #55

                      @Matt-Pitts on 3 is short press and in code is scene on and on long press is 7 scene off

                      MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                      MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                      
                      
                              send(scene2.set(keyInt));
                            } else {
                            send(scene.set(keyInt));```
                      1 Reply Last reply
                      0
                      • Matt PittsM Offline
                        Matt PittsM Offline
                        Matt Pitts
                        wrote on last edited by
                        #56

                        @rechin304 said:

                        @Matt-Pitts on 3 is short press and in code is scene on and on long press is 7 scene off

                        MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                        MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                        
                        
                                send(scene2.set(keyInt));
                              } else {
                              send(scene.set(keyInt));```
                        

                        Hi Not sure if that helps me, I'm struggling to understand how this actually works? as I said the only button doing anything is 3, do I need to modify the sketch to get the other buttons working?

                        rechin304R 1 Reply Last reply
                        0
                        • Matt PittsM Matt Pitts

                          @rechin304 said:

                          @Matt-Pitts on 3 is short press and in code is scene on and on long press is 7 scene off

                          MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                          MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                          
                          
                                  send(scene2.set(keyInt));
                                } else {
                                send(scene.set(keyInt));```
                          

                          Hi Not sure if that helps me, I'm struggling to understand how this actually works? as I said the only button doing anything is 3, do I need to modify the sketch to get the other buttons working?

                          rechin304R Offline
                          rechin304R Offline
                          rechin304
                          wrote on last edited by
                          #57

                          @Matt-Pitts then you need to check your conenction to all wires and if are correctly. Check first post as there is a picture.

                          1 Reply Last reply
                          0
                          • rechin304R rechin304

                            Complete code version 2 with short press ON long press OFF.

                            #define MY_DEBUG
                            #define MY_RADIO_NRF24
                            
                            
                            #include <SPI.h>
                            #include <MySensors.h>
                            #include <Keypad.h>
                            
                            #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you.
                            #define SN "Scene Controller"
                            #define SV "2.0"
                            #define KEYPAD_CHILD_ID 95
                            
                            MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                            MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                            
                            const byte ROWS = 4; //four rows
                            const byte COLS = 1; //one column
                            char keys[ROWS][COLS] = {
                              {'1'},
                              {'2'},
                              {'3'},
                              {'4'}
                            };
                            
                            byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
                            byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
                            
                            Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
                            byte lastState;
                            
                            
                            void setup() {
                              
                              sendSketchInfo(SN, SV);
                              present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
                              keypad.addEventListener(keypadEvent);
                            }
                            
                            void loop() {
                              char key = keypad.getKey();
                            }
                            
                            void keypadEvent(KeypadEvent key) {
                              switch (keypad.getState()) {
                            
                                case PRESSED:
                                  lastState = 1;
                                  break;
                            
                                case HOLD:
                                  lastState = 2;
                                  break;
                            
                                case RELEASED:
                                  int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
                                  if (lastState == 2) {
                                    //keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
                                    send(scene2.set(keyInt));
                                  } else {
                                  send(scene.set(keyInt));
                                  }
                                  //break;
                             }
                            }```
                            DrJeffD Offline
                            DrJeffD Offline
                            DrJeff
                            wrote on last edited by
                            #58

                            @rechin304

                            Not getting the Hold on buttons working, everything else works. Any ideas why the long press doesn't work?

                            1 Reply Last reply
                            0
                            • DrJeffD Offline
                              DrJeffD Offline
                              DrJeff
                              wrote on last edited by
                              #59

                              Never mind part of the code was commented out. I wasn't sure because I just started to use OTA. But it's all good now its working fine. Here it is:

                              #define MY_DEBUG
                              #define MY_RADIO_NRF24
                              #define MY_OTA_FIRMWARE_FEATURE
                              
                              #include <SPI.h>
                              #include <MySensors.h>
                              #include <Keypad.h>
                              
                              #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you.
                              #define SN "Scene Controller"
                              #define SV "2.0"
                              #define KEYPAD_CHILD_ID 95
                              
                              MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                              MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                              
                              const byte ROWS = 4; //four rows
                              const byte COLS = 1; //one column
                              char keys[ROWS][COLS] = {
                                {'1'},
                                {'2'},
                                {'3'},
                                {'4'}
                              };
                              
                              byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
                              byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
                              
                              Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
                              byte lastState;
                              
                              
                              void setup() {
                                
                                sendSketchInfo(SN, SV);
                                present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
                                keypad.addEventListener(keypadEvent);
                              }
                              
                              void loop() {
                                char key = keypad.getKey();
                              }
                              
                              void keypadEvent(KeypadEvent key) {
                                switch (keypad.getState()) {
                              
                                  case PRESSED:
                                    lastState = 1;
                                    break;
                              
                                  case HOLD:
                                    lastState = 2;
                                    break;
                              
                                  case RELEASED:
                                    int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
                                    if (lastState == 2) {
                                      keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
                                      send(scene2.set(keyInt));
                                    } else {
                                    send(scene.set(keyInt));
                                    }
                                    break;
                               }
                              }
                              
                              rechin304R 1 Reply Last reply
                              0
                              • DrJeffD DrJeff

                                Never mind part of the code was commented out. I wasn't sure because I just started to use OTA. But it's all good now its working fine. Here it is:

                                #define MY_DEBUG
                                #define MY_RADIO_NRF24
                                #define MY_OTA_FIRMWARE_FEATURE
                                
                                #include <SPI.h>
                                #include <MySensors.h>
                                #include <Keypad.h>
                                
                                #define NODE_ID AUTO // or set to AUTO if you want gw to assign a NODE_ID for you.
                                #define SN "Scene Controller"
                                #define SV "2.0"
                                #define KEYPAD_CHILD_ID 95
                                
                                MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                                MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                                
                                const byte ROWS = 4; //four rows
                                const byte COLS = 1; //one column
                                char keys[ROWS][COLS] = {
                                  {'1'},
                                  {'2'},
                                  {'3'},
                                  {'4'}
                                };
                                
                                byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
                                byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
                                
                                Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
                                byte lastState;
                                
                                
                                void setup() {
                                  
                                  sendSketchInfo(SN, SV);
                                  present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
                                  keypad.addEventListener(keypadEvent);
                                }
                                
                                void loop() {
                                  char key = keypad.getKey();
                                }
                                
                                void keypadEvent(KeypadEvent key) {
                                  switch (keypad.getState()) {
                                
                                    case PRESSED:
                                      lastState = 1;
                                      break;
                                
                                    case HOLD:
                                      lastState = 2;
                                      break;
                                
                                    case RELEASED:
                                      int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
                                      if (lastState == 2) {
                                        keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
                                        send(scene2.set(keyInt));
                                      } else {
                                      send(scene.set(keyInt));
                                      }
                                      break;
                                 }
                                }
                                
                                rechin304R Offline
                                rechin304R Offline
                                rechin304
                                wrote on last edited by
                                #60

                                @DrJeff ok, glad to hear you solved.

                                1 Reply Last reply
                                0
                                • ZwaZoZ Offline
                                  ZwaZoZ Offline
                                  ZwaZo
                                  wrote on last edited by
                                  #61

                                  Hello,

                                  Here an update of the original sketch with a small modif to add a buzzer for validating the keypress.

                                  It will beep once for short key press and twice for the long one.

                                  The buzzer is connected on D3 and the beep length can be adjusted in the function.

                                  Your feedback and improvement ideas are welcome.

                                  Best regards,

                                  Jef

                                  #define MY_DEBUG
                                  #define MY_RADIO_NRF24
                                  
                                  // Set LOW transmit power level as default, if you have an amplified NRF-module and
                                  // power your radio separately with a good regulator you can turn up PA level.
                                  /* - RF24_PA_MIN = -18dBm
                                   * - RF24_PA_LOW = -12dBm
                                   * - RF24_PA_HIGH = -6dBm
                                   * - RF24_PA_MAX = 0dBm
                                   */
                                  #define MY_RF24_PA_LEVEL RF24_PA_HIGH
                                  
                                  // Enabled repeater feature for this node
                                  #define MY_REPEATER_FEATURE
                                  
                                  // activate signal report
                                  // #define MY_SIGNAL_REPORT_ENABLED
                                  
                                  #include <SPI.h>
                                  #include <MySensors.h>
                                  #include <Keypad.h>
                                  
                                  #define NODE_ID AUTO // or set to AUTO if you want gw to assign a node id for you.
                                  #define SN "Keypad Scene Controller"
                                  #define SV "2.1"
                                  #define KEYPAD_CHILD_ID 95
                                  
                                  MyMessage scene(KEYPAD_CHILD_ID, V_SCENE_ON); //scene ON
                                  MyMessage scene2(KEYPAD_CHILD_ID, V_SCENE_OFF); //scene OFF
                                  
                                  int buzzer = 3; // buzzer pin
                                  
                                  
                                  const byte ROWS = 4; //four rows
                                  const byte COLS = 1; //one column
                                  char keys[ROWS][COLS] = {
                                    {'1'},
                                    {'2'},
                                    {'3'},
                                    {'4'}
                                  };
                                  byte rowPins[ROWS] = {6, 7, 4, 5}; //connect to the row pinouts of the keypad
                                  byte colPins[COLS] = {8}; //connect to the column pinouts of the keypad
                                  
                                  Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
                                  byte lastState;
                                  
                                  
                                  void setup() {
                                    
                                    sendSketchInfo(SN, SV);
                                    present(KEYPAD_CHILD_ID, S_SCENE_CONTROLLER);
                                    keypad.addEventListener(keypadEvent);
                                    pinMode(buzzer, OUTPUT);
                                  }
                                  /*
                                   * Declare the buzzer function.
                                   * Adjust the delay to fit your preferences
                                   */
                                  void beep()
                                  {
                                    digitalWrite(buzzer, HIGH);
                                    delay(50);
                                    digitalWrite(buzzer, LOW);
                                  }
                                  
                                  void loop() {
                                    char key = keypad.getKey();
                                  }
                                  
                                  void keypadEvent(KeypadEvent key) {
                                    switch (keypad.getState()) {
                                  
                                      case PRESSED:
                                        lastState = 1;
                                        beep();
                                        break;
                                  
                                      case HOLD:
                                        lastState = 2;
                                        beep();
                                        break;
                                  
                                      case RELEASED:
                                        int keyInt = key - '0'; //Quick way to convert Char to Int so it can be sent to controller
                                        if (lastState == 2) {
                                          //keyInt = keyInt + 4; //If button is held, add 4.  If using more than 4 buttons this number will need to be changed
                                          send(scene2.set(keyInt));
                                        } else {
                                        send(scene.set(keyInt));
                                        }
                                        //break;
                                   }
                                  }
                                  
                                  1 Reply Last reply
                                  2
                                  • S Offline
                                    S Offline
                                    Sanderunizuki
                                    wrote on last edited by
                                    #62

                                    I want to use this mysensors touch sensor to adjust a selector switch in domoticz, so if I select scene 1 the selector switch in Domoticz goes to 10%, and scene 2 to 20% and so on. Is that possible and how do I do that?

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    9

                                    Online

                                    11.7k

                                    Users

                                    11.2k

                                    Topics

                                    113.0k

                                    Posts


                                    Copyright 2019 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