Hi,
i’m trying to learn python and AppDeamon but i have hit a wall.
For learning purposes i removed all the fancy bits from the motion light exemple and got this:
import appdaemon.plugins.hass.hassapi as hass
class GarageRorelsevakt(hass.Hass):
def initialize(self):
self.handle = None
self.listen_state(self.motion,"switch.garage_rorelsevakt")
def motion(self, entity, attribute, old, new, kwargs):
if new == "on":
self.turn_on("switch.garage_belysning")
delay = "120"
self.cancel_timer(self.handle)
self.handle = self.run_in(self.light_off, delay)
def light_off(self, kwargs):
self.turn_off("switch.garage_belysning")
def cancel(self):
self.cancel_timer(self.handle)
I get what it does but not how.
For this to work:
self.cancel_timer(self.handle)
Shouldn’t
self.listen_state(self.motion,"switch.garage_rorelsevakt")
Be
handle = self.listen_state(self.motion,"switch.garage_rorelsevakt")
And to be honest i don’t really get this either
self.handle = self.run_in(self.light_off, delay)
Any help is mostly appreciated.