Giter Site home page Giter Site logo

haberda / periodic-lights Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 1.0 155 KB

This AppDaemon app progressively changes the brightness and color temperature of lights over the course of the day. This app also uses change thresholds to ignore lights that have been manually adjusted.

License: GNU General Public License v3.0

Python 100.00%
lights appdeamon homeassistant brightness color-temperature

periodic-lights's People

Contributors

denilsonsa avatar haberda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

xylot

periodic-lights's Issues

I don't understand how to achieve a pattern that follows the sun's

I have a hard time understanding if this is what I need and how to achieve it.

I'd like to have the lights temperature and brightness roughly follow the sun's: bright and cooler in the morning gradually moving towards warm and low brightness as the sun sets, warmest and lowest brightness overnight, gradually increasing back close to sunrise.

Is that what this code achieves? I can't figure out how to set start_time and end_time to achieve this effect. And do I need start_index and end_index at all in that scenario?

Is there a way to see the curve over 24h?

I'm really struggling wrapping my head around the algorithm for some reason. I think visualizing the curve like in the README but for my particular config would help. Is there a way to see it?

What I'd like to achieve: lights gradually warm up and dim down as we approach sunset. After sunset, the lights are around 20% brightness until midnight, where they switch to the warmest temperature and lowest brightness (say 5%), until 1h before sunrise. After that point, they gradually warm up and become brighter until sunrise where they switch to max brightness and cold temp until sunset again.

So this is what I have:

lights_temp:
  module: update_lights
  class: update_lights
  start_time: sunset
  end_time: sunrise
  start_index: 00:00:00
  end_index: sunrise - 01:00:00
  color_temp_max: 4000
  color_temp_min: 2000
  brightness_unit: percent
  max_brightness_level: 100
  min_brightness_level: 5
  brightness_threshold: 5
  watch_light_state: true
  run_every: 60

But that doesn't seem to work. The lights are very dim at some point in the afternoon way before sunset when they should be cold and bright. What am I doing wrong?

I... I am too dumb.

So I have been playing with this for two days now. It looks like it can do what I want, which basically is to have

  • Start increasing brightness and color in the morning from 1 hour (or so) before sunrise and be done 2 hours or so after sunrise.
  • Start decreasing brightness and color in the evening from 2 hours or so before sunrise an be in full effect 2 hours after (or so).

I have been reading the documentation but honestly, that is beyond me. And I am running a 400-or-so automations HA setup with 28 integrations. But this beats me.

I have been whacking at the settings in an orderly fashion at first, randomly bashing later.

main_periodic_lights:
  module: update_lights
  class: update_lights
  run_every: 180
  event_subscription: main_update_lights
  entities:
    - light.mi_esstischlampe
    - light.mi_licht_badezimmer
    - light.mi_licht_theodor
    - light.mi_licht_wohnzimmer_tv
    - light.licht_kuche
    - light.licht_johann
    - light.licht_schlafzimmer_4
    - light.licht_buro_3
  brightness_threshold: 25
  color_temp_max: 4100
  color_temp_min: 3000
# color_temp_unit: 'kelvin'
  max_brightness_level: 100
  min_brightness_level: 35
  brightness_unit: 'percent'
  sleep_entity:
    - input_boolean.just_woke_up,off
  disable_entity:
    - input_boolean.watching_tv,on
# red_hour: '21:00:00'
  start_time: sunset - 04:00:00
  end_time: sunrise + 01:00:00
  start_index: sunrise - 02:00:00
  end_index: sunset
  transition: 5
  keep_lights_on: False
  stop_lights_off: True
  watch_light_state: True
  sensor_log: sensor.main_lights

I have been playing with start_time, end_time, start_index etc. Even after reading the documentation 10 or so time I still don't know what they do. Sorry :)

Could someone pleas help me and roughly tell me what goes where?
And a "lamens section" in the documentation would not go amiss.

Cheers!
-Chris.

Clarification of start index and end index?

Hi There,
First thanks for your work. Second, I don't understand how the start index and end index are used in a practical sense, can you give an example of how they would function in an automation? I see in your docs that you give an example of two times that can be given, but what would be the impact in that case?

I think this app might fit my use case, but I'm just not sure how I'd deploy it. For my use case, I'd like my lights to go to full brightness at, let's say 5pm then dim to the minimum level at 10pm. Then I want to have those lights resume the minimum level at 6am, coming back up to full brightness at 10am. I'm pretty sure your app does this, but I think the variables and how they are used are confusing me.

Thanks

Turns of Lights but never adjusts them

I am running this script on appdaemon 4.0.5 and HA 0.115. It successfully turns on the lights as expected, however they never adjust as expected.

apps.yaml:
module: update_lights
class: update_lights
entities:
- light.fasad
max_brightness_level: 50
min_brightness_level: 10
run_every: 30
start_time: '09:18:00'
end_time: '10:00:00'
start_lights_on: true

appdaemon:
fasad_update_lights | 2020-10-05T09:18:00+02:00 | 1 day, 0:00:00 | lights_on | 1 | 1 | true | 0 | {"interval":86400} fasad_update_lights | 2020-10-04T09:33:47+02:00 | 0:00:30 | time_change | 31 | 31 | true | 0 | {"interval":30}

I see no errors in the logs using the appdaemon ui.

I do however notice one thing: the lights are 49 on turn on however they are set at 50.

App not working - invalid time string: 61200

Home Assistant 0.113.0
I think after update, app no longer works. Noticed when lights didn't change in the evening.
Here is the log when toggling lights:

2020-07-24 23:53:24.627305 WARNING main_update_lights: ------------------------------------------------------------
2020-07-24 23:53:24.627594 WARNING main_update_lights: Unexpected error in worker for App main_update_lights:
2020-07-24 23:53:24.627796 WARNING main_update_lights: Worker Ags: {'id': '64944d60d44c423c9ab57243a416792a', 'name': 'main_update_lights', 'objectid': '4811649cde87490e9e99ac2639c289ee', 'type': 'state', 'function': <bound method update_lights.state_change of <update_lights.update_lights object at 0x7f2e31afa400>>, 'attribute': 'state', 'entity': 'light.left_bulb', 'new_state': 'on', 'old_state': 'off', 'pin_app': True, 'pin_thread': 4, 'kwargs': {'__thread_id': 'thread-4'}}
2020-07-24 23:53:24.628036 WARNING main_update_lights: ------------------------------------------------------------
2020-07-24 23:53:24.631696 WARNING main_update_lights: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 777, in worker
    funcref(entity, attr, old_state, new_state,
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 107, in state_change
    self.adjust_light(entity, threshold, transition)
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 313, in adjust_light
    pct = self.pct()
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 141, in pct
    start_ts = datetime.datetime.combine(self.date(), self.parse_time(self.start_time))
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 191, in inner_sync_wrapper
    f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 285, in run_coroutine_threadsafe
    result = future.result(self.AD.internal_function_timeout)
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/lib/python3.8/site-packages/appdaemon/adapi.py", line 1810, in parse_time
    return await self.AD.sched.parse_time(time_str, name, aware)
  File "/usr/lib/python3.8/site-packages/appdaemon/scheduler.py", line 576, in parse_time
    return self.make_naive((await self._parse_time(time_str, name))["datetime"]).time()
  File "/usr/lib/python3.8/site-packages/appdaemon/scheduler.py", line 656, in _parse_time
    raise ValueError("invalid time string: %s", time_str)
ValueError: ('invalid time string: %s', '61200')

Lights get turned back on after they should be turned off

I have a setup such as automation.yaml:

- alias: Hallway lights on when motion detected or front door is open
  id: hallway_turn_on_the_lights_by_movement_or_door
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.frontdoor_motion
    - binary_sensor.eve_door_etuovi
    to: 'on'
  action:
  - service: light.turn_on
    entity_id:
    - light.etuovi
    - light.eteinen


- alias: Hallway lights off when motion detected or front door is open
  id: hallway_turn_off_the_lights_by_movement_or_door
  trigger:
  - platform: state
    entity_id: binary_sensor.frontdoor_motion
    to: 'off'
    for: 00:00:45
  - platform: state
    entity_id: binary_sensor.eve_door_etuovi
    to: 'off'
    for: 00:00:45
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: binary_sensor.eve_door_etuovi
      state: 'off'
    - condition: state
      entity_id: binary_sensor.frontdoor_motion
      state: 'off'
  action:
  - service: light.turn_off
    data:
      entity_id:
      - light.etuovi
      - light.eteinen
      transition: 15


- alias: Lights on when motion in bathroom
  id: lights_on_when_motion_in_bathroom
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.bathroom_motion
    to: 'on'
  action:
  - service: light.turn_on
    entity_id:
    - light.kylpyhuone_ledi


    
- alias: Lights off when no motion in bathroom and door is open
  id: lights_off_when_no_motion_in_bathroom_and_door_is_open
  trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_motion
    to: 'off'
    for: 00:00:45
  condition:
    - condition: state
      entity_id: binary_sensor.eve_door_kylpyhuone
      state: 'on'
  action:
  - service: light.turn_off
    data:
      entity_id:
      - light.kylpyhuone_ledi
      transition: 15


- alias: Lights off when no motion in bathroom and door is closed
  id: lights_off_when_no_motion_in_bathroom_and_door_is_closed
  trigger:
  - platform: state
    entity_id: binary_sensor.bathroom_motion
    to: 'off'
    for: 00:14:45
  condition:
    - condition: state
      entity_id: binary_sensor.eve_door_kylpyhuone
      state: 'off'
  action:
  - service: light.turn_off
    data:
      entity_id:
      - light.kylpyhuone_ledi
      transition: 15



- alias: Lights on when motion in wc hallway
  id: lights_on_when_motion_in_wc_hallway
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.hallway_motion
    to: 'on'
  action:
  - service: light.turn_on
    entity_id:
    - light.wc_eteinen


- alias: Lights off when motion in wc hallway
  id: lights_off_when_motion_in_wc_hallway
  trigger:
  - platform: state
    entity_id: binary_sensor.hallway_motion
    to: 'off'
    for: 00:00:45
  action:
  - service: light.turn_off
    data:
      entity_id:
      - light.wc_eteinen
      transition: 15

and apps.yaml:

motion_lights:
  module: update_lights
  class: update_lights
  run_every: 0
  entities:
    - light.kylpyhuone_ledi
    - light.etuovi
    - light.eteinen
    - light.wc_eteinen
  brightness_threshold: 0
  color_temp_max: 250
  color_temp_min: 500
  color_temp_unit: 'mired'
  max_brightness_level: 100
  min_brightness_level: 10
  brightness_unit: 'percent'
  red_hour: '01:00:00'
  start_time: sunset - 3:00:00
  end_time: sunrise + 2:00:00
  start_index: '19:00:00'
  end_index: '06:00:00'
  keep_lights_on: false
  start_lights_on: false
  stop_lights_off: false
  watch_light_state: true
  sensor_log: sensor.motion_lights

If I remove the motion_lights app, my automations work as intended:
They turn on when there is motion (and/or door is opened) and turned off when there has not been motion detected in given time (and door is open/closed).
But once I add this motion_lights, my lights get turned back on after the 15 second transition.
Any idea what would cause this? I'm suspecting that run_every does not respect the value of 0. I might be completely wrong as well, as I have tried other values as well, such as 3600, 300, etc. but still the lights get turned back on right after the transition has finished or right at the end of the transition. Even this is not consistent, it keeps turning the lights back to the value they were when the light turned on (thus ignoring the transition and turning the light off).

One very probable cause of this behaviour is my configuration. As I'm not 100% sure whether I've configured it properly, I don't know.

arch aarch64
chassis embedded
dev false
docker true
docker_version 19.03.11
hassio true
host_os HassOS 4.15
installation_type Home Assistant OS
os_name Linux
os_version 4.19.127-v8
python_version 3.8.6
supervisor 2020.11.0
timezone Europe/Helsinki
version 0.117.2
virtualenv false
2020-11-04 23:04:33.172554 INFO AppDaemon: AppDaemon Version 4.0.5 starting
2020-11-04 23:04:33.173061 INFO AppDaemon: Python version is 3.8.5

Latest version of update_lights.

Please let me know if I could provide you some more information.

Problem installing?

Hi,

I installed this module with HACS and then followed your readme, created an apps.yaml, set config and did an include in my main configuration and then Home-Asssistant says : Component error: apps - Integration 'apps' not found..

What can i do to fix this?

After latest update, no longer works- TypeError: expected string or bytes-like object

Turning on light, getting error in log: TypeError: expected string or bytes-like object

Update lights version: Installed: 2113049
Add-on: AppDaemon 4
Python Apps and Dashboard using AppDaemon 4.x for Home Assistant
Add-on version: 0.2.3
You are running the latest version of this add-on.
System: Debian GNU/Linux 10 (buster) (armv7 / odroid-xu)
Home Assistant Core: 0.106.6
Home Assistant Supervisor: 209

2020-03-17 18:05:19.120937 WARNING main_update_lights: ------------------------------------------------------------
2020-03-17 18:05:19.122602 WARNING main_update_lights: Unexpected error in worker for App main_update_lights:
2020-03-17 18:05:19.124103 WARNING main_update_lights: Worker Ags: {'id': '482aeefb35d84b0bb1fbed874f7f27f4', 'name': 'main_update_lights', 'objectid': '10a1a1a6bfd24976a7666ecac5c0de23', 'type': 'scheduler', 'function': <bound method update_lights.time_change of <update_lights.update_lights object at 0xb4b8c9a0>>, 'pin_app': True, 'pin_thread': 5, 'kwargs': {'interval': 60, '__thread_id': 'thread-5'}}
2020-03-17 18:05:19.125591 WARNING main_update_lights: ------------------------------------------------------------
2020-03-17 18:05:19.129184 WARNING main_update_lights: Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/appdaemon/threading.py", line 766, in worker
    funcref(self.AD.sched.sanitize_timer_kwargs(app, args["kwargs"]))
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 95, in time_change
    self.adjust_light(entities, threshold, transition)
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 301, in adjust_light
    pct = self.pct()
  File "/config/appdaemon/apps/update_lights/update_lights.py", line 144, in pct
    start_i_ts = datetime.datetime.combine(start_ts.date(), self.parse_time(self.start_index))
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 191, in inner_sync_wrapper
    f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
  File "/usr/lib/python3.8/site-packages/appdaemon/utils.py", line 285, in run_coroutine_threadsafe
    result = future.result(self.AD.internal_function_timeout)
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/lib/python3.8/site-packages/appdaemon/adapi.py", line 1810, in parse_time
    return await self.AD.sched.parse_time(time_str, name, aware)
  File "/usr/lib/python3.8/site-packages/appdaemon/scheduler.py", line 576, in parse_time
    return self.make_naive((await self._parse_time(time_str, name))["datetime"]).time()
  File "/usr/lib/python3.8/site-packages/appdaemon/scheduler.py", line 589, in _parse_time
    parts = re.search('^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+):(\d+)$', time_str)
  File "/usr/lib/python3.8/re.py", line 199, in search
    return _compile(pattern, flags).search(string)
TypeError: expected string or bytes-like object

2020-03-17 18:05:19.130563 WARNING main_update_lights: ------------------------------------------------------------

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.