I was using Unifi Presence with ST, and have nearly got it ported over to HE. I just have no idea about python and how to call the right commands.
I'm using the Maker API app for controlling the Virtual switch (since Maker API doesnt like presence, as per here: Maker API app error, and have change the 'home' and 'away' to 'on' and 'off'.
I've worked out the Unifi portion, and I've worked out what needs to be entered in HE, but I'm not sure how to send the command from python to HE.
This is the command that I need to send to HE. I've tested it in a web browser and it works, changing the switch from off to on.
http://[HUB ip]/apps/api/[maker API]/devices/[device ID]/on?access_token=[access token]
Previously, I've been using python to send a command to ST, but that code no longer works. How on earth do I send that command to HE in python. This is the snippet of code from python that I've modified. I realise that many of the definitions refer to ST, but that's mostly irrelevant, since in the configuration file whilst they are a ST naming convention, they point to HE. This is the snippet of code. The other parts of the code login to the Unifi controller and get presence based on mac address.
Original Code
def updateSmartThings(urlStShardbase, appID, AccessToken, currStatus):
if currStatus == 'Present':
status = 'home'
else:
status = 'away'
url = urlStShardbase + "/api/smartapps/installations/" + appID + "/Phone/" + status + "?access_token=" + AccessToken
# print url
try:
r = requests.get(url)
except requests.exceptions.RequestException as e:
print e
sys.exit("SmartThings Update Failed")
if not r.status_code == requests.codes.ok:
print datetime.datetime.now(), "SmartThings update failed with status code ", r.status_code
if int(r.status_code) == '500':
print datetime.datetime.now(), "Is this really a Virutal Presence Sensor?"
Modified code
def updateSmartThings(urlStShardbase, appID, AccessToken, currStatus):
if currStatus == 'Present':
status = 'on'
else:
status = 'off'
url = http://[HUB ip]/apps/api/[maker API]/devices/[device ID]/on?access_token=[access token]
# print url
try:
r = requests.get(url)
except requests.exceptions.RequestException as e:
print e
sys.exit("SmartThings Update Failed")
if not r.status_code == requests.codes.ok:
print datetime.datetime.now(), "SmartThings update failed with status code ", r.status_code
if int(r.status_code) == '500':
print datetime.datetime.now(), "Is this really a Virutal Presence Sensor?"
It even fails if I modify the line that begins url = ???? to url = http://[HUB ip]/apps/api/[maker API]/devices/[device ID]/on?access_token=[access token]
Any suggestions? All I really need, I think, it what code to change the url =
Paging @Navat604 since you indicated some interest in this project some months ago. But love help from anyone.