Coder Social home page Coder Social logo

firstone / restremote Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 7.0 157 KB

RESTful API based universal remote control

License: MIT License

Python 74.84% Shell 0.26% C++ 15.47% CSS 1.11% HTML 6.48% JavaScript 1.84%
restful-api rest remote-control lg tivo denon-avr shield android isy

restremote's Introduction

RESTRemote

Summary

Simple REST service that allows multiple devices control via similar interface. It allows easy additional of other device drivers. It current supports following:

  • LG Web OS TV (via WebSockets)
  • Tivo (via Tivo IP interface)
  • nVidia Shield (and probably other Android devices, via adb debug capability)
  • Denon AVR (via Denon IP interface)
  • Most IR devices (via ESP8266 board)

Getting Started

Install python3 and run install.sh

Configuration is done via configuration file (cfg/config.yaml). If you don't have one, it will be copied from cfg/config_sample.yaml.

If you don't have a particular device and don't want to load its driver, you can turn disable it by changing enabled: false.

Most devices require only host name defined.

You need to specify both, config file and server config file (cfg/server_config.yaml) in the command line. Run restremote.py --help for command line options.

Once service is running, you can execute GET calls via browser:

http://localhost:5000/devices

or via command line. For example, curl:

curl -i -X GET http://localhost:5000/living_tivo/commands

PUT commands have to be done from command line or tool:

curl -i -X PUT http://localhost:5000/living_tv/mute/on

Basic commands

  • /devices - list configured drivers
  • /<device name>/commands - list all available commands with method (GET, PUT)

Devices

Devices represent your physical AV devices and use drivers to communicated with them.

Each device has key (short name), which is what you use in REST command, a driver associated with it, as well as configuration parameters. Configuration parameters depend on the driver. See the driver section for configuration details.

Drivers

Tivo

There is not much to set up, other than hostName. Just look up IP in Tivo and plug it in. If you configure it for static IP in a router, this will never need to be changed. I'm not aware of any way to auto discover it.

Denon AVR

Denon ARV has auto discovery but I didn't see any of it documented. Just plug in host name or IP into hostName. If you configure your router for static IP, this never needs to be changed.

LG TV (Web OS devices)

Latest models don't need to be configured. They respond on WebSocket hostname of lgwebostv. If your device doesn't, plug host name or IP into hostName. There is a way to auto discover but I didn't code it since lgwebostv works.

The first time you start the service, it needs to be accepted on TV. Start the server, turn TV on and issue any command. You will see the prompt on TV. Clicks 'Accept'. If this fails for any reason, restart the service and try again. This will write client key so config directory needs to be writable. Or else, change clientKeyFile to point to writable location.

For some reason listing available launch point or available app doesn't work for me. So you can usually turn on an app, then issue get running app status command, and use that ID to configure launch commands.

If TV doesn't turn on using Power On command, set Broadcast Address parameter to you match your subnet. For example, if you TV's IP address is 192.168.0.xxx, set Broadcast Address to 192.168.0.255

Shield (Android devices)

Android based devices use adb debugging mode. Make sure you have adb installed and configured in executable. It either has to be in path or have absolute path specified. Not sure if there's auto discovery so just plug host name or IP into hostName.

Android device needs to be configured for network debugging. Usually you need to turn on USB debugging first. Once that's done, option for network debugging is available.

First time you turn it on, make sure your device is on, and it will prompt you to accept connection from your server MAC address. You only need to accept it once.

If you're getting unauthorized errors, try adb kill-server, followed by adb connect <host name>:5555. This should bring authorization dialog again.

If commands don't work, run adb devices. If device is listed offline, reboot it, run adb kill-server and run adb connect <host name>:5555. After that, adb devices should show status as online. It appears that only one MAC address can control Android device at a time. So every time you connect from another MAC, this needs to be repeated to switch to a new MAC.

In order to configure launching apps, issue command to list installed apps (it takes a while). This will return list off apps and launch activities.

ESP8266

This one requires most work. Schematics can be obtained here:

https://github.com/mdhiggins/ESP8266-HTTP-IR-Blaster

Do not load firmware from that page. Instead load firmware from esp8266 directory. You need Arduino IDE, ESP8266 libraries, ESPWebServer and IRRemoteESP8266.

DO THIS STEP BEFORE YOU TEACH ANY CODES. IT WILL REMOVE ANY EXISTING CODES Follow instruction for ESP8266 to setup file system transfer in Arduino IDE. After that, transfer files. It will pick up files in data directory. You don't need to specify them.

Connect to the blaster via browser and teach IR commands. After that you need to edit cfg/server_config.yaml file and assign command names to driver commands. At that point you should be able to send them though RESTRemote server.

restremote's People

Contributors

firstone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

restremote's Issues

set_channel function not working

Getting an error when trying to use the set channel function:
command.get('value'))
File "/var/polyglot/nodeservers/AVRemote/drivers/base_driver.py", line 107, in executeCommand
result['output'] = self.sendCommandRaw(commandName, command, args)
File "/var/polyglot/nodeservers/AVRemote/drivers/tivo_ip.py", line 30, in sendCommandRaw
conn.send(command['code'].encode())
KeyError: 'code'

`future feature annotations is not defined` when i try to start the server

i'm on mac osx 11.6.5

$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3

$ python3 restremote.py -c ./cfg/config.yaml -sc ./cfg/server_config.yaml 
2022-04-28 14:25:05,563 INFO     Starting with config file ./cfg/config.yaml
Traceback (most recent call last):
  File "restremote.py", line 99, in <module>
    RESTRemote()
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "restremote.py", line 72, in RESTRemote
    module = importlib.import_module('drivers.' + driverName)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/eflister/Downloads/RESTRemote-master/drivers/chromecast.py", line 1, in <module>
    import pychromecast
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/pychromecast/__init__.py", line 14, in <module>
    from . import socket_client
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/pychromecast/socket_client.py", line 24, in <module>
    from .controllers import BaseController
  File "/Users/eflister/Library/Python/3.6/lib/python/site-packages/pychromecast/controllers/__init__.py", line 4
    from __future__ import annotations
    ^
SyntaxError: future feature annotations is not defined

in config.yaml i set enable: true for the tv. i'm trying to control an lg c1. i haven't figured out the TV's MAC yet.

Error on Chromecast discovery

Throwing an error when trying to discover Chromecast devices

Current Version: 0.9.1

2022-06-05 08:59:44,769 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for android
2022-06-05 08:59:44,769 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for web_os
2022-06-05 08:59:44,769 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for tivo_ip
2022-06-05 08:59:44,769 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for denon_avr
2022-06-05 08:59:44,770 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for onkyo_avr
2022-06-05 08:59:44,770 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for esp8266
2022-06-05 08:59:44,770 Controller polyinterface      DEBUG    remotecontroller:discover: Running discovery for chromecast
2022-06-05 08:59:49,838 Controller polyinterface      ERROR    polyinterface:_parseInput: _parseInput: failed controller.runCmd(DISCOVER) 'Chromecast' object has no attribute 'device'
Traceback (most recent call last):
  File "/home/pi/.local/lib/python3.9/site-packages/polyinterface/polyinterface.py", line 842, in _parseInput
    self.nodes[input[key]['address']].runCmd(input[key])
  File "/home/pi/.local/lib/python3.9/site-packages/polyinterface/polyinterface.py", line 745, in runCmd
    fun(self, command)
  File "/home/pi/.polyglot/nodeservers/AVRemote/poly/remotecontroller.py", line 188, in discover
    devices = self.get_device_driver(driverName,
  File "/home/pi/.polyglot/nodeservers/AVRemote/drivers/chromecast.py", line 143, in discoverDevices
    friendly_name = cast.device.friendly_name
AttributeError: 'Chromecast' object has no attribute 'device'```

tivo device is not working properly

I have installed the code and been able to get the denon_avr driver to function.
Your tivo driver is producing an error and not working. I have an older version of this code and it still works. Wondering if you have tested that portion lately?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.