1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Disable lights with pushbutton?

Discussion in 'Hyperion General' started by Arakon, 25 March 2019.

  1. Arakon

    Arakon Member

    Messages:
    139
    Hardware:
    RPi1/Zero, RPi3, +Arduino
    Hi.

    I'm wondering if there's a way to disable the LED strip using a simple pushbutton connected to the GPIO?
    I'm waiting for the LED strip currently, going to set up a HDMI-input ambilight with the standard raspberry-grabber-hdmi splitter-hdmi converter combination.
    I saw there are plugins for Kodi etc for this, but no standalone options.
     
  2. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    1,259
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino, +nodeMCU/ESP8266
    you could start a script to start and kill hyperion..so why not
     
  3. Arakon

    Arakon Member

    Messages:
    139
    Hardware:
    RPi1/Zero, RPi3, +Arduino
    I'm very new to the raspberry and not a coder at all (much better at messing with the hardware than the software).. Do you have an example? I tried digging around some already, but all the tutorials seem to require decent coding knowledge and only give parts of the needed info, not a "from scratch" approach.
     
  4. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    1,259
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino, +nodeMCU/ESP8266
    things to search for: find out how to trigger a script with pushing a button on the gpio pins and then trigger 2 scripts... for example set all leds to black with hyperion-remote -c black and the second would be clear the message with hyperion-remote --clearall
     
  5. bnealon

    bnealon New Member

    Messages:
    13
    Hardware:
    +PhilipsHue
    if you're a smart phone user, your could create and save 2 ssh commands:
    Code:
    sudo systemctl start hyperion.service
    and
    Code:
    sudo systemctl stop hyperion.service
    Im on iOS and use the native 'shortcuts' app to do just this, i then have these SSH scripts set as two widgets on my smartphone that are quick to access.
     
  6. Arakon

    Arakon Member

    Messages:
    139
    Hardware:
    RPi1/Zero, RPi3, +Arduino
    Thanks, but I'd like to have the functionality without having to have my phone nearby.
     
  7. bnealon

    bnealon New Member

    Messages:
    13
    Hardware:
    +PhilipsHue
    You could still use SSH scripts, but wire it upto a physical button using something like nodered, or some other home automation software.
     
  8. Arakon

    Arakon Member

    Messages:
    139
    Hardware:
    RPi1/Zero, RPi3, +Arduino
    Ok, I managed to hack together a solution.
    Code:
    #!/usr/bin/env python
    
    
    import RPi.GPIO as GPIO
    import subprocess
    import time
    
    
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    state = 0
    while True:
        GPIO.wait_for_edge(3, GPIO.FALLING)
        if (state == 0):
            subprocess.call(['hyperion-remote', '-c', 'black'], shell=False)
            state = 1
            time.sleep(0.2)
        elif (state == 1):
            subprocess.call(['hyperion-remote', '--clearall'], shell=False)
            state = 0
            time.sleep(0.2)
    
    GPIO.cleanup()
    
    This goes in /usr/local/bin/ as hyper-switch.py.
    sudo chmod +x /usr/local/bin/hyper-switch.py

    Code:
    #! /bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          hyper-switch.py
    # Required-Start:    $remote_fs $syslog
    # Required-Stop:     $remote_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    ### END INIT INFO
    
    # If you want a command to always run, put it here
    
    # Carry out specific functions when asked to by the system
    case "$1" in
      start)
        echo "Starting hyper-switch.py - Use pin 5 and GND"
        /usr/local/bin/hyper-switch.py &
        ;;
      stop)
        echo "Stopping hyper-switch.py"
        pkill -f /usr/local/bin/hyper-switch.py
        ;;
      *)
        echo "Usage: /etc/init.d/hyper-switch.sh {start|stop}"
        exit 1
        ;;
    esac
    
    exit 0
    
    This goes in /etc/init.d/ as hyper-switch.sh
    sudo chmod +x /etc/init.d/hyper-switch.sh

    Finally run
    sudo update-rc.d hyper-switch.sh defaults

    Reboot.

    Connect a pushbutton between pin 5 (GPIO3) and GND.
    Pressing the button will toggle between setting the LED strip to all black and resuming normal operation.

    The code and info is mostly bits and pieces I found online and adjusted to fit my needs.. it seems to work fine so far.
     
    • Like Like x 2
  9. marpemim

    marpemim New Member

    Messages:
    1
    Hardware:
    +Arduino
    Hello,

    I need some similar to coreelec/libreelec, it is possible?

    Thanks