Skip to content

Commit

Permalink
ha - add dusk offset
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 22, 2024
1 parent ae9b7e5 commit 8b9cdb3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
18 changes: 17 additions & 1 deletion ph4ha/apps/blinds.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ def __init__(self, *args, **kwargs):
self.automation_enabled: bool = True
self.bedroom_automation_enabled: bool = True
self.next_dusk_time = None
self.dusk_offset = None

self.field_weekdays_open_time = None
self.field_guest_mode = None
self.field_automation_enabled = None
self.field_guest_weekdays_open_time = None
self.field_bedroom_automation_enabled = None
self.field_dusk_offset = None
self.field_weekend_open_time = None
self.field_sunset_offset_time = None
self.field_full_open_time = None
Expand All @@ -57,7 +59,8 @@ def initialize(self):
self.field_guest_weekdays_open_time = self.args["guest_weekdays_open_time_input"]
self.field_guest_mode = self.args["guest_mode_input"]
self.field_automation_enabled = self.args["automation_enabled_input"]
self.field_bedroom_automation_enabled = self.args["bedroom_automation_enabled"]
self.field_bedroom_automation_enabled = self.args["bedroom_automation_enabled_input"]
self.field_dusk_offset = self.args["dusk_offset_input"]
# self.field_weekend_open_time = self.args["weekend_open_time_input"]
# self.field_sunset_offset_time = self.args["sunset_offset_time_input"]
# self.field_full_open_time = self.args["full_open_time_input"]
Expand All @@ -69,6 +72,7 @@ def initialize(self):
self.update_blind_guest_mode()
self.update_blind_automation_enabled()
self.update_blind_bedroom_automation_enabled()
self.update_blind_dusk_offset()
self.update_dusk_time()

# Listen for changes to the input_datetime entity
Expand All @@ -77,6 +81,7 @@ def initialize(self):
self.listen_state(self.update_blind_guest_mode, self.field_guest_mode)
self.listen_state(self.update_blind_automation_enabled, self.field_automation_enabled)
self.listen_state(self.update_blind_bedroom_automation_enabled, self.field_bedroom_automation_enabled)
self.listen_state(self.update_blind_dusk_offset, self.field_dusk_offset)

# Listen to scene changes
self.listen_event(self.scene_activated, "call_service", domain="scene", service="turn_on")
Expand Down Expand Up @@ -162,6 +167,17 @@ def update_blind_bedroom_automation_enabled(self, entity=None, attribute=None, o
self.bedroom_automation_enabled = self.to_bool(self.get_state(self.field_guest_mode))
self.log(f"{self.bedroom_automation_enabled=}")

def update_blind_dusk_offset(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
self.log(f"on_update: {entity=}, {attribute=}, {old=}, {new=}, {kwargs=}")
value = self.get_state(self.field_dusk_offset)

if value is None:
self.log("Failed to retrieve field_dusk_offset state.")
return

self.dusk_offset = self.parse_time(value)
self.log(f"{self.dusk_offset=}")

def scene_activated(self, event_name, data, kwargs):
# Extract the scene ID or entity ID
scene_id = data.get("service_data", {}).get("entity_id")
Expand Down
5 changes: 5 additions & 0 deletions ph4ha/config-ha/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ input_datetime:
name: Blinds Guest Weekday Open Time
has_date: false
has_time: true
blinds_dusk_offset:
name: Blinds Dusk offset
has_date: false
has_time: true
initial: "12:00"

switch:
- platform: template
Expand Down
3 changes: 2 additions & 1 deletion ph4ha/config/apps.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ blinds:
guest_mode_input: "input_boolean.blinds_guest_mode"
guest_weekdays_open_time_input: "input_datetime.blinds_weekday_guest_open_time"
automation_enabled_input: "input_boolean.blinds_automation_enabled"
bedroom_automation_enabled: "input_boolean.blinds_bedroom_automation_enabled"
bedroom_automation_enabled_input: "input_boolean.blinds_bedroom_automation_enabled"
dusk_offset_input: "input_datetime.blinds_dusk_offset"

full_open_time_input: "input_text.weekday_blind_open_time"
full_close_time_input: "input_text.weekday_blind_open_time"
Expand Down

0 comments on commit 8b9cdb3

Please sign in to comment.