Skip to content

Commit

Permalink
ha - blinds define weekday open time and guest mdoe
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 13, 2024
1 parent 2838ede commit 64b2cc6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
39 changes: 37 additions & 2 deletions ph4ha/apps/blinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,24 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.blinds = None
self.weekdays_open_time = None
self.guest_mode: bool = False
self.field_weekdays_open_time = None
self.field_guest_mode = None

def initialize(self):
self.blinds = {x["name"]: x for x in self.args["blinds"]}
self.weekdays_open_time = self.get_state(self.args["weekdays_open_time"])
self.field_weekdays_open_time = self.args["weekdays_open_time"]
self.field_guest_mode = self.args["guest_mode_input"]

# Set initial blind open time
self.update_blind_open_time()
self.update_blind_guest_mode()

# Listen for changes to the input_datetime entity
self.listen_state(self.update_blind_open_time, self.field_weekdays_open_time)
self.listen_state(self.update_blind_guest_mode, self.field_guest_mode)

# Listen to scene changes
self.listen_event(self.scene_activated, "call_service", domain="scene", service="turn_on")

# # Schedule for weekdays
Expand All @@ -44,7 +57,29 @@ def initialize(self):
# # Schedule to lower and tilt blinds 1 hour after sunset
# self.run_at_sunset(self.lower_and_tilt_blinds, offset=3600) # offset in seconds

self.log(f"initialized, {self.weekdays_open_time=}")
self.log(f"initialized, {self.weekdays_open_time=}, {self.guest_mode=}")

def update_blind_open_time(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
weekday_blind_open_time = self.get_state(self.field_weekdays_open_time)

if weekday_blind_open_time is None:
self.log("Failed to retrieve weekday_blind_open_time state.")
else:
self.log(f"Weekday Blind Open Time updated: {weekday_blind_open_time}")

self.weekdays_open_time = self.parse_time(weekday_blind_open_time)
self.log(f"{self.weekdays_open_time=}")

# Cancel any previously scheduled runs to avoid duplication
# self.cancel_timers()

# Schedule the blind open event at the new time
# self.run_daily(self.open_blinds, self.weekdays_open_time)

def update_blind_guest_mode(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
guest_mode = self.get_state(self.field_guest_mode)
self.guest_mode = guest_mode == "on"
self.log(f"{self.guest_mode=}")

def scene_activated(self, event_name, data, kwargs):
# Extract the scene ID or entity ID
Expand Down
11 changes: 10 additions & 1 deletion ph4ha/config-ha/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ input_text:

input_boolean:
hallway_switch_updated_by_webhook:
name: "Updated by Webhook"
name: "Hallway Updated by Webhook"
initial: off
blinds_guest_mode:
name: "Blinds Guest Mode"
initial: false

input_datetime:
blinds_weekday_open_time:
name: Blinds Weekday Open Time
has_date: false
has_time: true

switch:
- platform: template
Expand Down
4 changes: 2 additions & 2 deletions ph4ha/config/apps.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ blinds:
ip_address: "192.168.0.12"
ha_name: "shellyplus2pm-zzz"
password: !secret shelly_blinds_study
weekdays_open_time: "input_text.weekday_blind_open_time"
guest_mode_input: "input_text.weekday_blind_open_time"
weekdays_open_time: "input_datetime.blinds_weekday_open_time"
guest_mode_input: "input_boolean.blinds_guest_mode"
stop_automation_input: "input_text.weekday_blind_open_time"
morning_routine_time_input: "input_text.weekday_blind_open_time"
full_open_time_input: "input_text.weekday_blind_open_time"
Expand Down

0 comments on commit 64b2cc6

Please sign in to comment.