Custom component for Lightpack

I’ve been using this for years and thought I should share it. Support on/off, brightness and profile via effect. Does not support api keys yet as I don’t use the feature. Please let me know what features you are missing.

https://github.com/mihalski/homeassistant/blob/master/custom_components/light/lightpack.py

3 Likes

Thanks so much for this!
I’ve tried to implement it, however I’m having problems. How does one setup the config in HASS?
After adding the following to my lights.yaml, the switch turns on, but immediately turns off. The brightness slider works and I can only turn the lightpack off by dragging the slider to zero.
Your assistance would be much appreciated!

  - platform: lightpack
    host: !secret lightpack_host
    port: !secret lightpack_port

You’re very welcome!
That’s very odd behaviour that I’ve not seen before. Is anything else controlling Prismatik?

Try adding this to your configuration:

logger:
  logs:
    custom_components.light.lightpack: debug

And paste the logs for when this is happening.

Hi there,
I am running Prismatik on a Windows 10 machine using the latest build from https://github.com/psieg/Lightpack

Here is the log entry:

2018-09-09 01:01:45 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.lightpack fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 353, in async_device_update
    yield from self.hass.async_add_job(self.update)
  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/light/lightpack.py", line 197, in update
    self._mode = self._update.getMode()
AttributeError: 'Lightpack' object has no attribute 'getMode'

Oops!! That’s totally my fault!

getMode() is something I was testing that does not exist in the library I’m using. It should be hetProfile(). I’ve updated the repository.

Let me know if this fixes the problem for you.

Ok, I’ve updated the file and removed the cache folder, after rebooting and enabling debug logging, I receive the following:
After I switch on the Lightpack, it turns on, but the switch immediately turns off. I am on able to turn off by dragging the bightness slider to 0.

2018-09-10 18:56:54 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=light, service=turn_on, service_data=entity_id=light.lightpack>
2018-09-10 18:56:54 DEBUG (MainThread) [custom_components.light.lightpack] Lightpack: available(); result: True
2018-09-10 18:56:54 DEBUG (SyncWorker_4) [custom_components.light.lightpack] Lightpack: lock()
2018-09-10 18:56:54 DEBUG (SyncWorker_4) [custom_components.light.lightpack] Lightpack: turn_on()
2018-09-10 18:56:54 DEBUG (SyncWorker_4) [custom_components.light.lightpack] Lightpack: unlock()
2018-09-10 18:56:54 DEBUG (SyncWorker_19) [custom_components.light.lightpack] Lightpack: connect()
2018-09-10 18:56:54 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.lightpack fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 353, in async_device_update
    yield from self.hass.async_add_job(self.update)
  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/light/lightpack.py", line 198, in update
    brightness = self._update.getBrightness()
AttributeError: 'Lightpack' object has no attribute 'getBrightness'

Made some modifications to the update routine and added some extra debugging. Maybe this will reveal what’s going on?

https://transfer.sh/g8L15/lightpack.py

Hi Mihalski,
Thanks alot for your assistance with this!

I’m receiving the following error in my logs every 30 seconds:

2018-09-15 08:19:34 ERROR (MainThread) [homeassistant.helpers.entity] Update for light.lightpack fails
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
    yield from self.async_device_update()
  File "/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 353, in async_device_update
    yield from self.hass.async_add_job(self.update)
  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/light/lightpack.py", line 225, in update
    brightness = self._update.getBrightness()
AttributeError: 'Lightpack' object has no attribute 'getBrightness'

Are there maybe any specific options that need to be setup on the Prismatik side?

BTW, I’ve found that I can use the brightness slider to turn the Lightpack on and I’m able to adjust the brightness. If I drag the brightness slider to 0 the lightpack turns off. So its just the switch that I’m having issues with, but I see that in your code it is reliant on the brightness and effect attributes.
I’ve read that ATTR_BRIGHTNESS for the light entity isn’t really reliable since it can give null values. Dunno if that has anything to do with it? I’m not a programmer, so my input is probably utterly useless

could you please share your file again the link is down

thank you

I know it’s been a while, but in case you want a working component all you have to do is on line 203 I think just set it to brightness = 100 #self._update.getBrightness()

You’ll lose brightness control (but really I just care about on/off more than brightness. If I want it dim I’ll usually just have it off anyway), but gain everything else.

1 Like

How does one setup the config in HASS?

Please … where can I get this from? … the link is broken :frowning:

1 Like