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

REQUEST nice feature

Discussion in 'Feature Requests' started by iiidefconiii, 5 September 2016.

  1. iiidefconiii

    iiidefconiii Member

    Messages:
    106
    Hardware:
    32/64bit, +Arduino
    Hi, i have a nice feature in my kodibuntu, i dont take credits writing the code, cause someone else did.
    But its such a nice feature.

    From my harmony remote (i configured 2 buttons) with keymap the refer to scripts.

    One script will change static background colour, each time i press the same button it will go to the next, same idea for the effectswitch.py

    Can we implant this script in hyperion ng, and make and hyperion-remote command? for me there is no need, but maybe others also like this.

    Scnd request: in hyperion,ng maybe its nice if we can setup the background to change to some pre-defined effects.

    The scripts are down below.

    effectswitch.py
    Code:
    import json
    import subprocess
    
    colors = ['Snake',
              'Strobe',
              'Rainbow swirl fast',
              'mood-blobs',
              'red',
              'purple',
              ]
    
    defaultData = {"color":"purple",
                   "effect":"Blue\\ mood\\ blobs"
                   }
    
    effects = ['Blue\\ mood\\ blobs',
              'Cold\\ mood\\ blobs',
              'Full\\ color\\ mood\\ blobs',
              'Green\\ mood\\ blobs',
              'Red\\ mood\\ blobs',
              'Warm\\ mood\\ blobs',
              'Rainbow\\ swirl',
              ]
             
    def read_current():
        try:
            with open('/usr/share/hyperion/scripts/currenteffect.json', 'r') as f:
                data = json.load(f)
            f.close()
            if data == '':
                return defaultData
            else:
                return data
        except (IOError, ValueError):
            return defaultData
       
    def write_current(data):
        try:
            with open('/usr/share/hyperion/scripts/currenteffect.json', 'w') as f:
                json.dump(data, f)
            f.close()
        except IOError:
            pass
       
    def parse_current_effect():
        pass
    
    def set_current_effect():
        pass
    
    def set_effect(effect):
        subprocess.Popen('/usr/share/hyperion/bin/hyperion-remote --priority 100 --effect ' + effect, shell=True)
    
    def main():
        current_data = read_current()
        for i,effect in enumerate(effects):
            if effect == current_data['effect']:
                if i == len(effects) - 1:
                    current_data['effect'] = effects[0]
                    break
                else:
                    current_data['effect'] = effects[i + 1]
                    break
           
        write_current(current_data)
        set_effect(current_data['effect'])
       
    main()
    colourswitch.py
    Code:
    import json
    import subprocess
    
    colors = ['purple',
              'orange',
              'blue',
              'green',
              'red',
              'cyan',
              ]
    
    defaultData = {"color":"purple",
                   "effect":"night rider"
                   }
    
    def read_current():
        try:
            with open('/usr/share/hyperion/scripts/currentcolour.json', 'r') as f:
                data = json.load(f)
            f.close()
            if data == '':
                return defaultData
            else:
                return data
        except (IOError, ValueError):
            return defaultData
       
    def write_current(data):
        try:
            with open('/usr/share/hyperion/scripts/currentcolour.json', 'w') as f:
                json.dump(data, f)
            f.close()
        except IOError:
            pass
       
    def parse_current_effect():
        pass
    
    def set_current_effect():
        pass
    
    def set_color(color):
        subprocess.Popen('/usr/share/hyperion/bin/hyperion-remote --priority 100 --color ' + color, shell=True)
    
    def main():
        current_data = read_current()
        for i,color in enumerate(colors):
            if color == current_data['color']:
                if i == len(colors) - 1:
                    current_data['color'] = colors[0]
                    break
                else:
                    current_data['color'] = colors[i + 1]
                    break
           
        write_current(current_data)
        set_color(current_data['color'])
       
    main()
     
  2. penfold42

    penfold42 Moderator Developer

    Messages:
    750
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    I think we should maintain a separate Hyperion "addons" repository for stuff like this.
    I've already got a lirc script to act on key presses and this would make a good addition to the collection

    Thanks for sharing !

    https://github.com/penfold42/hyperion-lirc
     
  3. Brindosch

    Brindosch Active Member

    Messages:
    678
    Hardware:
    RPi1/Zero, RPi2, RPi3, +nodeMCU/ESP8266
    Nice script!
    Well, it might be possible to implement something like this, and take care of addons and addition that could be installed optional.
    As we don't want to keep the current (very static) way you use effects it will look more different.
     
  4. iiidefconiii

    iiidefconiii Member

    Messages:
    106
    Hardware:
    32/64bit, +Arduino
    That seems cool, but I have no clue how to install this and how it works, do I need to configure the key mapping towards you're scripts or? TY
     
  5. penfold42

    penfold42 Moderator Developer

    Messages:
    750
    Hardware:
    RPi1/Zero, RPi2, RPi3, 32/64bit, +Arduino, +nodeMCU/ESP8266
    My script bypasses any key mapping and constantly queries lircd for the keys that are pressed.

    It then looks at the remote name and the button name to work or what to do.
     
  6. TPmodding

    TPmodding Administrator Staff Member Administrator

    Messages:
    1,296
    Hardware:
    RPi1/Zero, RPi2, RPi3, +Arduino, +nodeMCU/ESP8266
    as @penfold42 and @Brindosch said, we could add later a "addon" option but the focus is now on the hyperion ng release
     
  7. iiidefconiii

    iiidefconiii Member

    Messages:
    106
    Hardware:
    32/64bit, +Arduino
    you need to add
    from subprocess import os
    os.system("hyperion-remote --sourceAutoSelect")

    to both files, to start up the leds again, so when its in a --sourceOff mode, it also work when pressing a button.