Outdoor illuminance estimated from weather conditions

Agree 100%. I’m just too cheap to go buy one. :wink:

2 Likes

I just upgraded my HASS install to 0.85.0 and I’m getting this error now:

Thu Jan 10 2019 20:30:54 GMT-0500 (Eastern Standard Time)

Error loading custom_components.sensor.illuminance. Make sure all dependencies are installed

Traceback (most recent call last): 
File "/usr/src/app/homeassistant/loader.py", line 92, in get_component 
module = importlib.import_module(path) 
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module 
return _bootstrap._gcd_import(name[level:], package, level) 
File "<frozen importlib._bootstrap>", line 994, in _gcd_import 
File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked 
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked 
File "<frozen importlib._bootstrap_external>", line 678, in exec_module 
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 
File "/config/custom_components/sensor/illuminance.py", line 19, in <module> 
from homeassistant.components.sensor.darksky import ( 
ImportError: cannot import name 'CONF_ATTRIBUTION'

Anyone else getting this? Is this because they changed something in HASS?

Yes, this has been noticed and a PR has already been submitted. See Issue #83 and PR #84.

The root cause is a change in the darksky sensor platform.

Awesome, thanks. When I checked earlier on your git I didn’t see the issue, but I didn’t check the PR. Thanks for the fast response.

Released 2.0.1.

Fixes bug caused by change in Dark Sky Sensor in HA release 0.85. Now works with new HA version, as well as older versions.

Is there a way to force a sample, even if the illuminance level hasn’t changed?

I’d like to combine this sensor with a low pass filter to eliminate frequent “rainy/cloudy” changes and their huge jump in illuminance. However, it seems that the brightness level is only updated when a change in conditions occurred, causing my filters to not converge or update in time…

I tried setting scan_interval to 5 minutes, but that only seems to affect the minimum interval, not the maximum.

Yes, there is, but it would take a few changes. First, I’d want it to be configurable, so a new config option would have to be added. Next the should_poll method would have to change to return True if the new config option was set to True. Next an override of the force_update method would have to be added which should also return True if the new config option was set to True.

If you want to test out the theory, you could simply change the should_poll method to always return True, and add the following:

    @property
    def force_update(self):
        return True

I was interested in trying this out as well. Could you expand a little more on what should be changed? I looked at the code, and I can see this in the should_poll:

def should_poll(self):
    # For the system (i.e., EntityPlatform) to configure itself to
    # periodically call our async_update method any call to this method
    # during initializaton must return True. After that, for WU we'll
    # always poll, and for others we'll only need to poll during the ramp
    # up and down periods around sunrise and sunset, and then once more
    # when period is done to make sure ramping is completed.
    if not self._init_complete or self._using_wu:
        return True
    changing = 0 < self.sun_factor(dt_util.now()) < 1
    if changing:
        self._was_changing = True
        return True
    if self._was_changing:
        self._was_changing = False
        return True
return False

Not sure what I would change there to make it always return true? Based on my limited coding experience I would think this?

def should_poll(self):
      return True

Or should there be more to it than that? And then just add the other three lines in an @property below that?

Yes, change:

    @property
    def should_poll(self):
        # For the system (i.e., EntityPlatform) to configure itself to
        # periodically call our async_update method any call to this method
        # during initializaton must return True. After that, for WU we'll
        # always poll, and for others we'll only need to poll during the ramp
        # up and down periods around sunrise and sunset, and then once more
        # when period is done to make sure ramping is completed.
        if not self._init_complete or self._using_wu:
            return True
        changing = 0 < self.sun_factor(dt_util.now()) < 1
        if changing:
            self._was_changing = True
            return True
        if self._was_changing:
            self._was_changing = False
            return True
        return False

to:

    @property
    def should_poll(self):
        return True

    @property
    def force_update(self):
        return True

Awesome, thanks! I just went ahead and changed the script, I’ll let you know if I see anything weird or not working properly.

As has been discussed, starting with HA 0.86, the folder layout in custom_components has changed. I’ve recently updated the installation instructions. custom_components.json (which is used by Custom Updater) has also been updated to be compatible with the new layout.

If you are installing this custom platform for the first time:

Then just follow the recently updated installation instructions

If you do not use Custom Updater, and are updating HA from before 0.86 to 0.86 or later:

Then you need to manually move/rename the file. The following Linux commands (or similar) should make the necessary changes:

# From config folder
cd custom_components
sudo -u homeassistant mkdir illuminance
sudo -u homeassistant mv sensor/illuminance.py illuminance/sensor.py

If you use Custom Updater, and are on a version of HA before 0.86:

Then you’ll need to update the following line in your configuration for custom_updater. Change:

  component_urls:
    - https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components.json

to:

  component_urls:
    - https://raw.githubusercontent.com/pnbruckner/homeassistant-config/master/custom_components_old.json

Once you update to HA 0.86 or later you should change it back.

If you use Custom Updater, and are on HA 0.86 or later:

Then you should be good to go. Just use the Custom Updater to install and/or update.

Note: You may need to clean up the old files after you install/update, if you care.

If anyone is wondering how to install this, the instructions are here . https://github.com/pnbruckner/homeassistant-config/blob/master/docs/custom_updater.md

Not sure if anyone else has upgraded to 0.89, but I did tonight and I’m getting this error:

Wed Mar 06 2019 20:41:44 GMT-0500 (Eastern Standard Time)

Error loading custom_components.illuminance.sensor. Make sure all dependencies are installed

Traceback (most recent call last): 
  File "/usr/src/app/homeassistant/loader.py", line 166, in _load_file 
    module = importlib.import_module(path) 
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module 
    return _bootstrap._gcd_import(name[level:], package, level) 
  File "&lt;frozen importlib._bootstrap&gt;", line 1006, in _gcd_import 
  File "&lt;frozen importlib._bootstrap&gt;", line 983, in _find_and_load 
  File "&lt;frozen importlib._bootstrap&gt;", line 967, in _find_and_load_unlocked 
  File "&lt;frozen importlib._bootstrap&gt;", line 677, in _load_unlocked 
  File "&lt;frozen importlib._bootstrap_external&gt;", line 728, in exec_module 
  File "&lt;frozen importlib._bootstrap&gt;", line 219, in _call_with_frames_removed 
  File "/config/custom_components/illuminance/sensor.py", line 25, in &lt;module&gt; 
    from homeassistant.components.sensor.yr import ( 
ImportError: cannot import name 'CONF_ATTRIBUTION' from 'homeassistant.components.sensor.yr' (/usr/src/app/homeassistant/components/sensor/yr.py)

I rolled back to 0.88.2 and everything was fine, so not sure what happened with YR.

You’re using a custom component. There’s a documented Breaking Change for custom components.

D’oh! I’ll try to fix that soon. Yet another ramification of the Great Migration.

EDIT: Hmm, this time it actually wasn’t the great migration. It was renaming CONF_ATTRIBUTION in sensor.yr to ATTRIBUTION, just like they did back in the 0.85 release with the Dark Sky Sensor.

Yeah, I’ve already changed the file structure, I have other custom components that are working fine, including @pnbruckner’s Life360 component. So I don’t think it’s that.

No worries man, was just hoping it wasn’t me. lol. Thanks for the great work you put into these components.

1 Like

got the same error

ERROR (MainThread) [homeassistant.loader] Error loading custom_components.illuminance.sensor. Make sure all dependencies are installed Traceback (most recent call last): File "/srv/homeassistant/lib/python3.6/site-packages/homeassistant/loader.py", line 166, in _load_file module = importlib.import_module(path) File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "&lt;frozen importlib._bootstrap&gt;", line 978, in _gcd_import File "&lt;frozen importlib._bootstrap&gt;", line 961, in _find_and_load File "&lt;frozen importlib._bootstrap&gt;", line 950, in _find_and_load_unlocked File "&lt;frozen importlib._bootstrap&gt;", line 655, in _load_unlocked File "&lt;frozen importlib._bootstrap_external&gt;", line 678, in exec_module File "&lt;frozen importlib._bootstrap&gt;", line 205, in _call_with_frames_removed File "/home/homeassistant/.homeassistant/custom_components/illuminance/sensor.py", line 25, in &lt;module&gt; from homeassistant.components.sensor.yr import ( ImportError: cannot import name 'CONF_ATTRIBUTION'

For latest release (just because I am not using it), it was required to disable the yr component integration

"""
from homeassistant.components.sensor.yr import (
    CONF_ATTRIBUTION as YRS_ATTRIBUTION)
"""

I was able to do that because I am using darksky.

This is the error in the logs I was facing:

2019-03-07 12:38:31 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.illuminance.sensor. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/home/ha/homeassistant/lib/python3.6/site-packages/homeassistant/loader.py", line 166, in _load_file
    module = importlib.import_module(path)
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/ha/.homeassistant/custom_components/illuminance/sensor.py", line 25, in <module>
    from homeassistant.components.sensor.yr import (
ImportError: cannot import name 'CONF_ATTRIBUTION'
2019-03-07 12:38:31 ERROR (MainThread) [homeassistant.loader] Unable to find platform illuminance.

For some reason they decided to rename CONF_ATTRIBUTION to ATTRIBUTION in PR #21069. Working on a fix.