A number of api calls are native to AppDaemon and will exist in any App as they are inherited through the plugin API. If the get_plugin_api()
style of declarations is used, these functions will become available via an object created by the get_ad_api()
call:
import adbase as ad
import adapi as adapi
class Test(ad.ADBase):
def initialize(self):
adbase = self.get_ad_api()
handle = self.adbase.run_in(callback, 20)
These calls are documented below.
To create apps based on just the AppDaemon base API, use some code like the following:
import adbase as ad
class MyApp(ad.ADBase):
def initialize(self):
appdaemon.adapi.ADAPI.get_state
appdaemon.adapi.ADAPI.set_state
appdaemon.adapi.ADAPI.listen_state
appdaemon.adapi.ADAPI.cancel_listen_state
appdaemon.adapi.ADAPI.info_listen_state
appdaemon.adapi.ADAPI.parse_utc_string
appdaemon.adapi.ADAPI.get_tz_offset
appdaemon.adapi.ADAPI.convert_utc
appdaemon.adapi.ADAPI.sun_up
appdaemon.adapi.ADAPI.sun_down
appdaemon.adapi.ADAPI.parse_time
appdaemon.adapi.ADAPI.parse_datetime
appdaemon.adapi.ADAPI.get_now
appdaemon.adapi.ADAPI.get_now_ts
appdaemon.adapi.ADAPI.now_is_between
appdaemon.adapi.ADAPI.sunrise
appdaemon.adapi.ADAPI.sunset
appdaemon.adapi.ADAPI.time
appdaemon.adapi.ADAPI.datetime
appdaemon.adapi.ADAPI.date
appdaemon.adapi.ADAPI.get_timezone
appdaemon.adapi.ADAPI.cancel_timer
appdaemon.adapi.ADAPI.info_timer
appdaemon.adapi.ADAPI.run_in
appdaemon.adapi.ADAPI.run_once
appdaemon.adapi.ADAPI.run_at
appdaemon.adapi.ADAPI.run_daily
appdaemon.adapi.ADAPI.run_hourly
appdaemon.adapi.ADAPI.run_minutely
appdaemon.adapi.ADAPI.run_every
appdaemon.adapi.ADAPI.run_at_sunset
appdaemon.adapi.ADAPI.run_at_sunrise
appdaemon.adapi.ADAPI.register_service
appdaemon.adapi.ADAPI.list_services
appdaemon.adapi.ADAPI.call_service
appdaemon.adapi.ADAPI.run_sequence
appdaemon.adapi.ADAPI.cancel_sequence
appdaemon.adapi.ADAPI.listen_event
appdaemon.adapi.ADAPI.cancel_listen_event
appdaemon.adapi.ADAPI.info_listen_event
appdaemon.adapi.ADAPI.fire_event
appdaemon.adapi.ADAPI.log
appdaemon.adapi.ADAPI.error
appdaemon.adapi.ADAPI.listen_log
appdaemon.adapi.ADAPI.cancel_listen_log
appdaemon.adapi.ADAPI.get_main_log
appdaemon.adapi.ADAPI.get_error_log
appdaemon.adapi.ADAPI.get_user_log
appdaemon.adapi.ADAPI.set_log_level
appdaemon.adapi.ADAPI.set_error_level
appdaemon.adapi.ADAPI.dash_navigate
appdaemon.adapi.ADAPI.set_namespace
appdaemon.adapi.ADAPI.get_namespace
appdaemon.adapi.ADAPI.list_namespaces
appdaemon.adapi.ADAPI.save_namespace
Note: A service call always uses the app's default namespace. Although namespaces allow a new and easy way to work with multiple namespaces from within a single App, it is essential to understand how they work before using them in service's calls. See the section on namespaces for a detailed description.
AppDaemon has a predefined list of namespaces that can be used only for particular services. Listed below are the services by namespace.
admin
namespace only:
app/create
Used to create a new app. For this service to be used, the module must be existing and provided with the module's class. If no app name is given, the module name will be used as the app's name by default. The service call also accepts app_file
if wanting to create the app within a certain yaml file. Or app_dir
, if wanting the created app's yaml file within a certain directory. If no file or directory is given, by default the app yaml file will be generated in a directory ad_apps
, using the app's name. It should be noted that app_dir
and app_file
when specified, will be created within the AD's apps directory.
self.adbase.call_service("app/create", **data)
app/edit
Used to edit an existing app. This way, an app' args can be edited in realtime with new args
>>> self.call_service("app/edit", app="light_app", module="light_system", namespace="admin")
app/remove
Used to remove an existing app. This way, an existing app will be deleted. If the app is the last app in the yaml
file, the file will be delected
>>> self.call_service("app/remove", app="light_app", namespace="admin")
app/start
Starts an app that has been terminated. The app name arg is required.
>>> self.call_service("app/start", app="light_app", namespace="admin")
app/stop
Stops a running app. The app name arg is required.
>>> self.call_service("app/stop", app="light_app", namespace="admin")
app/restart
Restarts a running app. This service basically stops and starts the app. The app name arg is required.
>>> self.call_service("app/restart", app="light_app", namespace="admin")
app/reload
Checks for an app update. Useful if AD is running in production mode, and app changes need to be checked and loaded.
>>> self.call_service("app/reload", namespace="admin")
app/enable
Enables a disabled app, so it can be loaded by AD.
>>> self.call_service("app/enable", app="living_room_app", namespace="admin")
app/disable
Disables an enabled app, so it cannot be loaded by AD. This service call is persistent, so even if AD restarts, the app will not be restarted
>>> self.call_service("app/enable", app="living_room_app", namespace="admin")
production_mode/set
Sets the production mode AD is running on. The value of the mode arg has to be `True` or `False`.
>>> self.call_service("production_mode/set", mode=True, namespace="appdaemon")
All namespaces except appdaemon
, global
, and admin
:
state/add_entity
Adds an existing entity to the required namespace.
>>> self.call_service("state/set", entity_id="sensor.test", state="on", attributes={"friendly_name" : "Sensor Test"}, namespace="default")
state/set
Sets the state of an entity. This service allows any key-worded args to define what entity's values need to be set.
>>> self.call_service("state/set", entity_id="sensor.test", state="on", attributes={"friendly_name" : "Sensor Test"}, namespace="default")
state/remove_entity
Removes an existing entity from the required namespace.
>>> self.call_service("state/remove_entity", entity_id="sensor.test"}, namespace="default")
All namespaces except appdaemon
:
event/fire
Fires an event within the specified namespace. The event arg is required.
>>> self.call_service("event/fire", event="test_event", entity_id="appdaemon.test", namespace="hass")
rules
namespace only:
sequence/run
Runs a predefined sequence. The entity_id arg with the sequence full-qualified entity name is required.
>>> self.call_service("sequence/run", entity_id ="sequence.christmas_lights", namespace="rules")
appdaemon.adapi.ADAPI.set_app_pin
appdaemon.adapi.ADAPI.get_app_pin
appdaemon.adapi.ADAPI.set_pin_thread
appdaemon.adapi.ADAPI.get_pin_thread
appdaemon.adapi.ADAPI.create_task
appdaemon.adapi.ADAPI.run_in_executor
appdaemon.adapi.ADAPI.sleep
appdaemon.adapi.ADAPI.get_app
appdaemon.adapi.ADAPI.get_ad_version
appdaemon.adapi.ADAPI.entity_exists
appdaemon.adapi.ADAPI.split_entity
appdaemon.adapi.ADAPI.remove_entity
appdaemon.adapi.ADAPI.split_device_list
appdaemon.adapi.ADAPI.get_plugin_config
appdaemon.adapi.ADAPI.friendly_name
appdaemon.adapi.ADAPI.set_production_mode
appdaemon.adapi.ADAPI.start_app
appdaemon.adapi.ADAPI.stop_app
appdaemon.adapi.ADAPI.restart_app
appdaemon.adapi.ADAPI.reload_apps
Dialogflow ~~~~~
appdaemon.adapi.ADAPI.get_dialogflow_intent
appdaemon.adapi.ADAPI.get_dialogflow_slot_value
appdaemon.adapi.ADAPI.format_dialogflow_response
appdaemon.adapi.ADAPI.get_alexa_intent
appdaemon.adapi.ADAPI.get_alexa_slot_value
appdaemon.adapi.ADAPI.format_alexa_response
appdaemon.adapi.ADAPI.get_alexa_error
appdaemon.adapi.ADAPI.register_endpoint
appdaemon.adapi.ADAPI.unregister_endpoint
WebRoute ~~~
appdaemon.adapi.ADAPI.register_route
appdaemon.adapi.ADAPI.unregister_route
appdaemon.adapi.ADAPI.run_in_thread
appdaemon.adapi.ADAPI.submit_to_executor
appdaemon.adapi.ADAPI.get_thread_info
appdaemon.adapi.ADAPI.get_scheduler_entries
appdaemon.adapi.ADAPI.get_callback_entries
appdaemon.adapi.ADAPI.depends_on_module