Commit 1f354a85 authored by Rob Connolly's avatar Rob Connolly

AppDaemon stuff moved to it's own repo.

See: https://gitlab.com/robconnolly/appdaemon-config
parent 0cf205a9
......@@ -7,13 +7,11 @@ home-assistant_v2.db*
*.pem
deps/
tts/
dashboards/
.storage
custom_components/
www/community/
script-env/
broadlink-env/
shell_commands/__pycache__/
apps/__pycache__/
__pycache__/
ip_bans.yaml
---
log:
logfile: STDOUT
errorfile: STDERR
appdaemon:
threads: 10
timezone: 'Pacific/Auckland'
plugins:
HASS:
type: hass
ha_url: "http://172.17.0.1:8123"
token: !secret appdaemon_token
---
hello_world:
module: hello
class: HelloWorld
toilet_motion_lights:
module: motion_lights
class: BrightnessControlledMotionLight
motion_sensor: binary_sensor.toilet_motion
light: light.toilet
timeout: 120
bedroom_doors:
- !secret bed1_door_entity
- !secret bed2_door_entity
other_doors:
- binary_sensor.kitchen_hall_door_contact
import appdaemon.plugins.hass.hassapi as hass
#
# Hello World App
#
# Args:
#
class HelloWorld(hass.Hass):
def initialize(self):
self.log("Hello from AppDaemon")
self.log("You are now ready to run Apps!")
import appdaemon.plugins.hass.hassapi as hass
class MotionLight(hass.Hass):
def initialize(self):
self.motion_sensor = self.args['motion_sensor']
self.light = self.args['light']
self.timeout = self.args['timeout']
self.timer = None
self.listen_state(self.motion_callback, self.motion_sensor, new = "on")
def set_timer(self):
if self.timer is not None:
self.cancel_timer(self.timer)
self.timer = self.run_in(self.timeout_callback, self.timeout)
def is_light_times(self):
return self.now_is_between("sunset - 00:10:00", "sunrise + 00:10:00")
def motion_callback(self, entity, attribute, old, new, kwargs):
if self.is_light_times():
self.turn_on(self.light)
self.set_timer()
def timeout_callback(self, kwargs):
self.timer = None
self.turn_off(self.light)
class BrightnessControlledMotionLight(MotionLight):
def initialize(self):
self.last_door = "Other"
for door in self.args['bedroom_doors']:
self.listen_state(self.bedroom_door_callback, door, old = "off", new = "on")
for door in self.args['other_doors']:
self.listen_state(self.other_door_callback, door, old = "off", new = "on")
super().initialize()
def bedroom_door_callback(self, entity, attribute, old, new, kwargs):
self.last_door = "Bedroom"
self.log("Last door is: {}".format(self.last_door))
def other_door_callback(self, entity, attribute, old, new, kwargs):
self.last_door = "Other"
self.log("Last door is: {}".format(self.last_door))
def motion_callback(self, entity, attribute, old, new, kwargs):
if self.is_light_times():
if self.get_state(entity=self.light) == "off":
if self.now_is_between("07:00:00", "20:00:00") or self.last_door != "Bedroom":
self.turn_on(self.light, brightness_pct = 100)
else:
self.turn_on(self.light, brightness_pct = 1)
self.set_timer()
Subproject commit 09d2635e5d8a4e42b682608bf951718268f268de
import pytest
from appdaemontestframework import automation_fixture
from apps.motion_lights import MotionLight
@automation_fixture(MotionLight)
def motion_light(given_that):
given_that.passed_arg("motion_sensor").is_set_to("binary_sensor.motion")
given_that.passed_arg("light").is_set_to("light.test_light")
given_that.passed_arg("timeout").is_set_to(120)
def test_working(given_that, motion_light, assert_that):
assert(True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment