-
Notifications
You must be signed in to change notification settings - Fork 419
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
257 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Placeholder - required to all app module loading |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import homeassistant as ha | ||
import appapi | ||
|
||
class Log(appapi.APPDaemon): | ||
|
||
def initialize(self): | ||
return | ||
self.logger.info("Log Test: Parameter is {}".format(self.args["param1"])) | ||
self.log("Log Test: Parameter is {}".format(self.args["param1"])) | ||
self.error("Error Test") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
import homeassistant as ha | ||
import appapi | ||
|
||
class MirrorLight(appapi.APPDaemon): | ||
|
||
def initialize(self): | ||
ha.listen_state(self.name, self.light_changed, "light.andrew_bedside") | ||
#return | ||
self.listen_state(self.light_changed, "light.andrew_bedside") | ||
|
||
state = ha.get_state("light.andrew_bedside", "state") | ||
brightness = ha.get_state("light.andrew_bedside", "attributes.brightness") | ||
state = self.get_state("light.andrew_bedside") | ||
brightness = self.get_state("light.andrew_bedside", "brightness") | ||
|
||
self.logger.info("MirrorLight: Current State is {}, current brightness is {}".format(state, brightness)) | ||
self.log("MirrorLight: Current State is {}, current brightness is {}".format(state, brightness)) | ||
|
||
if ha.get_state("light.andrew_bedside", "state") == "on": | ||
ha.turn_on("light.office_lamp") | ||
if state == "on": | ||
self.call_service("light", "office_lamp", color_name = "red") | ||
else: | ||
self.turn_off("light.office_lamp") | ||
|
||
def light_changed(self, entity, old_state, new_state): | ||
self.logger.info("entity state changed, old: {}, new: {}".format(old_state["state"], new_state["state"])) | ||
def light_changed(self, entity, attribute, old, new): | ||
self.log("MirrorLight: entity {}.{} state changed, old: {}, new: {}".format(entity, attribute, old, new)) | ||
|
||
if new_state["state"] == 'on': | ||
#ha.turn_on("light.office_lamp") | ||
ha.turn_on("light.office_lamp", color_name = "blue") | ||
if new == 'on': | ||
#self.turn_on("light.office_lamp") | ||
print(self.call_service("light", "turn_on", entity_id = "light.office_lamp", color_name = "red")) | ||
else: | ||
ha.turn_off("light.office_lamp") | ||
print(self.turn_off("light.office_lamp")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import appapi | ||
|
||
class MotionLights(appapi.APPDaemon): | ||
|
||
def initialize(self): | ||
return | ||
self.listen_state(self.motion, "binary_sensor.upstairs_sensor_28") | ||
|
||
def motion(self, entity, attribute, old, new): | ||
if new == "on": | ||
#if new == "on" and self.sun_state() == "below_horizon": | ||
self.turn_on("light.office_1") | ||
self.run_in(self.light_off, 60) | ||
self.flashcount = 0 | ||
self.run_in(self.flash_warning, 1) | ||
|
||
def light_off(self, args, kwargs): | ||
self.turn_off("light.office_1") | ||
|
||
def flash_warning(self, args, kwargs): | ||
self.toggle("light.office_2") | ||
self.flashcount += 1 | ||
if self.flashcount < 10: | ||
self.run_in(self.flash_warning, 1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import homeassistant as ha | ||
import appapi | ||
|
||
class Service(appapi.APPDaemon): | ||
|
||
def initialize(self): | ||
return | ||
ha.notify("", "Service initialized") | ||
self.notify("", "Service initialized") | ||
# | ||
# turn_on and turn_off work with switches, lights, input_booleans, scenes and scripts | ||
# | ||
ha.turn_on("light.office_1") | ||
ha.run_in(self.name, self.toggle_light, 5) | ||
self.turn_on("light.office_1") | ||
self.run_in(self.toggle_light, 5) | ||
self.count = 0 | ||
|
||
def toggle_light(self, args, kwargs): | ||
ha.toggle("light.office_1") | ||
self.log("Toggling Light") | ||
self.toggle("light.office_1") | ||
self.count += 1 | ||
if self.count < 6: | ||
ha.run_in(self.name, self.toggle_light, 5) | ||
self.run_in(self.toggle_light, 5) | ||
else: | ||
ha.turn_off("light.office_1") | ||
self.turn_off("light.office_1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,59 @@ | ||
import homeassistant as ha | ||
import appapi | ||
|
||
class State(appapi.APPDaemon): | ||
|
||
def initialize(self): | ||
ha.listen_attr(self.name, self.attr, "input_select.house_mode", "state") | ||
state = ha.get_state("input_select.house_mode", "state") | ||
self.logger.info("State: Current State is {}".format(state)) | ||
return | ||
ha.listen_attr(self.name, self.attr, "light.office_1", "state") | ||
ha.listen_attr(self.name, self.attr, "light.office_1", "attributes.brightness") | ||
#self.logger.info(self.args["param1"]) | ||
ha.listen_state(self.name, self.all_state) | ||
ha.listen_state(self.name, self.lights, "light") | ||
ha.listen_state(self.name, self.lights, "light.office_1") | ||
|
||
# Set some callbacks | ||
#self.handle = self.listen_state(self.all_state) | ||
|
||
# set timer to cancel above callback in 10 seconds | ||
|
||
#self.run_in(self.cancel, 10) | ||
|
||
def all_state(self, entity, old, new): | ||
self.logger.info("Entity {} changed state".format(entity)) | ||
#self.listen_state(self.device, "light") | ||
#self.listen_state(self.entity, "light.office_1") | ||
#self.listen_state(self.attr, "light.office_1", "all") | ||
#self.listen_state(self.attr, "light.office_1", "state") | ||
#self.listen_state(self.attr, "light.office_1", "brightness") | ||
|
||
|
||
# Check some state values | ||
#state = self.get_state() | ||
#self.log(state) | ||
#state = self.get_state("media_player") | ||
#self.log(state) | ||
#state = self.get_state("light.office_1") | ||
#self.log(state) | ||
#state = self.get_state("light.office_1", "brightness") | ||
#self.log(state) | ||
#state = self.get_state("light.office_1", "all") | ||
#self.log(state) | ||
|
||
# Invalid combination | ||
|
||
#state = self.get_state("media_player", "state") | ||
#self.log(state) | ||
|
||
# Set a state | ||
|
||
#status = self.set_state("light.office_1", state = "on", attributes = {"color_name": "red"}) | ||
#self.log(status) | ||
|
||
|
||
|
||
def all_state(self, entity, attribute, old, new): | ||
self.log("Device {} went from {} to {}".format(entity, old, new)) | ||
|
||
def device(self, entity, attribute, old, new): | ||
self.log("Device {} went from {} to {}".format(entity, old, new)) | ||
|
||
def lights(self, entity, old, new): | ||
self.logger.info("Light {} went from {} to {}".format(entity, old["state"], new["state"])) | ||
def entity(self, entity, attribute, old, new): | ||
self.log("Entity {} went from {} to {}".format(entity, old, new)) | ||
|
||
def attr(self, entity, attribute, old, new): | ||
self.logger.info("ATTR {} {} {} {}".format(entity, attribute, old, new)) | ||
self.log("Attr {} {} {} {}".format(entity, attribute, old, new)) | ||
|
||
def cancel(self, args, kwargs): | ||
self.log("Cancelling callback: {}".format(self.handle)) | ||
self.cancel_listen_state(self.handle) |
Oops, something went wrong.