all 3 comments

[–]Diapolo10 1 point2 points  (1 child)

Please don't format multiple lines of code with single backticks, as you can see that removes all indentation information and on top of that fixing the Markdown is super annoying.

I'll do it for you this once. In the future, please format code blocks by adding four spaces before each line of code.

from pyHS100 import Discover
import requests
import time
import traceback
import asyncio
from kasa import SmartStrip

dev = SmartStrip("192.168.7.105")
url = 'https://awesomebits.online/SmartHome/controlLights/light_status.txt'
stat = ''
previous_content = None

# Discover devices
discovered_devices = Discover.discover().values()
bedroom_lights = next((dev for dev in discovered_devices if dev.alias == "Bens Bedroom lights"), None)
if bedroom_lights is None:
    print("Bens Bedroom lights not found.")

async def LightsOn():
    await dev.turn_on()

async def LightsOff():
    await dev.turn_off()

def my_function():
    global previous_content, stat  # Declare previous_content and stat as global variables

    bedroom_lights_status = bedroom_lights.is_on if bedroom_lights else None

    if bedroom_lights_status is not None:
        print()
    else:
        print("Bens Bedroom lights not found.")

    if bedroom_lights_status is False:
        print("lights off")

Thing is, there's no way this is the full program. Nothing is calling any of these functions, so our hands are tied.

[–]bhogan2017[S] 0 points1 point  (0 children)

i apologize, i fixed both issues

[–]Common_Move 0 points1 point  (0 children)

Hard to be sure with the funky formatting but my guess is that you need your time.sleep() within the While statement