Modbus sensor fails in 0.45

Hi, I have a problem with modbus switches and sensors, after upgrading to 0.46. Downgrading to 0.45.1 solves it for now.
Error log for an example entity as below, config:

modbus: { type: serial, method: rtu, port: /dev/ttyAMA0, baudrate: 115200, stopbits: 1, bytesize: 8, parity: N }

switch Lampy:
  platform: modbus
  slave: 1
  coils:
[...]
    - { name: Lampa Lazienka dol,         slave: 1, coil: 38 }
    - { name: Lampa Lazienka dol lustro,  slave: 1, coil: 39 }

Any suggestions?
Kind regards

Jun 05 06:44:53 raspberrypi hass[10545]: ERROR:homeassistant.helpers.entity:Update for switch.lampa_lazienka_dol fails
Jun 05 06:44:53 raspberrypi hass[10545]: Traceback (most recent call last):
Jun 05 06:44:53 raspberrypi hass[10545]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 224, in async_update_ha_state
Jun 05 06:44:53 raspberrypi hass[10545]: yield from self.hass.async_add_job(self.update)
Jun 05 06:44:53 raspberrypi hass[10545]: File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
Jun 05 06:44:53 raspberrypi hass[10545]: yield self  # This tells Task to wait for completion.
Jun 05 06:44:53 raspberrypi hass[10545]: File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
Jun 05 06:44:53 raspberrypi hass[10545]: value = future.result()
Jun 05 06:44:53 raspberrypi hass[10545]: File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
Jun 05 06:44:54 raspberrypi hass[10545]: raise self._exception
Jun 05 06:44:54 raspberrypi hass[10545]: File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
Jun 05 06:44:54 raspberrypi hass[10545]: result = self.fn(*self.args, **self.kwargs)
Jun 05 06:44:54 raspberrypi hass[10545]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/switch/modbus.py", line 73, in update
Jun 05 06:44:54 raspberrypi hass[10545]: result = modbus.HUB.read_coils(self._slave, self._coil, 1)
Jun 05 06:44:54 raspberrypi hass[10545]: File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/modbus.py", line 158, in read_coils
Jun 05 06:44:54 raspberrypi hass[10545]: **kwargs)
Jun 05 06:44:54 raspberrypi hass[10545]: File "/home/homeassistant/.homeassistant/deps/pymodbus/client/common.py", line 43, in read_coils
Jun 05 06:44:54 raspberrypi hass[10545]: return self.execute(request)
Jun 05 06:44:54 raspberrypi hass[10545]: File "/home/homeassistant/.homeassistant/deps/pymodbus/client/sync.py", line 84, in execute
Jun 05 06:44:54 raspberrypi hass[10545]: return self.transaction.execute(request)
Jun 05 06:44:54 raspberrypi hass[10545]: File "/home/homeassistant/.homeassistant/deps/pymodbus/transaction.py", line 98, in execute
Jun 05 06:44:54 raspberrypi hass[10545]: _logger.debug("recv: " + " ".join([hex(ord(x)) for x in result]))
Jun 05 06:44:54 raspberrypi hass[10545]: File "/home/homeassistant/.homeassistant/deps/pymodbus/transaction.py", line 98, in <listcomp>
Jun 05 06:44:54 raspberrypi hass[10545]: _logger.debug("recv: " + " ".join([hex(ord(x)) for x in result]))
Jun 05 06:44:54 raspberrypi hass[10545]: TypeError: ord() expected string of length 1, but int found

Same here…
Removing the ord( ) call in line 98 in “hass config dir”/deps/pymodbus/transaction.py should fix this

    _logger.debug("recv: " + " ".join([hex(ord(x)) for x in result]))

in

    _logger.debug("recv: " + " ".join([hex(x) for x in result]))
1 Like

This fixed it for me. Thank you for posting this!

1 Like

This is still a problem in version 0.48. I’ve submitted an issue on github so hopefully they fix this and we don’t have to do this after every new release.