diff --git a/atom.xml b/atom.xml index e6f44eef0a..4bd7c8d46a 100644 --- a/atom.xml +++ b/atom.xml @@ -4,7 +4,7 @@
The best way to show what AppDaemon does is through a few simple examples.
Lets 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 2 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.
import homeassistant.appapi as appapi
+Lets start with a simple App to turn a light on every night fifteen
+minutes (900 seconds) before 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 2 separate
+callbacks. The named argument offset
is the number of seconds offset
+from sunrise or sunset and can be negative or positive (it defaults to
+zero). For complex intervals it can be convenient to use Python’s
+datetime.timedelta
class for calculations. In the example below,
+when sunrise or just before sunset occurs, the appropriate callback
+function, sunrise_cb()
or before_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.
+ import appdaemon.plugins.hass.hassapi as hass
-class OutsideLights(appapi.AppDaemon):
+ class OutsideLights(hass.Hass):
- def initialize(self):
- self.run_at_sunrise(self.sunrise_cb, 0)
- self.run_at_sunset(self.sunset_cb, 0)
-
- def sunrise_cb(self, kwargs):
- self.turn_on(self.args["off_scene"])
+ def initialize(self):
+ self.run_at_sunrise(self.sunrise_cb)
+ self.run_at_sunset(self.before_sunset_cb, offset=-900)
+
+ def sunrise_cb(self, kwargs):
+ self.turn_on(self.args["off_scene"])
- def sunset_cb(self, kwargs):
- self.turn_on(self.args["on_scene"])
+ def before_sunset_cb(self, kwargs):
+ self.turn_on(self.args["on_scene"])
diff --git a/sitemap.xml b/sitemap.xml
index d9fe74b637..1fb46bc883 100644
--- a/sitemap.xml
+++ b/sitemap.xml
@@ -4090,7 +4090,7 @@
https://home-assistant.io/components/switch.hook/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/cookbook/automation_for_rainy_days/
@@ -4778,131 +4778,131 @@
https://home-assistant.io/docs/autostart/init.d/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/api/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/configuration/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/example_apps/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/installation/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/operation/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/reboot/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/running/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/tutorial/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/updating/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/appdaemon/windows/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/certificates/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/hadashboard/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/hass-configurator/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/ios/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/nginx/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/notebooks/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/scenegen/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/ecosystem/synology/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/benchmark/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/check_config/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/credstash/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/db_migrator/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/dev-tools/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/ensure_config/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/hass/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/influxdb_import/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/influxdb_migrator/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/keyring/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/docs/tools/scripts/
-2018-03-05T22:27:56+00:00
+2018-03-06T07:56:12+00:00
https://home-assistant.io/faq/after-upgrading/
@@ -6098,62 +6098,62 @@
https://home-assistant.io/demo/frontend.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/index.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-dev-event.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-dev-info.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-dev-service.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-dev-state.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-dev-template.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-history.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-iframe.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-logbook.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/demo/panels/ha-panel-map.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/googlef4f3693c209fe788.html
-2018-03-05T22:26:39+00:00
+2018-03-06T07:55:23+00:00
https://home-assistant.io/static/fonts/roboto/DESCRIPTION.en_us.html
-2018-03-05T22:26:40+00:00
+2018-03-06T07:55:24+00:00
https://home-assistant.io/static/fonts/robotomono/DESCRIPTION.en_us.html
-2018-03-05T22:26:40+00:00
+2018-03-06T07:55:24+00:00
https://home-assistant.io/static/mdi-demo.html
-2018-03-05T22:26:40+00:00
+2018-03-06T07:55:24+00:00