Max2play

Control Max2Play with Logitech Smart Control

Max2Play (www.max2play.com) on Raspberry Pi 3 is a great alternative for Logitech Squeezeboxes.

I needed a Jivelite setup for my HD screen to control my Logitech Touch as a couch potato without using binoculars. I had set my mind on controlling Max2Play with the Logitech Smart Control. Out of the box it doesn't:

Connect the Harmony bluetooth keyboard

First get Max2Play (Premium) and Jivelite up and running:
Burn the image on SD, Expand Filesystem, Update Kernel and Update Packages, Update Max2play.
Install Raspberry Cam plugin if you need it. If this plugin is installed later it won't work (in my case anyway).
Install the JiveLite and Bluetooth plugin from the max2play webpage.
In MyHarmony or the Harmony App create a new device: a Windows PC. Harmony remotes feature a bluetooth keyboard for three devices: Apple, WIndows and Other OS's. The big difference is the available keys. Only Apple and Windows have enough keys to play with and Windows offers the most. For instance "Esc" and most important "0" - "9".
Next create a Harmony activity with this new device and your other devices.
During the process Harmony wants to pair it's bluetooth keyboard to the Raspberry:
Start a SSH connection to the Pi3: ssh pi@your.ip password is "raspberry"
Start bluetoothctl
In bluetoothctl type scan on
The mac adress of the Harmony keyboard should popup
pair the harmony keyboard with pair 12:34:56:78:90. Replace the ID with your ID
Connect the harmony keyboard with connect 12:34:56:78:90.
Trust the harmony keyboard with trust 12:34:56:78:90. 
Harmony should display a message "pairing succesfull"
The webpage of max2play should now display a green text on the bluetooth page: "Following Bluetooth Speakers are known: Harmony Keyboard (12:34:56:78:90)". Yes your Harmony Keyboard is recognized as Bluetooth Speakers.
exit bluetoothctl
Keep SSH open

Program your Harmony remote
The basic keys are now available for your Harmony like direction keys and Esc which do most of the job controlling Jivelite. Program your remote the way you want it, minimal:
- Direction keys under the direction keys.
- Enter under the OK button
- and Esc under the Exit button.
This way the Harmony also works with Kodi if you need to remote control Kodi.
The hard part are the others keys. Jivelite supports every function with a hotkey. The file which controls this is /opt/jivelite/jivelite/share/jive/jive/InputToActionMap.lua. With a normal wired or bluetooth keyboard you can use all action keys. The Harmony bluetooth keyboard has most if not all normal keys missing.

I really needed the "Add" shortcut which does the same as the Add button on a Logitech Touch remote. With a normal keyboard "a" would do the job. Those keys are not available on a Harmony remote. Time to hack and remap some keys:

Hacking JiveLite

(re)open SSH to max2play
cd /opt/jivelite/jivelite/share/jive/jive 
sudo nano InputToActionMap.lua
Find any line with ["1"] ["2"] etc and comment it out, for instance:
-- ["1"] = "play_preset_1",
Add the following lines:
-- begin logitech harmony
["1"] = "go_current_track_info",
["2"] = "go_home_or_now_playing",
["3"] = "add",
["4"] = "add_end",
["5"] = "play_next",
["6"] = "play",
["7"] = "pause",
["8"] = "volume_up",
["9"] = "volume_down",
["0"] = "mute",
["\13"] = "go", -- RETURN
--end logitech harmony
Don't forget the last one. Without this hack Jivelite won't respond to the Ok button.
Save the file and exit.
Exit SSH
Restart Jivelite or reboot the Pi. Don't restart or reboot with nano editing the lua file! If you do reinstall Jivelite from the max2play webpage and reapply the hack.
After a reboot of the Pi sometimes your remote doesn't respond. Stop and Start JiveLite from the max2play webinterface and JiveLite now recognizes the (Harmony Bluetooth) keyboard.
The "1" key is available for Harmony remotes. Program the "1" key under any button for instance the Info button. "2" goes under the Menu button, "6" for Play, and "7" for Pause. "4" and "5" some other button.

Done!

Remember:

Everytime you reinstall Jivelite, the file InputToActionMap.lua is back to factory defaults and you need to fire up SSH to reapply the hack.