Mysensors broken after last update

Hi,
just upgraded to 0.52.1 and now mysensors is broken.

I noticed the sensors were simply gone and removed the persistance file and restarted. Now I get this when a new sensor presents itself on the mysensors network:

2017-08-31 20:48:33 DEBUG (Thread-7) [mysensors.gateway_mqtt] Receiving 252;100;1;0;38;2.62319851
2017-08-31 20:48:33 DEBUG (Thread-13) [homeassistant.components.mysensors] Node update: node 252 child 100
2017-08-31 20:48:33 ERROR (Thread-13) [mysensors] 'ChildSensor' object has no attribute 'get_schema'
Traceback (most recent call last):
  File "/export/home/hacker/.homeassistant/deps/lib/python3.5/site-packages/mysensors/__init__.py", line 282, in alert
    self.event_callback(msg)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/mysensors.py", line 474, in mysensors_callback
    validated = validate_child(msg.gateway, msg.node_id, child)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/mysensors.py", line 409, in validate_child
    _child_schema = child.get_schema(gateway.protocol_version)
AttributeError: 'ChildSensor' object has no attribute 'get_schema'

Hmm, could be that pymysensors did not update for some reason. I used pip3 to upgrade it to 0.11, put back my persistence file and now the sensors show up again. However, they do not display any values. I get these warnings in my log file:

2017-08-31 21:20:51 DEBUG (Thread-8) [homeassistant.components.mysensors] Invalid values: {38: '2.90233374'}: sensor platform: node 1 child 100: S_MULTIMETER requires value_type V_CURRENT @ data[39]
2017-08-31 21:20:51 DEBUG (Thread-8) [homeassistant.components.mysensors] Invalid values: {38: '2.90233374'}: sensor platform: node 1 child 100: S_MULTIMETER requires value_type V_IMPEDANCE @ data[14]

I assume it means that I am failing the validation. But how should I present my sensors and send the values in order to pass validation?

If all of your sensors stop reporting, you’re hitting a bug that was fixed here, including workaround:

1 Like

Thanks! I’ll have a look later today and see if it resolves the issue.

Do I need to update pymysensors to 0.11.1?

1 Like

If you edit your persistence file and replace null values for protocol_version with the correct mysensors version of your sensors, that should avoid the bug.

The fix has been merged with dev branch and is tagged to go out in 0.52.2. But I don’t know when that will be released. The fix will not be able to determine the correct protocol_version on its own though. It will just fall back to version 1.4 if a non valid protocol_version is detected. To get the correct version, automatically, you have to present the affected sensors again after deleting the persistence file or removing those sensors from the file.

It worked when I fixed my persistence file to have the correct version. However, I now have another problem which seems to be related to validation. I send a message from my power meter (sensor type S_POWER) with value type V_KWH (type 17). This doesn’t seem to pass validation, even though it should, according to the mysensors documentation (e.g value type 17 is expected from a S_POWER sensor):

2017-09-02 23:41:55 DEBUG (Thread-8) [mysensors.gateway_mqtt] Receiving 227;1;1;0;17;6698.00000000
2017-09-02 23:41:55 DEBUG (Thread-13) [homeassistant.components.mysensors] Node update: node 227 child 1
2017-09-02 23:41:55 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {17: '6698.00000000'}: sensor platform: node 227 child 1: S_POWER requires value_type V_KWH @ data[18]
2017-09-02 23:41:55 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {17: '6698.00000000'}: sensor platform: node 227 child 1: S_POWER requires value_type V_VAR @ data[54]
2017-09-02 23:41:55 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {17: '6698.00000000'}: sensor platform: node 227 child 1: S_POWER requires value_type V_VA @ data[55]
2017-09-02 23:41:55 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {17: '6698.00000000'}: sensor platform: node 227 child 1: S_POWER requires value_type V_POWER_FACTOR @ data[56]
2017-09-02 23:41:55 INFO (Thread-4) [homeassistant.components.mysensors] Adding new devices: [<Entity Energy Meter 227 1: None>]
2017-09-02 23:41:55 DEBUG (Thread-5) [homeassistant.components.mysensors] Entity update: Energy Meter 227 1: value_type 17, value = 6698.00000000
2017-09-02 23:41:55 DEBUG (Thread-13) [mysensors] Handle queue with call <bound method Gateway.logic of MQTTGateway>(('227;1;1;0;17;6698.00000000',), {}) took 0.112 seconds

Also, I’m getting IndexError exceptions:

2017-09-03 00:05:16 DEBUG (Thread-6) [mysensors.gateway_mqtt] Receiving 227;1;1;0;18;575.01898193
2017-09-03 00:05:16 DEBUG (Thread-13) [homeassistant.components.mysensors] Node update: node 227 child 1
2017-09-03 00:05:16 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {24: '575019.00000000', 17: '6405.00000000', 18: '575.01898193'}: sensor platform: node 227 child 1: S_POWER require
s value_type V_VAR @ data[54]
2017-09-03 00:05:16 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {24: '575019.00000000', 17: '6405.00000000', 18: '575.01898193'}: sensor platform: node 227 child 1: S_POWER require
s value_type V_VA @ data[55]
2017-09-03 00:05:16 DEBUG (Thread-13) [homeassistant.components.mysensors] Invalid values: {24: '575019.00000000', 17: '6405.00000000', 18: '575.01898193'}: sensor platform: node 227 child 1: S_POWER require
s value_type V_POWER_FACTOR @ data[56]
2017-09-03 00:05:16 ERROR (Thread-13) [mysensors] pop index out of range
Traceback (most recent call last):
  File "/export/home/hacker/.homeassistant/deps/lib/python3.5/site-packages/mysensors/__init__.py", line 308, in alert
    self.event_callback(msg)
  File "/usr/local/lib/python3.5/dist-packages/homeassistant/components/mysensors.py", line 479, in mysensors_callback
    dev_ids.pop(idx)
IndexError: pop index out of range

Value type 17 is V_WATT, and seems to be reported fine for your sensor. You can see that the entity updates with that value. You can ignore the debug log for the failed validations if you don’t experience a problem.

The bug with IndexError has been fixed in the dev branch. It suggests you are reporting multiple measurements per child which is not really supported by home assistant.

See this thread on the same topic:

Aha, ok - but will be it supported going forward? The sensor worked fine until the 0.52 update so I’m assuming that HA had no problems with earlier.

No, I’m planning to disallow this in the future. It has been allowed previously but has not been without problems. Eg you will have a conflict between entity_ids which will lead them to being updated with an index before the entity is added. Since the order of entity addition is not fixed you can face problems with entities changing entity_id between restarts.

See example here: