mirror of
https://github.com/home-assistant/home-assistant.io.git
synced 2025-07-23 01:06:52 +00:00
Update appdaemon.markdown
This commit is contained in:
parent
2270f929e5
commit
7cd587a1df
@ -35,7 +35,7 @@ The best way to show what AppDaemon does is through a few simple examples.
|
||||
Let's start with a simple App to turn a light on every night at sunset and off every morning at sunrise. Every App when first started will have its `initialize()` function called, which gives it a chance to register a callback for AppDaemons's scheduler for a specific time. In this case, we are using `run_at_sunrise()` and `run_at_sunset()` to register two separate callbacks. The argument `0` is the number of seconds offset from sunrise or sunset and can be negative or positive. For complex intervals, it can be convenient to use Python's `datetime.timedelta` class for calculations. When sunrise or sunset occurs, the appropriate callback function, `sunrise_cb()` or `sunset_cb()`, is called, which then makes a call to Home Assistant to turn the porch light on or off by activating a scene. The variables `args["on_scene"]` and `args["off_scene"]` are passed through from the configuration of this particular App, and the same code could be reused to activate completely different scenes in a different version of the App.
|
||||
|
||||
```python
|
||||
import homeassistant.appapi as appapi
|
||||
import appdaemon.appapi as appapi
|
||||
|
||||
class OutsideLights(appapi.AppDaemon):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user