Having some issues with getting lux out of a philips hue sensor

Hi
I keep getting an empty dict instead of a lux reading. so I wonder what I’m doing wrong.

This is what I do.

luxsensor = self.args["lux_sensor"]
self.log("Lux sensor:")
self.log(luxsensor)
light_level = self.get_state(luxsensor)
self.log("Light level:")
self.log(light_level)
if float(light_level) < self.defaultLightLevelThreshold:
    self.log("Lux light level is below the default light threshold")

what am I doing wrong ?
my output is always this:

2020-02-01 14:22:27.174523 INFO LuxSensorTest: Lux sensor:
2020-02-01 14:22:27.174722 INFO LuxSensorTest: [‘sensor.hue_sensor_illuminance’]
2020-02-01 14:22:27.175894 WARNING AppDaemon: ------------------------------------------------------------
2020-02-01 14:22:27.176019 WARNING AppDaemon: Unexpected error in worker for App LuxSensorTest:
2020-02-01 14:22:28.068878 WARNING AppDaemon: ------------------------------------------------------------
2020-02-01 14:22:28.069234 WARNING AppDaemon: Traceback (most recent call last):
File “/usr/lib/python3.8/site-packages/appdaemon/appdaemon.py”, line 594, in worker
funcref(entity, attr, old_state, new_state,
File “/config/appdaemon/apps/LuxSensorTest.py”, line 27, in LuxSensorTest
if float(light_level) < self.defaultLightLevelThreshold:
TypeError: float() argument must be a string or a number, not ‘dict’

I have also been trying to do both of the following:

light_level = self.get_state(luxsensor,attribute="illuminance")
light_level = self.get_state(luxsensor,attribute="lux")

the result just changes to the following instead:

ValueError: LuxSensorTest: Invalid entity ID: None

so what am I doing wrong ?

Well I tried to update to latest Appdaemon 4.x and the error message now changed to this

File “/config/appdaemon/apps/LuxSensorTest.py”, line 24, in LuxSensorTest
light_level = self.get_state(luxsensor)
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 1310, in get_state
return await self.AD.state.get_state(
File “/usr/lib/python3.8/site-packages/appdaemon/state.py”, line 351, in get_state
domain = entity_id.split(“.”, 1)[0]
AttributeError: ‘list’ object has no attribute ‘split’

You are passing the lux_sensor as a list to the app. Remove the brackets around ‘sensor.hue_sensor_illuminance’ in your yaml config file.

1 Like

boy I feel silly now that was such a simple issue

No need to feel silly, be happy that you got it to work :slight_smile:

I recommend naming variables like this default_light_level_threshold instead of defaultLightLevelThreshold, according to PEP8.

1 Like

yea still trying to get rid of my habits from the other languages I’ve learned. but thanks for reminding me. that I should use the PEP8 naming convention

1 Like