Kane610/deconz

Misreading xy_color from API

Closed this issue · 10 comments

The data in HA seems to be off for some entities:

{
  "brightness": 126,
  "xy_color": [
    29035,
    0.406578
  ],
  "effect_list": [
    "colorloop"
  ],
  "rgb_color": [
    255,
    0,
    0
  ],
  "friendly_name": "Panthella",
  "supported_features": 125
}

Compared to the deconz API:

{
  "ctmax": 454,
  "ctmin": 250,
  "etag": "dcf18ae24dbc407e045999a588772d13",
  "hascolor": true,
  "manufacturername": "IKEA of Sweden",
  "modelid": "TRADFRI bulb E27 CWS opal 600lm",
  "name": "Panthella",
  "state": {
    "alert": "none",
    "bri": 126,
    "colormode": "xy",
    "effect": "none",
    "hue": 0,
    "on": true,
    "reachable": true,
    "sat": 0,
    "xy": [
      0.444783,
      0.406578
    ]
  },
  "swversion": "1.3.002",
  "type": "Color light",
  "uniqueid": "00:0b:57:ff:fe:9c:2f:f5-01"
}

Please enable debug through the logger component and give me some printouts from the creation of the light and some updates over the web socket.

What should I put as log level? I don't get anything with this:

logger:
  default: warning
  logs:
    homeassistant.components.deconz: debug

Except from this:

2018-03-13 10:50:37 DEBUG (MainThread) [homeassistant.components.deconz] deCONZ config {'api_key': 'xxxxxxxxxx', 'host': '192.168.x.x', 'port': 80}
2018-03-13 10:50:37 WARNING (MainThread) [pydeconz.sensor] Unsupported sensor type ZHAPower (Plug)
2018-03-13 13:14:43 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback _SelectorSocketTransport._read_ready()
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 731, in _read_ready
    self._protocol.data_received(data)
  File "/srv/homeassistant/lib/python3.6/site-packages/pydeconz/websocket.py", line 98, in data_received
    self.async_callback(payload)
  File "/srv/homeassistant/lib/python3.6/site-packages/pydeconz/__init__.py", line 159, in async_event_handler
    self.sensors[event['id']].async_update(event)
AttributeError: 'NoneType' object has no attribute 'async_update'
2018-03-13 14:51:03 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback _SelectorSocketTransport._read_ready()
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/events.py", line 126, in _run
    self._callback(*self._args)
  File "/usr/local/lib/python3.6/asyncio/selector_events.py", line 731, in _read_ready
    self._protocol.data_received(data)
  File "/srv/homeassistant/lib/python3.6/site-packages/pydeconz/websocket.py", line 98, in data_received
    self.async_callback(payload)
  File "/srv/homeassistant/lib/python3.6/site-packages/pydeconz/__init__.py", line 159, in async_event_handler
    self.sensors[event['id']].async_update(event)
AttributeError: 'NoneType' object has no attribute 'async_update'

Though I do see some inconsistent behaviour with the xy_color in HA:

{
  "brightness": 126,
  "xy_color": [
    29035,
    26541
  ],
  "effect_list": [
    "colorloop"
  ],
  "rgb_color": [
    253,
    169,
    0
  ],
  "friendly_name": "Panthella",
  "supported_features": 125
}

and

{
  "brightness": 126,
  "xy_color": [
    0.444783,
    0.406578
  ],
  "effect_list": [
    "colorloop"
  ],
  "rgb_color": [
    214,
    177,
    108
  ],
  "friendly_name": "Panthella",
  "supported_features": 125
}

That error has got to do with unsupported sensor types so nothing related to lights..

change warning to debug since we don't really know what triggers the issue
Or if you want to start small you can add
logs:
pydeconz: debug
homeassistant.components.deconz: debug

Nothing weird for now. As you can see above, the error seems to be occasional..

2018-03-13 21:09:47 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella created as {'_alert': 'none', '_bri': 31, '_colormode': 'xy', '_ct': None, '_effect': 'none', '_hue': 0, '_on': True, '_reachable': True, '_sat': 0, '_x': 0.444783, '_y': 0.406578, '_async_set_state_callback': <bound method DeconzSession.async_put_state of <pydeconz.DeconzSession object at 0xa916ba50>>, '_deconz_id': '/lights/3', '_etag': 'edd527da96bde1bc2ba64bce51c70f1a', '_manufacturername': 'IKEA of Sweden', '_modelid': 'TRADFRI bulb E27 CWS opal 600lm', '_name': 'Panthella', '_swversion': '1.3.002', '_type': 'Color light', '_uniqueid': '00:0b:57:ff:fe:9c:2f:f5-01', '_async_callback': []}
2018-03-13 21:16:02 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 20414
2018-03-13 21:16:02 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 21478

You should get a web socket call just above those update lines, can you dig them out?

2018-03-13 21:30:44 DEBUG (MainThread) [pydeconz.utils] Sending {'data': '{"on": true, "xy": [0.4448, 0.4066], "bri": 240}'} to http://192.168.x.x:80/api/xxxxxxxxxx/lights/3/state
2018-03-13 21:30:44 DEBUG (MainThread) [pydeconz.utils] HTTP request response: [{'success': {'/lights/3/state/on': True}}, {'success': {'/lights/3/state/bri': 240}}, {'success': {'/lights/3/state/xy': [0.4448, 0.4066]}}]
2018-03-13 21:30:45 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"bri":240},"t":"event"}\x81E{"e":"changed","id":"3","r":"lights","state":{"x":29036},"t":"event"}\x81E{"e":"changed","id":"3","r":"lights","state":{"y":26542},"t":"event"}'
2018-03-13 21:30:45 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update bri with 240
2018-03-13 21:30:45 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 29036
2018-03-13 21:30:45 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 26542

Great! So we can verify that this is indeed some kind of error, but it is part of deconz so you need to create and issue with them.

Not sure if related - but the websocket seems to get spammed when calling a scene with a Trådfri bulb included:

2018-03-13 21:36:33 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":32378},"t":"event"}'
2018-03-13 21:36:33 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 32378
2018-03-13 21:36:33 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":16580},"t":"event"}'
2018-03-13 21:36:33 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 16580
2018-03-13 21:37:00 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":24927},"t":"event"}'
2018-03-13 21:37:00 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 24927
2018-03-13 21:37:00 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":13744},"t":"event"}'
2018-03-13 21:37:00 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 13744
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":25340},"t":"event"}'
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 25340
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":32853},"t":"event"}'
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 32853
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":23452},"t":"event"}'
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 23452
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":34152},"t":"event"}'
2018-03-13 21:37:01 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 34152
2018-03-13 21:37:03 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":23843},"t":"event"}'
2018-03-13 21:37:03 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 23843
2018-03-13 21:37:03 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":35784},"t":"event"}'
2018-03-13 21:37:03 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 35784
2018-03-13 21:37:04 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":19334},"t":"event"}'
2018-03-13 21:37:04 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 19334
2018-03-13 21:37:04 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":38271},"t":"event"}'
2018-03-13 21:37:04 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 38271
2018-03-13 21:37:06 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":11161},"t":"event"}'
2018-03-13 21:37:06 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 11161
2018-03-13 21:37:06 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81D{"e":"changed","id":"3","r":"lights","state":{"y":8845},"t":"event"}'
2018-03-13 21:37:06 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 8845
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":19334},"t":"event"}'
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 19334
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"y":38271},"t":"event"}'
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 38271
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":11161},"t":"event"}\x81D{"e":"changed","id":"3","r":"lights","state":{"y":8845},"t":"event"}'
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 11161
2018-03-13 21:37:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 8845
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81D{"e":"changed","id":"3","r":"lights","state":{"bri":31},"t":"event"}'
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update bri with 31
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81E{"e":"changed","id":"3","r":"lights","state":{"x":29035},"t":"event"}\x81E{"e":"changed","id":"3","r":"lights","state":{"y":26541},"t":"event"}'
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update x with 29035
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.deconzdevice] Panthella: update y with 26541
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz.websocket] Websocket data: b'\x81B{"e":"scene-called","gid":"2","r":"scenes","scid":"5","t":"event"}'
2018-03-13 21:38:07 DEBUG (MainThread) [pydeconz] Not supported event {'e': 'scene-called', 'gid': '2', 'r': 'scenes', 'scid': '5', 't': 'event'}

Is it with a transition? that would explain the spamming.

Lets close this one and open one with deconz. You can reference this issue to keep history

Yes, it is a transition for a group of 5 bulbs (4 Hues and 1 Trådfri). But it seems that only the Trådfri is spamming the log.