controlling multiple programs from single remote

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
te36
Posts: 23
Joined: Sat Jan 19, 2019 4:57 am

controlling multiple programs from single remote

Post by te36 » Wed Jan 23, 2019 7:39 pm

Never really played around with eventghost beside most basic mapping, MCE remote -> kodi plus a few custom command.

The most basic thing i am trying to understand is if/how eventghost would allow me control multiple programs from a single remote. Lets say i have N buttons to select one of N programs. Building the macro to bring that program window to front is fine, but how do i build a state machinery whereby each "standard" key would be mapped differently based on the program key last pressed in before ?

slattynan
Experienced User
Posts: 52
Joined: Fri Jul 06, 2018 12:15 pm

Re: controlling multiple programs from single remote

Post by slattynan » Thu Jan 24, 2019 8:59 pm

There are probably many ways to achieve this.

I do it by using dedicated buttons on the remote which triggers the enable and disable action on groups of functions (in folders) relating to the device/program you are trying to control.

In the image below I have 4 modes, plex, kodi, screensaver and Spotify. Each has different commands mapped to the remote inputs and various other characteristics, for instance, the monitor stays on permanently in screen saver mode. It also allows me to use the same Alexa commands for multiple devices

Image

User avatar
kgschlosser
Site Admin
Posts: 4623
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: controlling multiple programs from single remote

Post by kgschlosser » Mon Feb 18, 2019 7:15 am

late answer here sorry for that. to add to @slattynan's solution you can really tweak what buttons do what using the following logic.

it can be done using power states from a device. or it can be done using if the program is running or not.

you can also split the control. what I mean by that is.. say you have your TV on and your surround sound AVR off then the remote would operate the TV completely.

if the AVR is on and the TV off. then the controls would operate the AVR. if the TV is on and the AVR is on then the volume buttons would operate the volume on the AVR and the navigation controls would operate the TV.

hell why not toss in there having a program like plex or media portal running.

so if the TV is on and the TV source is set to PC and the AVR is on.
the volume would operate the volume on the AVR the navigation controls would control your HTPC software the setup menu button would still operate the TV menu. when the button is pressed then it would swap the navigation button controls over to controlling the TV. set that on a timeout period or a special "exit" button that would put the navigation controls back to controlling the HTPC software.

all of the above is done using the Enable action and the Disable action. you create a folder in your eventghost tree that contains all of the macros for each button press on the remote. name the folder something like. TV-On AVR-On Source-PC. put the actions into the macros for the buttons you want activate that action.

create a folder like this for each scenario.

you then create macros for TV power and AVR power and TV source.

if the plugin for the TV or AVR has a get action for the power and source then use that action. if it does not you will have to store the value when the event gets triggered for that state change.

you store the states into eg.globals. the logic for this is best accomplished by using python scripts

below is an example of storing the state changes.

code for the TV power event script
add the tv power event

Code: Select all

event = eg.event.suffix
state = event.split('.')[-1].lower()

if state == 'on':
    tv_state = True
else:
    tv_state = False

eg.globals.tv_state = tv_state
code for the TV source event script
add the tv source change event

Code: Select all

event = eg.event.suffix
tv_source= event.split('.')[-1].lower()
eg.globals.tv_source = tv_source
code for the AVR state script
add the avr power event

Code: Select all

event = eg.event.suffix
state = event.split('.')[-1].lower()

if state == 'on':
    avr_state = True
else:
    avr_state = False

eg.globals.avr_state = avr_state 
because of how EG processes events you will create 3 more macros. they have to be placed in a specific order. and they also have to be placed after the 3 scripts above.

tv on avr off macro

Code: Select all

tv_state = getattr(eg.globals, 'tv_state', False)
avr_state = getattr(eg.globals, 'avr_state', False)

if not tv_state or avr_state:
    eg.StopMacro()
    eg.Exit()
then add an enable action and point it to the folder that is for TV-On AVR-Off
add a disable action and point it to TV-Off AVR-On
add another disable action and point it to TV-On AVR-On SOURCE-PC

avr on tv off macro

Code: Select all

tv_state = getattr(eg.globals, 'tv_state', False)
avr_state = getattr(eg.globals, 'avr_state', False)

if tv_state or not avr_state:
    eg.StopMacro()
    eg.Exit()
then add an enable action and point it to the folder that is for TV-Off AVR-On
add a disable action and point it to TV-On AVR-Off
add another disable action and point it to TV-On AVR-On SOURCE-PC

avr on tv on source pc macro

Code: Select all

tv_state = getattr(eg.globals, 'tv_state', False)
avr_state = getattr(eg.globals, 'avr_state', False)
tv_source = getattr(eg.globals, 'tv_source', 'pc')

if tv_state and avr_state and tv_source == pc:
    pass
else:
    eg.StopMacro()
    eg.Exit()
then add an enable action and point it to the folder that is for TV-On AVR-On SOURCE-PC
add a disable action and point it to TV-On AVR-Off
add another disable action and point it to TV-Off AVR-On

add the avr power event and the tv power event and the tv source change event to all 3 of the above macros.
again the 3 above macros MUST be placed in the tree in the order above. they also must be placed after first macros.

the above is pseudo code and has not been tested. by using the enable and disable on the folders you are able to activate the group of remote button macros that you want to use and then disable the others.

because EG runs the macros in a top down and left to right fashion you are able to have an event run the macros in a specific order and have it not process the contents of the macro if a specific set of conditions are not met. at which time it will move to the next macro.

we do not care if we activate the TV-ON AVR-ON folder if the source happens to be PC. it will process that event last and discover the source is in fact set to PC and make the changes needed. this works correctly because if the source happens to not be set on PC then the correct folder has been enabled.

this kind of a scenario can get out of sorts if you have to restart eventghost and there is no "get' actions for hee plugin that controls the PC or the plugin that controls the AVR.

you can also add some additional checking to see if the HTPC software is running as well or if you happen to use more then a single application for viewing media you can define buttons specific to that program depending on whether or not it is running.

if the above doesn't make any sense let me know.
If you like the work I have been doing then feel free to Image

Post Reply