MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    [MMM-Buttons] Connect multiple buttons to send configurable notifications

    Scheduled Pinned Locked Moved System
    40 Posts 15 Posters 36.9k Views 14 Watching
    Loading More Posts
    • 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
      Jopyth Moderator
      last edited by Jopyth

      Description:

      This is a module for Magic Mirror² to act based on button presses via GPIO.
      It is basically a generalized version of the Button module, original idea comes from @PtrBld.
      It is capable of connecting multiple buttons at once, which can be individually configured.
      However it only sends out notifications to other modules.

      For example this can be used to send notifications to the following modules:

      • Remote Control
      • Profile Switcher

      Download:

      [card:Jopyth/MMM-Buttons]

      FAQ

      Error on npm install: An unhandled error occurred inside electron-rebuild. Unable to find electron-prebuilt’s version number, either install it or specify an explicit version

      Possible Solution: Upgrade your MagicMirror 2.1.0 or higher.

      Changelog

      [1.0.0] - 2017-01-28

      Initial release of the Buttons module.

      Helpful sticky: How to troubleshoot

      1 Reply Last reply Reply Quote 3
      • B Offline
        Burner911
        last edited by

        This sounds awesome! Do you think there is a relatively easy way to output from the GPIO instead? I would like to turn my TV off using a transistor being it does not support HDMI-CEC like a monitor does. I’m thinking this might be best discussed with regards to MMM-Remote-Control.

        1 Reply Last reply Reply Quote 0
        • tosti007T Offline
          tosti007 Module Developer
          last edited by

          Nice! I think many people will be able to use this for their mirror

          If there is anything don't hesitate to contact me!
          ProfileSwitcher, TouchNotifications

          1 Reply Last reply Reply Quote 0
          • istepgueuI Offline
            istepgueu
            last edited by istepgueu

            Hi @Jopyth !

            Thanks for your module.

            I would like to use an on / off button instead of a push button
            for my garage door project (https://forum.magicmirror.builders/topic/1620/garage-door-detectors)

            Is there a way to send a notification on “button_up” and an other notification on “Button_down” ?

            Thank you very much ;-)

            1 Reply Last reply Reply Quote 0
            • istepgueuI Offline
              istepgueu
              last edited by

              Does anyone know how to read the initial value of a button (GPIO) before it is run ?

              Thanks.

              1 Reply Last reply Reply Quote 0
              • M Offline
                Mar
                last edited by

                @Jopyth Moved my post here out from another thread.

                I am having one more issue though. Using a python test program i can see every single instance of my button press is registered instantly. But in the mirror it seems MMM-Buttons doesnt register pushes unless sometimes I double or triple click…then sometimes the button registers 5-6 times. I’m not really sure how to debug this sort of thing.

                Also would it be right to assume the pull up/down resistors were not enabled with MMM-Buttons?

                istepgueuI 2 Replies Last reply Reply Quote 0
                • istepgueuI Offline
                  istepgueu @Mar
                  last edited by

                  @Mar all is here https://forum.magicmirror.builders/topic/211/button

                  ;-)

                  M 1 Reply Last reply Reply Quote 0
                  • istepgueuI Offline
                    istepgueu @Mar
                    last edited by

                    @Mar i have same problem. I run my little script button.py before start MM and its solve the problem

                    M 1 Reply Last reply Reply Quote 0
                    • M Offline
                      Mar @istepgueu
                      last edited by Mar

                      @istepgueu Ive taken your button.py program and modified it for me two buttons 5/6. And while the program reads my button presses perfectly, MM-Buttons doesnt at all. I pretty much have to double click each time to make a button register. It switches my profiles just fine … but just takes lots of clicks to register.

                      import RPi.GPIO as GPIO
                      import time
                      
                      GPIO.setmode(GPIO.BCM)
                      GPIO.setup(5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                      GPIO.setup(6, GPIO.IN, pull_up_down=GPIO.PUD_UP)
                      
                      tries = 0
                      
                      while (tries < 200000):
                          if GPIO.input(6):
                              print("Open 6")
                          else:
                              print("Close 6")
                          if GPIO.input(5):
                              print("Open 5")
                          else:
                              print ("Close 5")
                          time.sleep(0.5)
                          tries = tries + 1
                      
                      1 Reply Last reply Reply Quote 0
                      • M Offline
                        Mar @istepgueu
                        last edited by Mar

                        @istepgueu Will take a look through this now, but i already have a 1k resistor between pins 5/6 and the respective button. Hopefully something else comes up here.

                        Yes my problem seems a bit opposite of what was posted in your link. I dont have any erroneous button presses, it just takes a few clicks until MMM-Buttons registers the click. You button.py registers every click instantly. So must be something in the buttons code?

                        1 Reply Last reply Reply Quote 0
                        • J Offline
                          Jopyth Moderator
                          last edited by Jopyth

                          @Mar @istepgueu The library (onoff) I am currently using does not directly allow configuring pull up and pull down resistors, and I was not able to make it consistently work (see Readme).

                          Therefore I myself made use of the “right” pins for my setup, as the readme says:

                          The defaults can be seen in Table 6-31 on pages 102 and 103 of the BCM2835 ARM Peripherals documentation.

                          There I simply used buttons with the correct default pull-up/pull-down resistor configuration (second column of that table), and I wanted a few pins close together on the board, so I chose GPIO 22,23,24 and 25 (connected 4 buttons), since they all have the default of a low input.

                          Helpful sticky: How to troubleshoot

                          M 1 Reply Last reply Reply Quote 0
                          • M Offline
                            Mar @Jopyth
                            last edited by

                            @Jopyth Thanks for the response, and that seems to make complete sense. I missed that part in the documentation.

                            Though upon trying PINS 22/23 i am still getting the same result. The button.py program detects each individual click properly, but in the MM I have to double (sometimes triple) click the button so that it registers. I can see it registers as it shows up in the pm2 logs and my profile changes.

                            Im not sure if its an issue with the buttons as they are a standard 4 pin button and the test script works fine with them?

                            J 1 Reply Last reply Reply Quote 1
                            • J Offline
                              Jopyth Moderator @Mar
                              last edited by Jopyth

                              @Mar Well its not, as if it were documented anywhere in my readme. :( Should probably add this somewhere.

                              How long are you pressing the button? For a very short time? Note, that if the press is longer than 500ms it will not be registered as a (short) press (it is the maxShortPressTime and can be configured).

                              If this is not the case, I am sorry, but I have no real idea how to fix it, without having the same situation on my Pi.

                              Helpful sticky: How to troubleshoot

                              M 3 Replies Last reply Reply Quote 1
                              • M Offline
                                Mar @Jopyth
                                last edited by

                                @Jopyth I thought this also, and set the short time from 0-1000ms and still will only register the second of a double click.

                                Its very consistent though, i can get it to work 100% of the time with a double click like opening a folder on the computer. one click doesnt do anything, and I don’t believe the longPress worked at all (But i wasnt using it so not that bothered with it).

                                Maybe its just the buttons…i just dont have anything else around that i could use to test as a button.

                                1 Reply Last reply Reply Quote 0
                                • M Offline
                                  Mar @Jopyth
                                  last edited by

                                  @Jopyth Just tested with buttons ripped out from an old monitor and same issue, needed to double click. I suppose i will slowly go through the code and try break it down and see. any advice on which functions to start with?

                                  1 Reply Last reply Reply Quote 0
                                  • M Offline
                                    Mar @Jopyth
                                    last edited by Mar

                                    @Jopyth Fixed!! I switched the 1 and the 0 in the watchHandler function of node_helper.js and solved the issue. Must have been backwards with how the button was being interpreted vs set up?

                                    Put the 0 first, then 1.

                                    Now the double click makes sense, the time between the clicks seems to have been what was counted as a valid min press time.

                                    1 Reply Last reply Reply Quote 1
                                    • M Offline
                                      Mar
                                      last edited by

                                      @Jopyth Anyway to use one button to switch between profiles? Trying to use profile switches classes and creating the same button on different profiles (classes) but it always runs both buttons so take me back to the default page.

                                      J 1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        Jopyth Moderator @Mar
                                        last edited by Jopyth

                                        @Mar Glad you got it work. :) Did you switch back to the default (regarding the 0 and 1)? Or is it now different than in the main code? Not yet possible to switch between multiple profiles. Could maybe be implemented as an array of notification definitions, instead of a single notification definition and then it cycles through these notifications on each press?

                                        Helpful sticky: How to troubleshoot

                                        M 1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          Mar @Jopyth
                                          last edited by Mar

                                          @Jopyth No i had to switch the 1 and the 0 to make it work (0 first, then 1) so my code does differ slightly unfortunately. Suppose I’ll have to remember to manually make the change on updates unless it can be made a config option.
                                          That could be a good option. We’d need a way for profile switcher to send over all unique profiles which would make it easy to do, rather than scrape the config file for “classes”.

                                          edit: Though I suppose thinking about this not relying on another module would be much quicker fix.

                                          1 Reply Last reply Reply Quote 0
                                          • ? Offline
                                            A Former User
                                            last edited by yawns

                                            What if I want to send an alert show display message when the GPIO port is ON? I mean, is not like a switch that closes the GPIO port, is when you programatically send an outoput GPIO signal to close (lets say a relay). Is there any changes necessary? I can´t make it happen.

                                            {
                                                     module: 'MMM-Buttons',
                                                    config: {
                                                    buttons: [
                                                            {
                                                             pin: 17,
                                                            name: "rele",
                                                            longPress: {
                                                                            title: "Rele longpress",
                                                                            message: 'El rele esta siendo pulsado largo',
                                                                            imageFA: 'power-off',
                                                                            notification: 'SHOW_ALERT',
                                                                            payload: {
                                                                                    type: 'notification',
                                                                                    title: 'Alerta rele pulsado largo'
                                                                            }
                                                                    },
                                                                    shortPress:  {
                                                                            title: "Rele shortress",
                                                                            message: 'El rele esta siendo pulsado corto',
                                                                           imageFA: 'power-on',
                                                                            notification: 'SHOW_ALERT',
                                                                     payload: {
                                                                                  type: 'notification',
                                                                                    title: 'Alerta rele pulsado largo'
                                                                         }
                                            
                                                                    }
                                            
                                            
                                                            }
                                                    ]
                                                            } //del config
                                            
                                             },
                                            
                                            1 Reply Last reply Reply Quote 0

                                            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                            With your input, this post could be even better 💗

                                            Register Login
                                            • 1
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post
                                            Enjoying MagicMirror? Please consider a donation!
                                            MagicMirror created by Michael Teeuw.
                                            Forum managed by Sam, technical setup by Karsten.
                                            This forum is using NodeBB as its core | Contributors
                                            Contact | Privacy Policy