Skip to content

Instantly share code, notes, and snippets.

@hnykda
Last active October 29, 2023 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnykda/03c3b7c3cab328223651e58bc6c7e899 to your computer and use it in GitHub Desktop.
Save hnykda/03c3b7c3cab328223651e58bc6c7e899 to your computer and use it in GitHub Desktop.
Home Assistant PyScript setting temperatures via pyvicare
from PyViCare.PyViCare import PyViCare
COMFORT = "comfort"
NORMAL = "normal"
REDUCED = "reduced"
SLEEP = 5
@pyscript_executor
def circuit_factory():
client_id = "{YOUR CLIENT ID FROM VIESSMAN API PORTAL}"
email = "{YOUR VIESSMAN USER EMAIL}"
password = "{YOUR VIESSMAN USER PASSWORD}"
vicare = PyViCare()
vicare.initWithCredentials(email, password, client_id, "vicare_manual_set_token.save")
# if you have multiple devices or circuits,
# you may have to find yours in a safer way. Most people have
# just one, so this works
device = vicare.devices[0]
boiler = device.asAutoDetectDevice()
return boiler.circuits[0]
circuit = circuit_factory()
@pyscript_executor
def _set_program_temperature(name, temperature):
circuit.setProgramTemperature(name, temperature)
@service
def set_default_temperatures(reduced=None, normal=None, comfort=None):
"""yaml
name: Set vicare temperature for given programs
description: Sets a temperature of specific vicare programs
fields:
reduced:
description: temperature of the reduced program
example: 12
required: false
normal:
description: temperature of the normal program
example: 18
required: false
comfort:
description: temperature of the comfort program
example: 23
required: false
"""
log.info(f"Settings program temperatures: {REDUCED}={reduced}, {NORMAL}={normal}, {COMFORT}={comfort}")
if reduced:
_set_program_temperature(REDUCED, reduced)
task.sleep(SLEEP)
if normal:
_set_program_temperature(NORMAL, normal)
task.sleep(SLEEP)
if comfort:
_set_program_temperature(COMFORT, comfort)
@hnykda
Copy link
Author

hnykda commented Dec 27, 2022

Referenced in somm15/PyViCare#240 (comment)

Few notes:

  1. pyscript adds some default global variables (such as task, log, ...)
  2. it's ugly you have to have the credentials hardcoded, maybe it could be gathered from secrets somehow
  3. you may have to adjust the circuit_factory to actually get the right circuit for the right device
  4. the SLEEP is there because otherwise the API just disregarded the subsequent calls. Maybe you have to increase it, who knows, Viessman API is crap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment