Last active
October 29, 2023 12:30
-
-
Save hnykda/03c3b7c3cab328223651e58bc6c7e899 to your computer and use it in GitHub Desktop.
Home Assistant PyScript setting temperatures via pyvicare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Referenced in somm15/PyViCare#240 (comment)
Few notes:
pyscript
adds some default global variables (such astask
,log
, ...)circuit_factory
to actually get the right circuit for the right deviceSLEEP
is there because otherwise the API just disregarded the subsequent calls. Maybe you have to increase it, who knows, Viessman API is crap.