Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Refresh token for Wyze SDK
#1
I have added a few Wyze smart bulbs to my home security system, running them on their own program but using door sensors from the security program. Everything works when I start the program, but after a few days the token expires and I get errors. I want the token to refresh maybe once per day as a precaution. In the github thread (found here) for this Wyze SDK, a post contained the suggestion that I add a loop to my code. According to that thread, the loop would look like this:

client = Client(email=os.getenv('WYZE_EMAIL'), password=os.getenv('WYZE_PASS'))
 -- Loop here --
     <check sensor status>
     response=client.refresh_token()
     client._token = response["data"]["access_token"]
     client._refresh_token = response["data"]["refresh_token"]
But I'm not sure where to put it in my code (sensitive stuff removed). How do I add a daily or every few hours recurring refresh command?

from gpiozero import Button, LED
from signal import pause
from time import sleep
from datetime import datetime
from datetime import timedelta
import requests

from wyze_sdk import Client
from wyze_sdk.errors import WyzeApiError
client = Client(email="[email protected]", password="ShutYaMouf")

garagepassage = Button(20)  # Input from garage passage door
stairspassage = Button(18)  # Input from door at top of stairs

now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print("Door Started at ", current_time)
r = requests.post("https://autoremotejoaomgcd.appspot.com/sendnotification?key=APA91bHuMGY0IPSomeSecretStuffHereygUkO2Ody2SsXjiC&title=Just%20Saying&text=Switch%20monitoring%20has%20begun")

bulbS1 = client.bulbs.info(device_mac='LKFI*&DFYF')
bulbS2 = client.bulbs.info(device_mac='HFKHDKFh686F')



def open():
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    print("Door open at " + current_time)
    client.bulbs.turn_on(device_mac=bulbS1.mac, device_model=bulbS1.product.model)
    client.bulbs.turn_on(device_mac=bulbS2.mac, device_model=bulbS2.product.model)
    client.bulbs.turn_off(device_mac=bulbS1.mac, device_model=bulbS1.product.model, after=timedelta(hours=.5))    
    client.bulbs.turn_off(device_mac=bulbS2.mac, device_model=bulbS2.product.model, after=timedelta(hours=.5))
    print("on")
    


def closed():
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    print("Door closed at " + current_time)
    client.bulbs.turn_off(device_mac=bulbS1.mac, device_model=bulbS1.product.model, after=timedelta(hours=.1))
    client.bulbs.turn_off(device_mac=bulbS2.mac, device_model=bulbS2.product.model, after=timedelta(hours=.1))
    print("off")
        
stairspassage.when_pressed = closed
stairspassage.when_released = open
garagepassage.when_pressed = closed
garagepassage.when_released = open

pause()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to sign JWT token with JWK key stucoder 1 1,700 Feb-21-2022, 09:04 AM
Last Post: stucoder
  Python requests oauth2 access token herobpv 6 3,943 Sep-27-2021, 06:54 PM
Last Post: herobpv
  unexpected token < in json at position 0 Frodoxzibit 5 2,819 Jul-10-2021, 09:33 AM
Last Post: Larz60+
  Refresh data in python script while running in Terminal frankenchrist 4 7,315 Feb-03-2021, 09:54 AM
Last Post: Larz60+
  counting down in while with refresh andrzej357 1 1,670 Jul-17-2020, 10:17 AM
Last Post: Gribouillis
  / token in function parameterlist tpourjalali 1 1,883 Apr-12-2020, 07:05 PM
Last Post: deanhystad
  Getting an "Unexpected Token" Error and don't know why... NotAHackusator 1 1,859 Nov-20-2019, 03:00 PM
Last Post: buran
  get and reuse the token value with huawei modem Reims 1 4,591 Oct-02-2019, 04:29 AM
Last Post: Reims
  Need help in adding xsrf token keerthiprashanth 1 2,050 Aug-08-2019, 02:35 PM
Last Post: keerthiprashanth
  Python - joining xmls together invalid token error jan86 0 2,221 Apr-26-2019, 08:52 AM
Last Post: jan86

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020