Add ability to set color. Added limited ability to set effect. The only effects that work are: blink, breathe, okay, channel_change. Added hex_to_RGB color
This commit is contained in:
37
apps/timer.py
Normal file
37
apps/timer.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from appdaemon.entity import Entity
|
||||
from appdaemon.plugins.hass.hassapi import Hass
|
||||
|
||||
|
||||
class TimerClass(Hass):
|
||||
def initialize(self):
|
||||
on_time = self.args['on_time']
|
||||
self.run_daily(self.activate, start=on_time)
|
||||
self.log(f'Initialized timer for {self.light.friendly_name} at {on_time}')
|
||||
|
||||
@property
|
||||
def light(self) -> Entity:
|
||||
return self.get_entity(self.args['light'])
|
||||
|
||||
def activate(self, **kwargs: dict):
|
||||
hex = self.args.get('color')
|
||||
br_val = self.args.get('brightness')
|
||||
self.light.turn_on(brightness=br_val,rgb_color=self.hex_to_rgb(hex))
|
||||
|
||||
# This function was written by chatgpt...
|
||||
def hex_to_rgb(self, hex_color: str) -> list:
|
||||
|
||||
# Remove the "#" if it's included
|
||||
hex_color = hex_color.lstrip('#')
|
||||
|
||||
# Check if the string has a valid length
|
||||
if len(hex_color) != 6:
|
||||
raise ValueError(f"Invalid hex color: {hex_color}. Must be 6 characters long.")
|
||||
|
||||
try:
|
||||
# Split the hex color into its RGB components and convert to integers
|
||||
r = int(hex_color[0:2], 16)
|
||||
g = int(hex_color[2:4], 16)
|
||||
b = int(hex_color[4:6], 16)
|
||||
return [r, g, b]
|
||||
except ValueError:
|
||||
raise ValueError(f"Invalid hex color: {hex_color}. Must contain only valid hex digits.")
|
||||
Reference in New Issue
Block a user