From b470a3a2cef4119f101d75fe7f64d39041b50445 Mon Sep 17 00:00:00 2001 From: Rich O Date: Wed, 27 Nov 2019 14:34:07 -0500 Subject: [PATCH] added code to turn light back off --- r0b3bot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/r0b3bot.py b/r0b3bot.py index 412d762..e787be9 100644 --- a/r0b3bot.py +++ b/r0b3bot.py @@ -284,7 +284,18 @@ async def printstat(ctx): # If we turned on the light, let's be nice and turn it back off if turned_on_light: print(" - Turning Light back Off") - remote.call_service(hassapi, 'switch', 'turn_off', {'entity_id':'{}'.format('switch.work_lights')}) + try: + # REST API call to home assistant to turn the light off. + #remote.call_service(hassapi, 'switch', 'turn_on', {'entity_id':'{}'.format(HASS_LIGHT)}) + hassAPIRUL = HASS_IP_ADDRESS + "/api/services/switch/turn_off" + payload = { + "entity": HASS_LIGHT + } + requests.post(hassAPIURL, data=payload, headers=hassHEADERS) + except: + # Do nothing is this fails + print(" ! Unable to turn off light") + pass # Send the image to the chat channel print(" - Uploading image to chat channel") -- 2.39.5