Last active
November 5, 2019 11:58
-
-
Save dlashua/dc402058da8fcefb6102a4afa7ae549e to your computer and use it in GitHub Desktop.
daysequence AppDaemon App
This file contains hidden or 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
celestebed_color_lights: | |
module: dlashua_daysequence | |
class: DaySequenceEvent | |
days_list: | |
- option: halloween | |
start: | |
month: 10 | |
day: 1 | |
end: | |
month: 11 | |
day: 2 | |
- option: thanksgiving | |
start: | |
month: 11 | |
day: 3 | |
end: | |
month: 11 | |
day: 30 | |
- option: xmas | |
start: | |
month: 12 | |
day: 1 | |
end: | |
month: 12 | |
day: 28 | |
- option: july_four | |
start: | |
month: 7 | |
day: 3 | |
end: | |
month: 7 | |
day: 5 | |
- option: canada_day | |
start: | |
month: 6 | |
day: 30 | |
end: | |
month: 7 | |
day: 2 | |
- option: vday | |
start: | |
month: 2 | |
day: 1 | |
end: | |
month: 2 | |
day: 16 | |
sequence: | |
celestebed_color_lights_normal: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
color_name: purple | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
color_name: purple | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
color_name: purple | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
color_name: dodgerblue | |
celestebed_color_lights_july_four: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 128 | |
rgb_color: [255, 255, 255] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
rgb_color: [0, 0, 255] | |
celestebed_color_lights_canada_day: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
rgb_color: [255, 255, 255] | |
celestebed_color_lights_vday: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
rgb_color: [255, 0, 127] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
rgb_color: [255, 0, 127] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
rgb_color: [255, 0, 127] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
rgb_color: [0, 255, 0] | |
celestebed_color_lights_xmas: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
rgb_color: [255, 0, 0] | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
rgb_color: [0, 255, 0] | |
celestebed_color_lights_halloween: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
color_name: orange | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
color_name: orange | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
color_name: orange | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
rgb_color: [0, 255, 0] | |
celestebed_color_lights_thanksgiving: | |
steps: | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_left | |
brightness: 255 | |
color_name: yellow | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_right | |
brightness: 255 | |
color_name: yellow | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_middle | |
brightness: 255 | |
color_name: red | |
- light/turn_on: | |
entity_id: light.celestebed_floorlamp_top | |
brightness: 255 | |
color_name: orange |
This file contains hidden or 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
import appdaemon.plugins.hass.hassapi as hass | |
import datetime | |
DEFAULT_DOMAIN = 'day_sequence' | |
class DaySequenceEvent(hass.Hass): | |
def initialize(self): | |
self._seq_prefix = self.args.get('seq_prefix', self.name) | |
self._default_name = self.args.get('default_name', 'normal') | |
self._days_list = self.args.get('days_list', []) | |
self._domain = self.args.get('domain', DEFAULT_DOMAIN) | |
event_name = "{}.{}".format(self._domain, self._seq_prefix) | |
self.listen_event(self.event_cb, event_name) | |
def event_cb(self, event, data, kwargs): | |
option = data.get('option', self._default_name) | |
now = self.get_now() | |
for day_item in self._days_list: | |
start = now | |
start = start.replace(hour=0, minute=0, second=0) | |
start = start.replace(**day_item['start']) | |
end = now | |
end = end.replace(hour=23, minute=59, second=59) | |
end = end.replace(**day_item['end']) | |
if start <= now and now <= end: | |
option = day_item['option'] | |
self.log("{} is NOW".format(option), level="DEBUG") | |
break | |
else: | |
self.log("{} is NOT NOW".format(day_item['option']), level="DEBUG") | |
sequence_name = "sequence.{}_{}".format( | |
self._seq_prefix, | |
option) | |
self.run_sequence(sequence_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment