I’m trying to create an automation to cure what appears to be flaws in my audio system. When I turn my TV on, the soundbar cuts out. All that has to be done is to send a signal down to tell it to use the source. I use a vizio soundbar which does have an api to control it. I can call the correct curl to the api and fix the problem. The cURL is to a secure URL, but it’s a self signed certificate, so I have to use an insecure request. I’ve tried many different ways to accomplish this inside hassio (python script - can’t import requests, command_line_switch - can’t do insecure requests, input_boolean - calling a switch with the rest API… again can’t call insecure request), but as you can tell each time I ran into a wall.
What I want to do is to run an automation that is triggered by the tv turning on, so that it all happens seemlessly, but I can’t find anywhere inside hassio that will allow me to call an insecure request. In appdaemon, it seems to accept the “verify=false” at the end of the request which is what allows it to function correctly outside of hassio/appdaemon, but when I post that inside appdaemon, it seems to ignore the flag.
Here’s my code in appdaemon (I’m using a input_boolean as a trigger for testing until the script works):
import appdaemon.plugins.hass.hassapi as hass
import requests, json
class change_input(hass.Hass):
def initialize(self):
self.log('Vizio Input change script loaded.')
self.listen_state(self.change, "input_boolean.vizio_source", new="on")
def change(self, entity, attribute, old, new, kwargs):
#powermode = requests.get('https://192.168.1.142:9000/state/device/power_mode', verify=False)
response = requests.get('https://hassio:9000/menu_native/dynamic/audio_settings/input/current_input', verify=False)
self.log(response.text)
# example response below
# {
# "ITEMS": [{
# "NAME": String,
# "CNAME": String,
# "TYPE": String,
# "VALUE": String,
# "ENABLED": Boolean,
# "HASHVAL": Integer
# }],
# "NAME": String,
# "HASHLIST": Array,
# "GROUP": String,
# "PARAMETERS": {
# "HASHONLY": String,
# "FLAT": String,
# "HELPTEXT": String
# },
# ...
# }
response_dict = json.loads(response.text)
hashval = str(response_dict["ITEMS"][0]["HASHVAL"])
self.log(hashval)
headers = {'Content-Type': 'application/json'}
data = '{"REQUEST": "MODIFY","VALUE": "HDMI-ARC","HASHVAL":' + hashval + '}'
response2 = requests.put('https://hassio:9000/menu_native/dynamic/audio_settings/input/current_input', headers=headers, data=data, verify=False)
self.log(response2.text)
and here is the error I get in the appdaemon log:
requests.exceptions.SSLError: HTTPSConnectionPool(host='hassio', port=9000): Max retries exceeded with url: /menu_native/dynamic/audio_settings/input/current_input (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1056)')))
2019-10-18 20:46:06.362459 WARNING AppDaemon: ------------------------------------------------------------
I’m open to trying other avenues as well, but every path I’ve taken runs into this same issue. I’ve been working on this for a few days and I think I’m about out of ideas here. Seems like a pretty simple issue, but I don’t know how to make this happen at this point. Any help is appreciated. Thanks!