nkgilley / python-ecobee-api

Python API for controlling Ecobee Thermostats
MIT License
44 stars 40 forks source link

Add ability to change preset settings (climates) #59

Open rianadon opened 3 years ago

rianadon commented 3 years ago

I'm working on extending the Home Assistant Ecobee integration to support changing preset cool & heat temperatures as another option for automation. The Ecobee API supports changing the thermostat's program by re-uploading both the program schedule and climate (i.e. preset settings) information.

I've written a brief proof of concept below that change's a presets' temperature settings. By editing other fields of thermostat["program"], it would be possible to edit the thermostat's schedule and or other preset settings.

thermostat = ecobee.thermostats[thermostat_index]

# Find the first preset with name set to "Home" and change its settings
homeprogram = next(c for c in thermostat["program"]["climates"] if c["name"] == "Home")
homeprogram["coolTemp"] = 850 # 85 degrees
homeprogram["heatTemp"] = 600 # 60 degrees

body = {
    "selection": {
        "selectionType": "thermostats",
        "selectionMatch": thermostat["identifier"],
    },
    "thermostat": {"program": thermostat["program"]},
}
log_msg_action = "update program"
ecobee._request("POST", ECOBEE_ENDPOINT_THERMOSTAT, log_msg_action, body=body)

Would it be possible to add a method to change a given preset's coolTemp and heatTemp to the library? Or perhaps change all of the preset's settings (which include options like color and whether people are away or home during the preset)? Or maybe it would be cleanest to have a method to change the whole program (including schedule and preset/climate settings)?