From ba2d8467d08866d4953cacb8e673e9d42d16c277 Mon Sep 17 00:00:00 2001 From: Matt O Date: Fri, 13 Jan 2023 03:20:41 +0000 Subject: [PATCH 1/2] Allow value to be a string or list of strings in constrain_input_boolean and constrain_input_select --- appdaemon/plugins/hass/hassapi.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/appdaemon/plugins/hass/hassapi.py b/appdaemon/plugins/hass/hassapi.py index 097489ff7..442712239 100644 --- a/appdaemon/plugins/hass/hassapi.py +++ b/appdaemon/plugins/hass/hassapi.py @@ -310,15 +310,17 @@ def constrain_input_boolean(self, value): unconstrained = True state = self.get_state() - values = value.split(",") - if len(values) == 2: - entity = values[0] - desired_state = values[1] - else: - entity = value - desired_state = "on" - if entity in state and state[entity]["state"] != desired_state: - unconstrained = False + constraints = [value] if isinstance(value, str) else value + for constraint in constraints: + values = constraint.split(",") + if len(values) == 2: + entity = values[0] + desired_state = values[1] + else: + entity = constraint + desired_state = "on" + if entity in state and state[entity]["state"] != desired_state: + unconstrained = False return unconstrained @@ -326,10 +328,12 @@ def constrain_input_select(self, value): unconstrained = True state = self.get_state() - values = value.split(",") - entity = values.pop(0) - if entity in state and state[entity]["state"] not in values: - unconstrained = False + constraints = [value] if isinstance(value, str) else value + for constraint in constraints: + values = constraint.split(",") + entity = values.pop(0) + if entity in state and state[entity]["state"] not in values: + unconstrained = False return unconstrained From 146ce03d714ba3fefa917b13410fcae882dbdee2 Mon Sep 17 00:00:00 2001 From: Matt O Date: Wed, 1 Feb 2023 00:04:18 +0000 Subject: [PATCH 2/2] Update the documentation to include multiple constraints --- docs/APPGUIDE.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/APPGUIDE.rst b/docs/APPGUIDE.rst index 3be9e8fc3..1b3968126 100644 --- a/docs/APPGUIDE.rst +++ b/docs/APPGUIDE.rst @@ -711,6 +711,18 @@ the input\_boolean is off, use the optional state parameter by appending, class: SomeClass constrain_input_boolean: input_boolean.enable_motion_detection,off +If you want to constrain on multiple input_boolean entities, you can provide +the constraints as a yaml list + +.. code:: yaml + + some_app: + module: some_module + class: SomeClass + constrain_input_boolean: + - input_boolean.enable_motion_detection + - binary_sensor.weekend,off + input\_select ^^^^^^^^^^^^^ @@ -726,6 +738,19 @@ according to some flag, e.g., a house mode flag. # or multiple values constrain_input_select: input_select.house_mode,Day,Evening,Night + +If you want to constrain on multiple input_select entities, you can provide +the constraints as a yaml list + +.. code:: yaml + + some_app: + module: some_module + class: SomeClass + constrain_input_select: + - input_select.house_mode,Day + - sensor.day_of_week,Monday,Wednesday,Friday + presence ^^^^^^^^