Flask-Samsung – A REST API to control Samsung TV’s (2012/2013 series)

This is a really simple Flask-Based RESTfull API to control a samsung TV (2012/2013 models) just because…sometimes the remote is too far away and why not?
I am not sure if this will work for recent models.
Make sure your tv is connected to the internet and the network remote control option is enabled in the tv settings.

Instalation:

PHP Code:
pip install flask 
PHP Code:
git clone https://github.com/enen92/flask-samsung 
PHP Code:
cd flask-samsung 
PHP Code:
python samsung.py 

Configuration
It is important that the API knows how to translate channel names into button presses. You can setup your channels by editing the file channels.json identifying your TV channels and the respective position on the EPG.
You need also to define the IP address of the Television and the IP address of the device running the API. Both variables are defined in the beginning of samsung.py python file.

Available endpoints:

http://127.0.0.1:5000/tv/channel/ – returns the list of channels defined on channels.json

http://127.0.0.1:5000/tv/channel/SIC – changes the TV to the channel identified as SIC

http://127.0.0.1:5000/tv/sendkey/ – lists all available remote keys

http://127.0.0.1:5000/tv/sendkey/KEY_CHUP – sends key Channel Up to the TV (see keys.json for the list of all available keys)

http://127.0.0.1:5000/tv/switchchannel/22 – sends 22 to the TV for it to switch the channel

http://127.0.0.1:5000/tv/volup/5 – sends 5 volume up keys to the TV

http://127.0.0.1:5000/tv/voldown/5 – sends 5 volume down keys to the TV

Source: https://github.com/enen92/flask-samsung
Licence: GPLv3
Adapted from Asif Iqbal 2012 project