Skip to content

Instantly share code, notes, and snippets.

@ALERTua
Created July 16, 2024 16:24
Show Gist options
  • Save ALERTua/e4d8436d3ed240d27ba163f863a001b4 to your computer and use it in GitHub Desktop.
Save ALERTua/e4d8436d3ed240d27ba163f863a001b4 to your computer and use it in GitHub Desktop.
ha pyscript water heater away mode toggle via pyoverkiz
import datetime
from pyoverkiz.const import SUPPORTED_SERVERS
from pyoverkiz.client import OverkizClient
from pyoverkiz.enums import Server
from pyoverkiz.models import Command
USERNAME = "overkiz_username"
PASSWORD = "overkiz_password"
@pyscript_compile
async def _water_heater_away(turn_away_on=True):
async with OverkizClient(USERNAME, PASSWORD, server=SUPPORTED_SERVERS[Server.ATLANTIC_COZYTOUCH]) as client:
try:
await client.login()
except Exception as exception: # pylint: disable=broad-except
return
devices = await client.get_devices()
modbus = [_ for _ in devices if 'modbuslink://' in _.device_url][0]
device_url = modbus.device_url
if turn_away_on:
now = datetime.datetime.now()
future = now + datetime.timedelta(weeks=10)
await client.execute_command(device_url, Command('setAbsenceStartDate', [{'month': now.month, 'hour': now.hour, 'year': now.year, 'weekday': now.weekday(), 'day': now.day, 'minute': now.minute, 'second': now.second}]))
await client.execute_command(device_url, Command('setAbsenceEndDate', [{'month': future.month, 'hour': future.hour, 'year': future.year, 'weekday': future.weekday(), 'day': future.day, 'minute': future.minute, 'second': future.second}]))
await client.execute_command(device_url, Command('setAbsenceMode', ['prog']))
else:
cmd = Command('setAbsenceMode', ['off'])
result = await client.execute_command(device_url, cmd)
return result
# https://hacs-pyscript.readthedocs.io/en/stable/reference.html#service-service-name-supports-response-none
@service(supports_response="none") # none, optional, only
def water_heater_away(turn_away_on=True):
"""yaml
name: Water Heater Away Mode Switch Service
description: Water Heater Away Mode Switch Service
fields:
turn_away_on:
description: true turns the away mode on, false turns it off
example: true
required: true
selector:
boolean:
"""
log.info(f"{__name__} Toggling away mode to {turn_away_on}")
result = _water_heater_away(turn_away_on)
log.info(f"{__name__} result: {result}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment