Circadian Lighting [Custom Component]

I had the same issue (on a docker install as well so maybe something to do with that) so just logged into the console and installed manually (pip3 install timezonefinder).

1 Like

Good workaround, although it would be nice to figure out why itā€™s not installing automatically as it should.

That was the complete content of my home-assistant.log. Nothing from homeassistant.util.package in there :-/

Will try to list the folders in site-packages when I come back home later.
I will also try to install the timezonefinder directly via console. Thanks to @zestyphresh

Hi @claytonjn,

these are the folders I have in /config/deps/lib/python3.6/site-packages

.libs_cffi_backend
__pycache__
aiodns
aiodns-1.1.1.dist-info
aiohttp
aiohttp_cors
aiohttp_cors-0.7.0.dist-info
aiohttp-3.1.1.dist-info
aiohttp-3.3.2.dist-info
aiohue
aiohue-1.3.0.dist-info
aiohue-1.5.0.dist-info
apiclient
asn1crypto
asn1crypto-0.24.0.dist-info
async_timeout
async_timeout-3.0.0.dist-info
attr
attrs-17.4.0.dist-info
attrs-18.1.0.dist-info
beautifulsoup4-4.6.0.dist-info
boto3
boto3-1.7.10.dist-info
botocore
botocore-1.10.10.dist-info
bs4
cdu
certifi
certifi-2018.4.16.dist-info
cffi
cffi-1.11.5.dist-info
chardet
chardet-3.0.4.dist-info
cookies-2.2.1.dist-info
Crypto
cryptography
cryptography-2.2.2.dist-info
datadog
datadog-0.15.0.dist-info
dateutil
decorator-4.3.0.dist-info
distro-1.2.0.dist-info
distro-1.3.0.dist-info
docopt-0.6.2.dist-info
docutils
docutils-0.14.dist-info
ecdsa
ecdsa-0.13.dist-info
envs
envs-1.2.4.dist-info
forecastio
fritzconnection
fritzconnection-0.6.5.dist-info
future
future-0.16.0.dist-info
google
google_api_python_client-1.6.4.dist-info
googleapiclient
googlemaps
googlemaps-2.5.1.dist-info
gtts_token
gTTS_token-1.1.1.dist-info
hass_frontend
hass_frontend_es5
hbmqtt
hbmqtt-0.9.1.dist-info
hbmqtt-0.9.2.dist-info
home_assistant_frontend-20180404.0.dist-info
home_assistant_frontend-20180426.0.dist-info
home_assistant_frontend-20180509.0.dist-info
home_assistant_frontend-20180526.4.dist-info
home_assistant_frontend-20180708.0.dist-info
http_ece
http_ece-1.0.5.dist-info
httplib2
httplib2-0.11.3.dist-info
idna
idna_ssl-1.0.1.dist-info
idna-2.6.dist-info
jmespath
jmespath-0.9.3.dist-info
jose
jwt
libfuturize
libpasteurize
luftdaten
luftdaten-0.2.0.dist-info
lxml
lxml-4.2.1.dist-info
multidict
multidict-4.2.0.dist-info
multidict-4.3.1.dist-info
mutagen
mutagen-1.40.0.dist-info
nest
netdisco
netdisco-1.3.1.dist-info
netdisco-1.3.dist-info
netdisco-1.5.0.dist-info
netifaces-0.10.6.dist-info
netifaces-0.10.7.dist-info
nmap
oauth2client
oauth2client-4.0.0.dist-info
oauth2client-4.1.2.dist-info
paho
paho_mqtt-1.3.1.dist-info
passlib
passlib-1.7.1.dist-info
past
pkg_resources
protobuf-3.5.2.post1.dist-info
psutil
psutil-5.4.3.dist-info
psutil-5.4.6.dist-info
py_vapid
py_vapid-1.3.1.dist-info
pyasn1
pyasn1_modules
pyasn1_modules-0.2.1.dist-info
pyasn1-0.4.2.dist-info
pycares
pycares-2.3.0.dist-info
pychromecast
PyChromecast-2.1.0.dist-info
pycparser
pycparser-2.18.dist-info
pycryptodome-3.3.1.dist-info
pydeconz
pydeconz-38.dist-info
pyfritzhome
pyfritzhome-0.3.6.dist-info
pyfritzhome-0.3.7.dist-info
PyJWT-1.6.0.dist-info
python_dateutil-2.7.2.dist-info
python_forecastio-1.4.0.dist-info
python_jose_cryptodome-1.3.2.dist-info
python_nest-4.0.2.dist-info
python_nmap-0.6.1.dist-info
pywebpush
pywebpush-1.6.0.dist-info
PyYAML-3.12.dist-info
requests
requests-2.19.1.dist-info
responses-0.9.0.dist-info
RestrictedPython
RestrictedPython-4.0b2.dist-info
RestrictedPython-4.0b4.dist-info
rsa
rsa-3.4.2.dist-info
s3transfer
s3transfer-0.1.13.dist-info
schiene
schiene-0.22.dist-info
scripts
setuptools
setuptools-39.0.1.dist-info
setuptools-39.1.0.dist-info
simplejson
simplejson-3.14.0.dist-info
six-1.11.0.dist-info
soco
soco-0.14.dist-info
speedtest_cli-2.0.2.dist-info
sqlalchemy
SQLAlchemy-1.2.5.dist-info
SQLAlchemy-1.2.8.dist-info
sseclient
sseclient_py-1.7.dist-info
tests
transitions
transitions-0.6.5.dist-info
ua_parser
ua_parser-0.8.0.dist-info
uritemplate
uritemplate-3.0.0.dist-info
urllib3
urllib3-1.22.dist-info
user_agents
user_agents-1.1.0.dist-info
voluptuous
voluptuous_serialize
voluptuous_serialize-1.0.0.dist-info
voluptuous-0.11.1.dist-info
wakeonlan-1.0.0.dist-info
warrant
warrant-0.6.1.dist-info
websockets
websockets-4.0.1.dist-info
xmltodict-0.11.0.dist-info
yaml
yarl
yarl-1.1.1.dist-info
yarl-1.2.4.dist-info
zeroconf-0.20.0.dist-info
_cffi_backend.cpython-36m-x86_64-linux-gnu.so
cookies.py
decorator.py
distro.py
docopt.py
easy_install.py
idna_ssl.py
netifaces.cpython-36m-x86_64-linux-gnu.so
protobuf-3.5.2.post1-py3.6-nspkg.pth
responses.py
six.py
speedtest.py
speedtest_cli.py
test_cookies.py
test_responses.py
wakeonlan.py
xmltodict.py
zeroconf.py

Installing timezonefinderdirectly via docker console also worked for me. Thanks :slight_smile:

Hi.

Saidly I have nothing thereā€¦
My whole deps library is empty. If samba share shows the truth.

Iā€™m really at a loss, the best advice I can give at this point is to run pip3 install timezonefinder through ssh.

I tried it before, and now again. But all I get after I run pip3 install timezonefinder is this message at the end:


Sorry for printscreen but I can copy the text because Iā€™m too noob for it.
OK, I managed to copy the full install log about timezonefinder instalaltion:
tf_ins_log.yaml (25.8 KB)
Itā€™s saved in yaml since forum not allows to upload plain txt :slight_smile:

The timezonefinder does not seem to be essential to the function of Circadian Lighting. (If you know your timezone).
In Hass.io for example it does not allow to manually install requirements via pip3.
What I did to get this custom component running was deleting all references to timezonefinder from the main circadian_lighting.py and edited the get_timezone function to return a hardcoded 'Europe/Berlin'.
Of course this is not really practical for updates.

@claytonjn:
does it make sense to make the timezone a configuration variable? That way you could omit timezonefinder It is required by the calculation of sun position using the astral module, right? So you can make it an required variable.

@claytonjn:
Have you read about circadian rhythms during short days in winter and a regular work day? My work day is not adjusted to the ā€˜naturalā€™ circadian rhythm at allā€¦ unfortunately it begins earlier than sunrise and ends after sunset in winter (in Germany in winter sunrise is around 8:00am and sunset around 4:30pm).
Also I guess that no one will end his day, just because the sun has set and not get up before sunrise nowadays. This has been true for some generations before us, who were reliant on natural daylight anyways.

I understand that maintaining a steady rhythm of the day is healthy, but bright light in office wont truely allow for that anyways.
So I am not really sure will be best:

  1. syncing the lighting at home to the working day and keeping it steady throughout the year or adjust it only slightly to make the difference between outside and inside less harsh
  2. syncing the lighting to outside, eliminating the gap between natural and artificial light, but sitting in the dark some time after waking and quite a long time before going to bed. (yes, I am aware of the ā€œmin_brightnessā€ variable, but I would not want to adjust it to the minimum value for winter afternoon, which is rather bright)

What do you think?

A request for the sensor:
Iā€™d like to use the sensor only and then use the output of it to switch the lights. Would you mind adding all of the configuration variables (except lists of light entities) and add brightness output as an attribute, so that the sleep state and also the disable function is managed by the Circadian Lighting component?
I could also do that and send you the code for review, so that you can merge the changes?!

I could do that, but my goal was to make the configuration as simple as possible. The way itā€™s designed currently the sensor can be had by adding just one line to configuration.yaml. If we canā€™t figure out why timezonefinder isnā€™t installing then that is an option but Iā€™d much rather fix the actual problem then just implement a workaround. timezonefinder should be installable, even on Hassio (which is what I personally use).

I think thatā€™s really a personal decision, everyone will have different reactions and has different situations which is why I tried to allow for much customization. My personal opinion is that following the natural rhythm is preferable if itā€™s fairly consistent, but for those closer to the poles where day variations are more extreme, or where there are other factors outside their control I think using the overrides to artificially make the lighting more consistent may be better. So in your case I would likely go with option 1, although you should experiment with the options yourself until you find what you prefer.

Is there a reason you couldnā€™t just configure a switch with no lights selected, so that it calculates brightness but doesnā€™t actually adjust any lights? I donā€™t want to have those features only in the sensor because there are situations where people want certain groups of lights to be disabled in different situations, or some to have brightness adjusted and others not, etc. I also donā€™t want to have those options duplicated because I feel that will be very confusing for new users.

Can you share your files? So I can see where do I have to change the code?

Just running across this project now.

Iā€™ve been looking to just have my lights default to a color temp thatā€™s relevant to the time of day when I turn them on, unless I override the color (in which case reset when they turn off back to being based on time of day).

Sure, that is the better approach. Did you manually install timezonefinder or did HA pull it automatically?

I have to set sunrise_time and sunset_time then, correct? I should be able to put an variable, in which I calculate a ā€œmildā€ sunrise and sunset time, shouldnt I? I am still not really used to how variables and templates work in HA.

Actually I have not tried that, because your last note says: one of the lights should be set. Will do that. Thanks mate.

@taanczos.tamaas: maybe it is better to find the reason why it is not installing timezonefinder first. If it isnā€™t possible to solve, then I can send you the adjustments.

@cicero222, @oakbrad, @taanczos.tamaas, @CM000n, @zestyphresh, @g0t0

Iā€™ve updated CL to completely remove the use of timezonefinder without having to modify configuration. The following files were updated:

Let me know of any issues!

Hi, Iā€™m thrilled by this component, as my whole reason to go into home automation was to try to help my circadian rhythm. I live in the arctic, so canā€™t rely on natural sunlight at all.

My problem is that I donā€™t know what format the sunrise_time and sunset_time should be. This doesnā€™t work:

circadian_lighting:
  sunrise_time: '07:00'
  sunset_time: '20:00'

Also not working without the ā€™ ā€™ marks. Or with seconds added, with or without the ā€™ ā€™ marks.

Sorry if this is something everyone should know. This is my third day with home automation, and my first custom component.

That should work, what error(s) are you getting?

This is my log:

2018-09-03 17:42:14 ERROR (MainThread) [homeassistant.setup] Error during setup of component circadian_lighting
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 148, in _async_setup_component
    component.setup, hass, processed_config)  # type: ignore
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/circadian_lighting.py", line 114, in setup
    interval, transition)
  File "/config/custom_components/circadian_lighting.py", line 139, in __init__
    self.data['percent'] = self.calc_percent()
  File "/config/custom_components/circadian_lighting.py", line 193, in calc_percent
    today_sun_times = self.get_sunrise_sunset()
  File "/config/custom_components/circadian_lighting.py", line 158, in get_sunrise_sunset
    sunrise = date.replace(self.data['sunrise_time'])
TypeError: an integer is required (got type datetime.time)
2018-09-03 17:42:15 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of switch.circadian_lighting. Setup failed for dependencies: circadian_lighting
2018-09-03 17:42:15 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.circadian_lighting: Could not set up all dependencies.
2018-09-03 17:42:23 WARNING (MainThread) [homeassistant.loader] You are using a custom component for sensor.circadian_lighting which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2018-09-03 17:42:23 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of sensor.circadian_lighting. Setup failed for dependencies: circadian_lighting
2018-09-03 17:42:23 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform sensor.circadian_lighting: Could not set up all dependencies.
2018-09-03 17:42:24 WARNING (MainThread) [homeassistant.setup] Setup of config is taking over 10 seconds.
2018-09-03 17:42:30 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

@zennr

Just pushed an update that should fix this. The following files were updated:

Let me know how it goes!

This works, thank you! :hibiscus:

It works great! Thanks.
But some few things i found. Iā€™m running Deconz and some various Zigbee ct-lights and errors i found:
When trying to change brightness the lights are fading back and forth and often end up on the wrong brightness.If i do this for a group the brightness varies between lights. And often i cant set brightness to the lowest level so i have to turn off Circadian Lighting to set the brigtness and then turn it back on again.
I running this with auto brightness turned off.

And a request: Sleep color and not just color temp to set a night light to red.

I donā€™t think I understand what youā€™re describing, could you elaborate? If disable_brightness_adjust is true, CL shouldnā€™t touch brightness at all.

I should be able to add this. I actually have a few places where I have lights come on red at night and I handle it by turning off CL and setting them to red, then turning CL back on in the morning. It would probably streamline things to just let CL handle it all though.