alexmo
(Alex Moshilov)
October 11, 2019, 7:20pm
1
Hello,
I tried to search for something like what I’m looking to do, unsuccessfully.
Just wants to turn a light off after a period of time (let’s say 10 sec).
The following is my code:
apps.yaml
Turn_Off_Laundry_Lights:
module: lights
class: TurnOffLights
lights.py
import appdaemon.plugins.hass.hassapi as hass
#
# Turn Off Lights App
#
# Args:
#
class TurnOffLights(hass.Hass):
def initialize(self):
# Listen for a state change involving light.office1 changing to state on and remaining on for a minute
# Trigger the delay immediately if the light is already on
self.listen_state(self.light_off_from_on,"switch.47023800a4cf12b15cac_3",new='on', old='off')
def light_off_from_on(self, entity, attribute, old, new, kwargs):
self.run_in(self.light_off, 10)
def light_off(self):
self.turn_off("switch.47023800a4cf12b15cac_3")
petro
(Petro)
October 11, 2019, 7:24pm
2
Try this.
self.run_in(self.light_off, seconds=10)
Although, yours should work. Your listener probably needs entity=.
self.listen_state(self.light_off_from_on, entity="switch.47023800a4cf12b15cac_3", new='on', old='off')
alexmo
(Alex Moshilov)
October 11, 2019, 7:37pm
3
Thanks, but still not working
petro
(Petro)
October 11, 2019, 8:14pm
5
just noticed that your missing the required kwargs argument for callbacks
def light_off(self, kwargs):
self.turn_off("switch.47023800a4cf12b15cac_3")
alexmo
(Alex Moshilov)
October 11, 2019, 8:38pm
6
Thanks !!
It’s working now.
As for log file… where should I find the errors/info related to:
Appdaemon ?
Python syntax errors ?
In the Home Assistant log or here /config/appdaemon/info.log
The following is what I set in AppDaemon.yaml file:
log:
logfile: /config/appdaemon/info.log
errorfile: /config/appdaemon/info.log
petro
(Petro)
October 11, 2019, 8:44pm
7
alexmo:
Appdaemon ?
Python syntax errors ?
appdaemon info is in logfile
python errors will show up in error file.
alexmo
(Alex Moshilov)
October 11, 2019, 9:05pm
8
Thank you very much Petro.
If I write something like that , the “Hello from AppDaemon” should appear in logfile: /config/appdaemon/info.log ?
class HelloWorld(hass.Hass):
def initialize(self):
self.log("Hello from AppDaemon")
Yes.
Why don’t you just try it?