AppDaemon / appdaemon

:page_facing_up: Python Apps for Home Automation
Other
836 stars 418 forks source link

constrain_person not working #1437

Closed aneisch closed 1 year ago

aneisch commented 2 years ago

I'm trying to constrain my callbacks based on person presence but it is not working. I don't think I'm doing anything wrong because both constrain_presence and constrain_input_boolean are working as expected.

My app config:

Indoor Light Automation Sunset:
  module: entity_timer
  class: Timer
  constrain_person: anyone
  time_on: sunset - 00:20:00
  entities: light.andrew_desk_lamp
  brightness: 255

My app:

import appdaemon.plugins.hass.hassapi as hass

class Timer(hass.Hass):
  def initialize(self):
    # DEBUG: Log whether my constraints should be applied
    if self.noone_home(person=True):
      self.log("No one home")
    if self.anyone_home(person=True):
      self.log("Anyone home")
    if self.everyone_home(person=True):
      self.log("Everyone home")

    if "time_on" in self.args:
      time_on = self.parse_time(self.args["time_on"])
      self.run_daily(self.on, time_on)

    if "time_off" in self.args:
      time_off = self.parse_time(self.args["time_off"])
      self.run_daily(self.off, time_off)

  def on(self, kwargs):
    for device in self.split_device_list(self.args["entities"]):
        self.log("Turning on " + device)
        if "brightness" in self.args and "light." in device: # API failure if we pass brightness when non-light
          self.turn_on(device, brightness = self.args["brightness"])
        else:
          self.turn_on(device)

  def off(self, kwargs):
    for device in self.split_device_list(self.args["entities"]):
        self.log("Turning off " + device)
        self.turn_off(device)

Logs:

2021-12-31 15:57:27.972737 INFO AppDaemon: App 'Indoor Light Automation Sunset' added
2021-12-31 17:16:11.000000 INFO AppDaemon: Initializing app Indoor Light Automation Sunset using class Timer from module entity_timer
2021-12-31 17:16:14.223652 INFO Indoor Light Automation Sunset: No one home
2021-12-31 17:16:23.000000 INFO Indoor Light Automation Sunset: Turning on light.andrew_desk_lamp
Odianosen25 commented 2 years ago

Hello @aneisch,

I believe the constrain_person, is only to be used with the person entity.

You sure its all setup correctly?

Regards

aneisch commented 2 years ago

https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html?highlight=constrain_person#person suggests that the configuration options are the same as constrain_presence

acockburn commented 1 year ago

Fixed in 4.0.3