How to use the appdaemon.appapi function in appdaemon

To help you get started, we’ve selected a few appdaemon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github azogue / hass_appdaemon_apps / conf / apps / family_tracker.py View on Github external
Harcoded custom logic for controlling HA with feedback from these actions.

"""
from datetime import datetime as dt
from dateutil.parser import parse

import appdaemon.appapi as appapi
import appdaemon.conf as conf


# DELAY_TO_SET_DEFAULT_TARGET = 1800  # sec
DELAY_TO_SET_DEFAULT_TARGET = 120  # sec


# noinspection PyClassHasNoInit
class FamilyTracker(appapi.AppDaemon):
    """Family Tracker."""

    _tracking_state = None
    _telegram_targets = None
    _notifier = None
    _timer_update_target = None
    _base_url = None
    _anybody_home = None

    def initialize(self):
        """AppDaemon required method for app init."""
        config = dict(self.config['AppDaemon'])
        _chatids = [int(x) for x in config.get('bot_chatids').split(',')]
        self._notifier = config.get('notifier').replace('.', '/')
        self._base_url = config.get('base_url').replace('.', '/')
        self._anybody_home = False
github azogue / hass_appdaemon_apps / conf / apps / ios_events_listener.py View on Github external
"yellow": [0.4925, 0.4833], "green": [0.4084, 0.5168], "violet": [0.3425, 0.1383]}

DEFAULT_NOTIF_MASK = "Recibido en {:%d/%m/%y %H:%M:%S} desde {}. Raw: {}."
NOTIF_MASK_ALARM_ON = "ALARMA CONECTADA en {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_ALARM_HOME = "Vigilancia conectada en casa a las {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_ALARM_SILENT = "Se silencia la alarma a las {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_ALARM_RESET = "Se ignora el estado de alarma, reset a las {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_ALARM_OFF = "ALARMA DESCONECTADA en {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_TOGGLE_AMB = "Cambio en modo Ambilight{:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_TOGGLE_AMB_CONF = "Cambio en configuración de Ambilight (# de bombillas) {:%d/%m/%y %H:%M:%S}, desde '{}'."
NOTIF_MASK_POSTPONE_ALARMCLOCK = "{:%d/%m/%y %H:%M:%S}: Postponer despertador (desde '{}')."
NOTIF_MASK_LAST_VALIDATION = "Last validation: {:%d/%m/%y %H:%M:%S}, from '{}'."


# noinspection PyClassHasNoInit
class EventListener(appapi.AppDaemon):
    """Event listener for ios.notification_action_fired."""

    _config = None
    _lights_notif = None
    _lights_notif_state = None
    _lights_notif_state_attrs = None
    _notifier = None

    # Family Tracker
    _devs_to_track = None
    _tracking_state = None

    # Alarm state
    _alarm_state = False

    # _sended_notifications = {}
github azogue / hass_appdaemon_apps / conf / apps / main_alarm.py View on Github external
This little app has to control the alarm state of the house, sending notifications on alert & more.
This is a work in progress...

"""
import appdaemon.appapi as appapi
from itertools import cycle


LOG_LEVEL = 'DEBUG'
# LOG_LEVEL = 'INFO'
DEFAULT_ALARM_COLORS = [(255, 0, 0), (50, 0, 255)]


# noinspection PyClassHasNoInit
class MyAlarm(appapi.AppDaemon):
    """App for handle the main intrusion alarm."""
    pir = None
    camera = None
    light_notify = None
    alarm_lights = None
    notifier = None
    manual_trigger = None

    alarm_state = False
    camera_state = False
    cycle_colors = cycle(DEFAULT_ALARM_COLORS)

    def initialize(self):
        """AppDaemon required method for app init."""
        self.pir = self.args.get('pir')
        self.camera = self.args.get('camera', None)
github ReneTode / My-AppDaemon / apps / foscam_app_v2 / homeassistant0.54 / foscam.py View on Github external
#                                                                                         #
#  args:                                                                                  #
#  see the readme on                                                                      #
#  https://github.com/ReneTode/My-AppDaemon/tree/master/apps/foscam_app_v2                #
#                                                                                         #
###########################################################################################

import appdaemon.appapi as appapi
import datetime
import untangle
from urllib.request import urlopen
import urllib.request
from socket import timeout
import time

class foscam(appapi.AppDaemon):

  def initialize(self):
    runtime = datetime.datetime.now() + datetime.timedelta(seconds=5)
    self.loglevels = {
        "CRITICAL": 50,
        "ERROR": 40,
        "WARNING": 30,
        "INFO": 20,
        "DEBUG": 10,
        "NOTSET": 0
    }
    self.logsettings = self.args["logsettings"]
    if "loglevel" in self.logsettings:
      self.loglevel = self.logsettings["loglevel"]
    else:
      self.loglevel = "INFO"
github ReneTode / My-AppDaemon / lightschedule / lights.py View on Github external
def set_lights_off(self, kwargs):
    #self.log(kwargs["switch"] + " uitgedaan")
    self.light_action_log("automatisch uit",kwargs["switch"],"off")
    self.turn_off(kwargs["switch"])

  def light_action_log(self,description, entity1, value1):
    runtime = datetime.datetime.now().strftime("%d-%m-%Y %H:%M:%S")
    try:
      log = open(self.args["logfile"], 'a')
      log.write(runtime + ";" + description + ";" + entity1 + ";" + value1 + "\n")
      log.close()
    except:
      self.log("VERLICHTINGSLOGFILE NIET BEREIKBAAR!!")

class alllightsout(appapi.AppDaemon):

  def initialize(self):
    self.listen_state(self.lights_out,self.args["lightswitch"], new = "on")

  def lights_out(self, entity, attribute, old, new, kwargs):
    self.log("alle verlichting uit","INFO")
    
    for counter in range(1,int(self.args["total_switches"])+1):
      if self.get_state(self.args["switch"+str(counter)])=='off':
        self.turn_on (self.args["switch"+str(counter)])
        time.sleep(2)
      self.turn_off(self.args["switch"+str(counter)])      
      time.sleep(2)
    self.turn_off(self.args["lightswitch"])
    self.light_action_log("alle verlichting","","off")
github ReneTode / My-AppDaemon / sound / sound.py View on Github external
#
#  to put music in your soundlist (or sounds)
#
###########################################################################################


import appdaemon.appapi as appapi
import datetime
import tempfile
import subprocess
import os
import time as timelib
from gtts import gTTS
import threading

class sound(appapi.AppDaemon):

  def initialize(self):
############################################
# setting variabele startvalues
############################################
    self.soundlog("============================================================")
    self.soundlog("initialize; started soundfunctions")
    self.lasttime = datetime.datetime.now()
    self.totaltime = datetime.timedelta(seconds=1)
    self.loopamount = 1
    self.minutesrunning = 0
    self.restarts = 0
    self.lastsound = datetime.datetime.now()
    runtime = datetime.datetime.now() + datetime.timedelta(minutes=15)
    startdelay = 30
    self.maindelay = 2
github azogue / hass_appdaemon_apps / conf / apps / morning_alarm_clock.py View on Github external
"inline_keyboard": TELEGRAM_INLINE_KEYBOARD_ALARMCLOCK,
                "disable_notification": False}
    return data_msg


def _weekday(str_wday):
    str_wday = str_wday.lower().rstrip().lstrip()
    if str_wday in WEEKDAYS_DICT:
        return WEEKDAYS_DICT[str_wday]
    print('Error parsing weekday: "{}" -> mon,tue,wed,thu,fri,sat,sun'
          .format(str_wday))
    return -1


# noinspection PyClassHasNoInit
class AlarmClock(appapi.AppDaemon):
    """App for run a complex morning alarm.

    With sunrise light simulation and launching of a Kodi add-on,
    after waking up the home-cinema system,
    or a Modipy instance with a streaming audio."""

    _alarm_time_sensor = None
    _delta_time_postponer_sec = None
    _max_volume = None
    _volume_ramp_sec = None
    _weekdays_alarm = None
    _notifier = None
    _transit_time = None
    _phases_sunrise = []
    _tz = None
    _lights_alarm = None
github aneisch / home-assistant-config / extras / appdaemon / apps / door_notify.py View on Github external
import appdaemon.appapi as appapi


class FrontDoorNotify(appapi.AppDaemon):

  def initialize(self):
    if "door_sensor" in self.args:
      for sensor in self.split_device_list(self.args["door_sensor"]):
        self.listen_state(self.state_change, sensor)

  def state_change(self, entity, attribute, old, new, kwargs):
    if entity == "sensor.front_door_status" and new == "Open" and self.get_state("input_boolean.door_notify") == "on":
      self.call_service("notify/notify_push_android", title = "Home Assistant", message = "Front Door Opened")
    elif entity == "sensor.back_door_status" and new == "Open" and self.get_state("input_boolean.door_notify") == "on":
      self.call_service("notify/notify_push_android", title = "Home Assistant", message = "Back Door Opened")
github azogue / hass_appdaemon_apps / conf / apps / publish_states_in_master.py View on Github external
"""
import appdaemon.appapi as appapi
import homeassistant.remote as remote
import datetime as dt
from dateutil.parser import parse
from math import ceil


LOG_LEVEL = 'INFO'
DEFAULT_SUFFIX = '_slave'
DEFAULT_RAWBS_SECS_OFF = 10


# noinspection PyClassHasNoInit
class SlavePublisher(appapi.AppDaemon):
    """SlavePublisher.

    AppDaemon Class for setting states
    from one HASS instance (main) in Another (remote).
    Valid for binary_sensors and sensors."""

    _hass_master_url = None
    _hass_master_key = None
    _hass_master_port = None
    _master_ha_api = None

    _sufix = None
    _sensor_updates = None

    _raw_sensors = None
    _raw_sensors_sufix = None
github ReneTode / My-AppDaemon / custom_css / lcars / stardate / stardate.py View on Github external
###########################################################################################
#                                                                                         #
#  Rene Tode ( hass@reot.org )                                                            #
#  2017/11/06 Germany                                                                     #
#                                                                                         #
###########################################################################################

import appdaemon.appapi as appapi
import datetime

class stardate(appapi.AppDaemon):

  def initialize(self):
    self.run_at_sunrise(self.set_stardate)
    self.set_stardate(self)

  def set_stardate(self, kwargs):
    century="1"
    today = datetime.datetime.now()
    startdate = datetime.datetime(2000, 1, 1, 0, 0)
    daysgone=today-startdate   
    days_gone = round((daysgone.days/10)*2.73785,1)
    self.log("STARDATE:"+ century + str(days_gone))
    self.set_state("sensor.stardate",state="STARDATE:"+ century + str(days_gone))