Skip to content

Commit

Permalink
update with dimrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythm authored Nov 25, 2023
1 parent d413dec commit d036cc2
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 525 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Lightwand
an Appdaemon app for complete control of your lights in every situation

## Updates coming
Try to clean up configuration of the app to make it easier to get started.
Set brightness transition over time. -/+ 1 brightness pr x minutes. Will be defined with dimrate
an Appdaemon app for extensive control of lights based on time of day with mode event in addition to motion, presence, lux, rain, and media player sensors.

## Installation
Download the `Lightwand` directory from inside the `apps` directory here to your Appdaemon `apps` directory, then add configuration to a yaml file to enable the `Lightwand` module. See configuration below or my lightwand.yaml file for examples.
Expand Down Expand Up @@ -67,6 +63,8 @@ If 'orLater' is later than 'time' it will shift all times following the same tim

You can in prevent shifts and deletions with a 'fixed: True' under time that locks time from beeing moved of deleted. I only use this to make sure the lights for the children turns off at bedtime even when sun sets after.

Use dimrate to set brightness transition over time. -/+ 1 brightness pr x minutes.

### Motion behaviour
Configure <b>motionlights</b> to change light based on motion sensors in room. Easiest configuration is

Expand Down Expand Up @@ -119,7 +117,7 @@ Sorted by priority if more than one mediaplayer is defined in room. Can be any s
You can use Lux sensors to control or constrain lights. Optionally you can provide if statement to be meet for light to turn on at normal/morning/motion mode or with automations defined. Inherits Appdaemon Api as ADapi.

### Get started
Easisest to start off with is to copy this example. There is a lot of list/dictionaries that needs to be correctly indented. And remember: All sections and configurations are optional, so you use only what is applicable
Easisest to start off with is to copy this example and update with your sensors and lights and build from that. There is a lot of list/dictionaries that needs to be correctly indented. And remember: All sections and configurations are optional, so you use only what is applicable.

## App configuration

Expand Down
52 changes: 49 additions & 3 deletions apps/Lightwand/lightwand.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
FIXME:
- if 'motion_constraints' becomes true when motion sensor is detecting motion, light will not be updated until motion is redetected
History:
v1.0.2
- Updated with the possibility to dim lights 1 brightness at every x minutes with dimrate.
@Pythm / https://github.com/Pythm
"""

Expand Down Expand Up @@ -504,7 +508,7 @@ def __init__(self, api,
automation['time'] = automation['orLater']
elif timeToAdd > datetime.timedelta(minutes = 0) :
if 'fixed' in automation :
continue
timeToAdd = datetime.timedelta(minutes = 0)
newtime = self.ADapi.parse_datetime(automation['time']) + timeToAdd
automation['time'] = str(newtime.time())

Expand All @@ -519,6 +523,20 @@ def __init__(self, api,
for num in reversed(automationsToDelete) :
del self.automations[num]

brightness = 0
for automation in self.automations :
if 'dimrate' in automation :
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
timeDate = self.ADapi.parse_datetime(automation['time'])
while brightness > automation['light_data']['brightness'] :
brightness -= 1
timeDate += datetime.timedelta(minutes = automation['dimrate'])
self.automations.append({'time': str(timeDate), 'light_data': {'brightness': brightness}})
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
brightness = automation['light_data']['brightness']

for automation in self.automations :
if not 'state' in automation :
automation.update({'state': 'none'})
Expand Down Expand Up @@ -547,7 +565,7 @@ def __init__(self, api,
automation['time'] = automation['orLater']
elif timeToAdd > datetime.timedelta(minutes = 0) :
if 'fixed' in automation :
continue
timeToAdd = datetime.timedelta(minutes = 0)
newtime = self.ADapi.parse_datetime(automation['time']) + timeToAdd
automation['time'] = str(newtime.time())

Expand All @@ -561,6 +579,20 @@ def __init__(self, api,
for num in reversed(automationsToDelete) :
del self.motionlight[num]

brightness = 0
for automation in self.motionlight :
if 'dimrate' in automation :
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
timeDate = self.ADapi.parse_datetime(automation['time'])
while brightness > automation['light_data']['brightness'] :
brightness -= 1
timeDate += datetime.timedelta(minutes = automation['dimrate'])
self.motionlight.append({'time': str(timeDate), 'light_data': {'brightness': brightness}})
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
brightness = automation['light_data']['brightness']

for automation in self.motionlight :
if not 'state' in automation :
automation.update({'state': 'none'})
Expand Down Expand Up @@ -589,7 +621,7 @@ def __init__(self, api,
automation['time'] = automation['orLater']
elif timeToAdd > datetime.timedelta(minutes = 0) :
if 'fixed' in automation :
continue
timeToAdd = datetime.timedelta(minutes = 0)
newtime = self.ADapi.parse_datetime(automation['time']) + timeToAdd
automation['time'] = str(newtime.time())

Expand All @@ -603,6 +635,20 @@ def __init__(self, api,
for num in reversed(automationsToDelete) :
del mode['automations'][num]

brightness = 0
for automation in mode['automations'] :
if 'dimrate' in automation :
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
timeDate = self.ADapi.parse_datetime(automation['time'])
while brightness > automation['light_data']['brightness'] :
brightness -= 1
timeDate += datetime.timedelta(minutes = automation['dimrate'])
mode['automations'].append({'time': str(timeDate), 'light_data': {'brightness': brightness}})
if 'light_data' in automation :
if 'brightness' in automation['light_data'] :
brightness = automation['light_data']['brightness']

for automation in mode['automations'] :
if not 'state' in automation :
automation.update({'state': 'none'})
Expand Down
Loading

0 comments on commit d036cc2

Please sign in to comment.