home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.84k forks source link

MODBUS switch does not work reporting error #52496

Closed woniol closed 3 years ago

woniol commented 3 years ago

The problem

Hi I use Modbus integration to connect to my Sinclair AC using RS485 to eth module. I works with rtuovertcp connetion type. I use it with following platforms: climate, sensor and switch. Swich is used to turn the AC unit on/off. Since HA 2021.6.6 switch stopped to work. When I switch it for the UI I get following error in the logs: Pymodbus: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

What is version of Home Assistant Core has the issue?

core-2021.6.6

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Modbus

Link to integration documentation on our website

https://www.home-assistant.io/integrations/modbus/

Example YAML snippet

modbus:
  name: AC
  delay: 5
  timeout: 10
  type: rtuovertcp
  host: 192.168.0.7
  port: 1212
  climates:
    - name: AC Sinclair
      slave: 1
      data_type: uint
      data_count: 1
      scale: 1
      offset: 0
      precision: 1
      max_temp: 30
      min_temp: 16
      temp_step: 1
      target_temp_register: 20
      current_temp_register: 4
  switches:
    - name: AC Sinclair power
      slave: 1
      address: 2
      command_on: 170
      command_off: 85
      scan_interval: 5

Anything in the logs that might be useful for us?

Pymodbus: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)

Additional information

No response

probot-home-assistant[bot] commented 3 years ago

modbus documentation modbus source (message by IssueLinks)

probot-home-assistant[bot] commented 3 years ago

Hey there @adamchengtkc, @janiversen, @vzahradnik, mind taking a look at this issue as its been labeled with an integration (modbus) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

woniol commented 3 years ago

One more information. I works fine using service calls: `service: modbus.write_register data: unit: 1 address: 2 value:

janiversen commented 3 years ago

That is weird, because it should never reach your device.

woniol commented 3 years ago

It works fine with service call. but not with the switch defined.

janiversen commented 3 years ago

if you say so, but as you can see in the PR provided, the rtuovertcp protocol is never selected and host is set to “rtuovertcp”.

woniol commented 3 years ago

I've reported two issues. This one if related to core-2021.6.6 and is only about the switch. No connection problems “rtuovertcp” here. Connection problem with “rtuovertcp” is for core-2021.7 beta.

janiversen commented 3 years ago

one issue one report. Mixing issues is bad because it is impossible to keep track of. I did not see 2 issues and have only solved the rtuovertcp.

janiversen commented 3 years ago

but this one your device is not responding. And you need to provide a debug log to get more information. You miss verify: in your switch, otherwise it is write only.

woniol commented 3 years ago

There it is: 2021-07-04 22:36:12 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [547408144896] Received {'type': 'call_service', 'domain': 'switch', 'service': 'turn_on', 'service_data': {'entity_id': 'switch.ac_sinclair_power'}, 'id': 81} 2021-07-04 22:36:12 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=switch.ac_sinclair_power> 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.transaction] Current transaction state - TRANSACTION_COMPLETE 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.transaction] Running transaction 11 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.transaction] SEND: 0x1 0x6 0x0 0x2 0x0 0xaa 0xa8 0x75 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.framer.rtu_framer] Changing state to IDLE - Last Frame End - 1625430968.076678, Current Time stamp - 1625430972.377124 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.client.sync] New Transaction state 'SENDING' 2021-07-04 22:36:12 DEBUG (SyncWorker_11) [pymodbus.transaction] Changing transaction state from 'SENDING' to 'WAITING FOR REPLY' 2021-07-04 22:36:16 DEBUG (SyncWorker_11) [pymodbus.transaction] Transaction failed. (Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received)) 2021-07-04 22:36:16 DEBUG (SyncWorker_11) [pymodbus.framer.rtu_framer] Frame - [b''] not ready 2021-07-04 22:36:16 DEBUG (SyncWorker_11) [pymodbus.transaction] Getting transaction 1 2021-07-04 22:36:16 DEBUG (SyncWorker_11) [pymodbus.transaction] Changing transaction state from 'PROCESSING REPLY' to 'TRANSACTION_COMPLETE' 2021-07-04 22:36:16 ERROR (SyncWorker_11) [homeassistant.components.modbus.modbus] Pymodbus: Modbus Error: [Input/Output] Modbus Error: [Invalid Message] No response received, expected at least 2 bytes (0 received) 2021-07-04 22:36:16 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=switch.ac_sinclair_power, old_state=<state switch.ac_sinclair_power=off; friendly_name=AC Sinclair power @ 2021-07-04T22:35:16.574076+02:00>, new_state=<state switch.ac_sinclair_power=unavailable; friendly_name=AC Sinclair power @ 2021-07-04T22:36:16.385119+02:00>> 2021-07-04 22:36:16 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [547408144896] Sending {"id": 2, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "switch.ac_sinclair_power", "old_state": {"entity_id": "switch.ac_sinclair_power", "state": "off", "attributes": {"friendly_name": "AC Sinclair power"}, "last_changed": "2021-07-04T20:35:16.574076+00:00", "last_updated": "2021-07-04T20:35:16.574076+00:00", "context": {"id": "ae6fb5f8c5ffeed82e03f369a06c1843", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "switch.ac_sinclair_power", "state": "unavailable", "attributes": {"friendly_name": "AC Sinclair power"}, "last_changed": "2021-07-04T20:36:16.385119+00:00", "last_updated": "2021-07-04T20:36:16.385119+00:00", "context": {"id": "22f10c60868d7d68a20b91e9c38729f0", "parent_id": null, "user_id": "d1fa27bda57d41adb84d250346921626"}}}, "origin": "LOCAL", "time_fired": "2021-07-04T20:36:16.385119+00:00", "context": {"id": "22f10c60868d7d68a20b91e9c38729f0", "parent_id": null, "user_id": "d1fa27bda57d41adb84d250346921626"}}}

woniol commented 3 years ago

I think I managed to find the source of the problem: When dealing with switch single value is send to the device (modbus function code 0x06): In my case it is 170, which results in following data beeing send (log): SEND: 0x1 0x6 0x0 0x2 0x0 0xaa 0xa8 0x75 My device does not responde to that message.

When I use service call, I need to send array [170, 0] as value (modbus function code 0x10): SEND: 0x1 0x10 0x0 0x2 0x0 0x2 0x4 0x0 0xaa 0x0 0x0 0x52 0x56

I suppose it used to send 0x10 with switch before 2021.6. Would it be possible to define switch values for on and of as arrays maybe?

woniol commented 3 years ago

Isn't it something that should be controlled with write_type parameter in the switch config?