Skip to content

Instantly share code, notes, and snippets.

@nshores nshores/onkyo_reboot.py
Last active Oct 8, 2018

Embed
What would you like to do?
onkyo_reboot.py
#Reboot receiver when eISCP commands fail
#https://github.com/miracle2k/onkyo-eiscp
import eiscp
import requests
import time
import urllib
from influxdb import InfluxDBClient
#Define influxdb stuff
host='192.168.99.118'
port='8086'
dbname = 'cacti2'
client = InfluxDBClient(host=host, port=port, database=dbname)
#Define Vera URL
url = 'http://vera.local:49451/data_request?'
#Define receiver IP
receiver = eiscp.eISCP('192.168.99.130')
#Define vera request params
vera_switch_on = {
'id': 'action',
'DeviceNum': '77',
'serviceId': 'urn:upnp-org:serviceId:SwitchPower1',
'action': 'SetTarget',
'newTargetValue': '1',
}
vera_switch_off = {
'id': 'action',
'DeviceNum': '77',
'serviceId': 'urn:upnp-org:serviceId:SwitchPower1',
'action': 'SetTarget',
'newTargetValue': '0',
}
#Fixup vera request url encoding
vera_switch_on_qry = urllib.parse.urlencode(vera_switch_on).replace('%3A', ':')
vera_switch_off_qry = urllib.parse.urlencode(vera_switch_off).replace('%3A', ':')
def vera_request(qry):
s = requests.Session()
req = requests.Request(method='GET', url=url)
prep = req.prepare()
prep.url = url + qry
r = s.send(prep)
#Main loop
receiver_reachable = None
try:
#Try to send a command to the reciever
receiver_status = receiver.command('dimmer-level=bright')
except:
print("Cant connect to onkyo")
receiver_reachable = 0
json_body = [
{
"tags": {
"host": "onkyo",
},
"measurement": "reachable",
"fields": {
"int_value": receiver_reachable
}
}
]
client.write_points(json_body)
print("Turning Receiver off")
vera_request(vera_switch_off_qry)
#Sleep 5
time.sleep(5)
print("Turning Receiver on")
vera_request(vera_switch_on_qry)
else:
print('Success - Receiver Conencted!')
receiver_reachable = 1
json_body = [
{
"tags": {
"host": "onkyo",
},
"measurement": "reachable",
"fields": {
"int_value": receiver_reachable
}
}
]
client.write_points(json_body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.