Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import appdaemon.plugins.hass.hassapi as hass
"""
Notifies the specified notifier on
the days you specify.
"""
class Notify(hass.Hass):
def initialize(self):
if "countdown_entity" in self.args:
self.listen_state(self.evaluate_notice, self.args["countdown_entity"])
def evaluate_notice(self, entity, attribute, old, new, kwargs):
days_remaining = self.get_state(entity, attribute="days_remaining")
entity_friendly_name = self.get_state(entity, attribute="friendly_name")
if type(self.args["notification_days"]) == int:
notification_days = [self.args["notification_days"]]
else:
notification_days = [int(day) for day in self.args["notification_days"].split(",")]
if days_remaining in notification_days:
self.send_notice()
elif self.args["notify_overdue"] and days_remaining < 0:
from pprint import pformat
import appdaemon.plugins.hass.hassapi as hass
class MotionLights(hass.Hass):
def initialize(self):
self.handles = {}
self.timers = {}
config = self.args.get('config')
self.log('Config: {}'.format(pformat(config)), level='DEBUG')
for entry in config:
name = entry.get('name')
lights = entry.get('lights')
sensors = entry.get('sensors')
duration = entry.get('duration')
sensor_enable = entry.get('constraints', {}).get('state')
sensor_enable_state = None
self.log('{}: Use {} to control {} -> {} secs'.format(
name,
sensors,
import appdaemon.plugins.hass.hassapi as hass
import little_helpers
import ir_packets_manager
class HandleMqttFan(hass.Hass):
def initialize(self):
# initialization of the class, register handler for event listening
self.ir_send_service = little_helpers.fix_service_domain(self.args["ir_send_service"])
self.fan_type = self.args["fan_type"]
self.command = self.args['command']
if self.args['payload']:
self.fan_handler = self.listen_event(self.message_arrived, 'MQTT_MESSAGE', topic = self.args['topic'], payload = self.args['payload'], namespace = 'mqtt')
else:
self.fan_handler = self.listen_event(self.message_arrived, 'MQTT_MESSAGE', topic = self.args['topic'], namespace = 'mqtt')
def terminate(self):
self.cancel_listen_event(self.fan_handler)
def message_arrived(self, event_name, data, kwargs):
# mqtt message handler, gets the service and packet based on the room and command
except ValueError:
pass;
return(res)
def update_state (self):
self.temp = self.get_float("temp",25.0)
self.hum = self.get_float("hum",50.0)
self.calc_result = ada.temp.calc_heat_index_celsius(self.temp, self.hum)
#self.log(" CALC_T {}, (t:h) {}:{}, res:{}".format(self.args["temp"],self.temp,self.hum,self.calc_result))
self.set_state(self.args["out"],state = "{0:.1f}".format(self.calc_result))
def do_check_temperator (self,entity, attribute, old, new, kwargs):
self.update_state ()
class CTestDays(hass.Hass):
def initialize(self):
self.log("start CTestDays");
self.run_daily(self._cb_event,
self.parse_time("13:36:00"),
constrain_days=ada.schedule.day_of_week(6),
a="1",b="2")
self.run_daily(self._cb_event,
self.parse_time("13:37:00"),
constrain_days=ada.schedule.day_of_week(1),
a="3",b="4")
def _cb_event(self,kwargs):
""" kwargs include
rule=rule
##
# Automatically lock doors, turn off lights, and leave a dim night
# light on for a few seconds so you can see to get down the hallway.
##
import appdaemon.plugins.hass.hassapi as hass
from datetime import datetime, time
class GoodNight(hass.Hass):
def initialize(self):
self.setup_goodnight_listener(None)
self.setup_goodnight_master_listener(None)
# Turn off at 6:15am
self.run_daily(self.goodmorning, time(6, 30, 0))
# Nursery Door alerts
self.listen_state(self.chime, "binary_sensor.nursery_door")
def goodnight(self, entity, attribute, old, new, kwargs):
# Sanity Check
if (self.time_in_range(time(20, 00), time(23, 59), datetime.now().time()) or self.time_in_range(time(00, 00), time(5, 00), datetime.now().time())):
# try to keep both input_booleans in sync without running this automation twice
# notify_name (optional): who to notify. example: group_notifications
# use_alexa (optional): use alexa for notification. example: False
#
# Release Notes
#
# Version 1.2:
# Rename of SetThermostatOnStateChange
#
# Version 1.1:
# Use isHome as trigger
#
# Version 1.0:
# Initial Version
class SetThermostatOnStateChange(hass.Hass):
def initialize(self):
self.timer_handle_list = []
self.listen_state_handle_list = []
self.app_switch = globals.get_arg(self.args, "app_switch")
self.trigger_entity = globals.get_arg(self.args, "trigger_entity")
self.trigger_state = globals.get_arg(self.args, "trigger_state")
self.climate_entity = globals.get_arg(self.args, "climate_entity")
self.target_entity = globals.get_arg(self.args, "target_entity")
try:
self.message = globals.get_arg(self.args, "message")
except KeyError:
self.message = None
try:
self.notify_name = globals.get_arg(self.args, "notify_name")
except KeyError:
self.police_notify(msg)
else:
pass; # not needed, will be handled by another app for disconnect/connect wifi issues
#msg = "ERROR new {} or old {} state is not int " .format(new,old)
#self.police_notify(msg)
def home_cb(self, event_name, data, kwargs):
if data['enable']=='on':
self.at_home = True
else:
self.leak_ticks =0
self.at_home = False
class CFollowState(hass.Hass):
""" folow the state of a diffrent object """
#input:
#output:
def initialize(self):
self.log(" start folow app ");
self.listen_state(self.do_state_change, self.args["input"])
# sync with the state
if self.get_state(self.args["input"])=="on":
self.turn_on(self.args["output"])
else:
self.turn_off(self.args["output"])
def do_state_change (self,entity, attribute, old, new, kwargs):
if new == "on":
self.turn_on(self.args["output"])
else:
# false positives
#
# Version 1.3:
# delay and lingering_time now as args
#
# Version 1.2:
# Added app_switch
#
# Version 1.1:
# Rework without proximity
#
# Version 1.0:
# Initial Version
class LeavingZoneNotifier(hass.Hass):
def initialize(self):
self.listen_state_handle_list = []
self.timer_handle_list = []
self.app_switch = globals.get_arg(self.args, "app_switch")
self.user_name = globals.get_arg(self.args, "user_name")
self.zone = globals.get_arg(self.args, "zone")
self.notify_name = globals.get_arg(self.args, "notify_name")
self.device = globals.get_arg(self.args, "device")
# 'lingering_time' the time a user has to stay in a zone
# for this app to trigger
self.lingering_time = globals.get_arg(self.args, "lingering_time")
self.delay = globals.get_arg(self.args, "delay")
self.message = globals.get_arg(self.args, "message")
try:
#
# Version 1.2:
# Add after_sundown argument
#
# Version 1.1:
# Add ability for other apps to cancel the timer
#
# Version 1.0:
# Initial Version
SENSOR_TYPE_XIAOMI = "xiaomi"
SENSOR_TYPE_ZIGBEE2MQTT = "zigbee2mqtt"
SENSOR_TYPE_DECONZ = "deconz"
class MotionTrigger(hass.Hass):
def initialize(self):
self.timer_handle = None
self.listen_event_handle_list = []
self.listen_state_handle_list = []
self.timer_handle_list = []
self.turned_on_by_me = False # Giggedi
self.app_switch = globals.get_arg(self.args, "app_switch")
self.sensor = globals.get_arg(self.args, "sensor")
self.entity_on = globals.get_arg(self.args, "entity_on")
try:
self.entity_off = globals.get_arg(self.args, "entity_off")
except KeyError:
self.entity_off = None