Skip to content

Instantly share code, notes, and snippets.

@milbar
Created June 19, 2024 14:57
Show Gist options
  • Save milbar/c04fe1d2b460f8aa5a5589cb6b47987d to your computer and use it in GitHub Desktop.
Save milbar/c04fe1d2b460f8aa5a5589cb6b47987d to your computer and use it in GitHub Desktop.
BroadLink Thermostat Schedule Setup
import broadlink
import time
from typing import List
def discover_devices():
devices = broadlink.discover(timeout=5, local_ip_address='')
if devices:
for device in devices:
device.auth()
print(f"Connected to {len(devices)} devices")
return devices
else:
raise Exception("No Broadlink devices found")
def main():
devices = discover_devices()
# Define the weekday schedule
weekday_schedule = [
{'start_hour': 6, 'start_minute': 0, 'temp': 25},
{'start_hour': 8, 'start_minute': 0, 'temp': 22},
{'start_hour': 12, 'start_minute': 0, 'temp': 22},
{'start_hour': 14, 'start_minute': 0, 'temp': 22},
{'start_hour': 18, 'start_minute': 0, 'temp': 25},
{'start_hour': 22, 'start_minute': 0, 'temp': 25}
]
# Define the weekend schedule
weekend_schedule = [
{'start_hour': 8, 'start_minute': 0, 'temp': 25},
{'start_hour': 22, 'start_minute': 0, 'temp': 25}
]
# Set the schedule on the device
# device.set_schedule(weekday_schedule, weekend_schedule)
#device.set_power(1)
for device in devices:
device.set_power(1)
time.sleep(2)
device.set_schedule(weekday_schedule, weekend_schedule)
device.set_power(0)
time.sleep(2)
device.set_power(1)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment