I’m trying to setup QwikSwitch but i get the following errors in the log.
The sample had three spaces before the url which I made two based on the setup/config guide. I also tried removing the quotes around the url itself.
The latter errors are where I was switching a device on and off to see if that is what is needed to get it displayed in the home screen.
16-05-22 21:30:58 homeassistant.components.light: Error while setting up platform qwikswitch
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 109, in _setup_platform
discovery_info)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/components/light/qwikswitch.py”, line 34, in setup_platform
add_devices([dev])
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 166, in add_entities
if self.component.add_entity(entity, self):
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py”, line 136, in add_entity
entity.update_ha_state()
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 147, in update_ha_state
state = STATE_UNKNOWN if self.state is None else str(self.state)
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/helpers/entity.py”, line 232, in state
return STATE_ON if self.is_on else STATE_OFF
File “/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/homeassistant/components/qwikswitch.py”, line 65, in is_on
return self._value > 0
TypeError: unorderable types: str() > int()
This is most probably because some devices were not recognized as relays or switches, Pyqwikswitch library v0.3 returns a value between 0-100 for known devices, but for unknown currently just passes the string value through. I will add some checks to handle these cases better.
legacy_status might be a way to decode it any packet. Not sure if switching the value will work then
HI guys
On initial setup of the qwikswitch plugin it seemed to work okay.
running on ubuntu 14.04 with homebridge and home assistant.
No after a few reboots and no changes the light test dimmer i have hooked up only turns on and fails to turn off
I get this error on switching off:
16-06-08 11:20:48 INFO (ThreadPool Worker 15) [urllib3.connectionpool] Starting new HTTP connection (1): 127.0.0.1
16-06-08 11:20:48 ERROR (ThreadPool Worker 15) [homeassistant.core] BusHandler:Exception doing job
Traceback (most recent call last):
File “/home/eel/.homeassistant/deps/pyqwikswitch/init.py”, line 229, in _decode_value
val = (120-int(qsval[-2:], 16))/1.2
ValueError: invalid literal for int() with base 16: ‘0%’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 809, in job_handler
func(arg)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 663, in _execute_service
service(call)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/core.py”, line 522, in call
self.func(call)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/components/light/init.py”, line 240, in handle_light_service
light.turn_on(**params)
File “/usr/local/lib/python3.4/dist-packages/homeassistant/components/qwikswitch.py”, line 80, in turn_on
if self._qsusb.set(self._id, round(min(newvalue, 255)/2.55)) >= 0:
File “/home/eel/.homeassistant/deps/pyqwikswitch/init.py”, line 200, in set
return self._decode_value(qs_id, set_result[‘data’])
File “/home/eel/.homeassistant/deps/pyqwikswitch/init.py”, line 234, in _decode_value
{}: {}’’’.format(qs_id, val[-2:]))
UnboundLocalError: local variable ‘val’ referenced before assignment
16-06-08 11:20:48 INFO (Thread-3) [urllib3.connectionpool] Starting new HTTP connection (1): 127.0.0.1
16-06-08 11:20:48 INFO (Thread-2) [urllib3.connectionpool] Starting new HTTP connection (1): 127.0.0.1
16-06-08 11:20:48 ERROR (Thread-3) [homeassistant.components.qwikswitch] Exception in qwikswitch callback
Type: <class ‘UnboundLocalError’>
Message: local variable ‘val’ referenced before assignment
There is also a regular timeout to the script:
16-06-08 11:21:53 ERROR (Thread-2) [homeassistant.components.qwikswitch] <class ‘socket.timeout’>timed out
So my Python guru made a few changes and now its working:
def _decode_value(self, qs_id, qsval):
"""Encode value to be passed to QSUSB."""
qstype = self._types.get(qs_id, '')
self._log('qsval = %s' % qsval)
if qstype == QSType.relay:
return 0 if qsval == 'OFF' else \
100 if qsval == 'ON' else \
legacy_status(qsval)
elif qstype == QSType.dimmer and len(qsval) > 2:
# if we're dealing with a percentage value here
if qsval[-1] == '%':
val = (120 - int(qsval.rstrip('%')[-2:])) / 1.2
else:
try:
val = (120-int(qsval[-2:], 16))/1.2
# Adjust dimmer exponentially to get a smoother effect
val = round(math.pow(val, self._dim_adj))
except ValueError:
self._log('''Unable to convert hex value in QS dimmer data
{}: {}'''.format(qs_id, val[-2:]))
return -1
return min(val, 100)
return legacy_status(qsval)
Hi @eel69, sorry I missed your post. The pyqwikswitch v0.4 library included from homeassistant 0.21 (8 June) should fix this error. It relies mostly on legacy_status