Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modbus write_register accept single value and array #21621

Merged
merged 2 commits into from
Mar 10, 2019

Conversation

gertdb
Copy link
Contributor

@gertdb gertdb commented Mar 3, 2019

Description:

Updated voluptuous schema to accept single value and array. That way the correct function code modbus function code is called (0x06 for integer (single register), 0x10 for list (multiple registers)).

Related issue (if applicable): fixes #

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#8814

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

If user exposed functionality or configuration variables are added/changed:

@fabaff fabaff merged commit bab53a1 into home-assistant:dev Mar 10, 2019
@ghost ghost removed the in progress label Mar 10, 2019
@fucm
Copy link
Contributor

fucm commented Mar 10, 2019

@fabaff Just recognised, that this merge creates an exception (<unknown>): did not find expected ',' or '}' while parsing a flow mapping at line 12 column 12 . You can paste the services.yaml into a yaml checker to see the same error. The range needs to be represented differently. example: 0 or [4,0]} could be changed to example: 0 or 4..0}.
I guess a new PR is required?

@gertdb
Copy link
Contributor Author

gertdb commented Mar 10, 2019

Sorry, don’t know how I overlooked this. Forgot double quotes, change to example: "0 or [4,0]"} will fix this. New PR needed?

@MartinHjelmare
Copy link
Member

Yes, a new PR is needed since this PR is merged.

@gertdb gertdb mentioned this pull request Mar 11, 2019
2 tasks
@gertdb
Copy link
Contributor Author

gertdb commented Mar 11, 2019

Ok, just created PR #21923 to fix this.

@balloob balloob mentioned this pull request Mar 20, 2019
@wellsy57
Copy link

Using 0.90.0 I have several automations using Input Number's to write to registers. These have all been working fine using @Monkey-House multiple modbus hub workaround and @gertdb fix (to write to single values) which became incorporated to 0.90.0 recently.
To make this new inbuilt system work I have modified the automations like:

- id: IrrigationShadehouseSetpoint
  alias: Irrigation Shadehouse Setpoint
  trigger:
    platform: state
    entity_id: input_number.slider3
  action:
    service: modbus.write_register
    data_template:
      hub: hub1
      unit: 3
      address: 3079
      value: "{{ states.input_number.slider3.state|int }}"

Also my config is all up and running now (with no trouble at all for modbus sensors, modbus binary sensors and modbus switches) for multiple modbus hubs using:

modbus:
  - name: hub5
    type: tcp
    host: MyIP
    port: 5003
    
  - name: hub3
    type: tcp
    host: MyIP
    port: 5001
    
  - name: hub1
    type: tcp
    host: MyIP
    port: 5002

However I now get this error in my logs when I try to set the register value with input number:

Sat Mar 30 2019 15:58:42 GMT+1000 (Australian Eastern Standard Time)
Error while executing automation automation.irrigation_start_time. Unknown error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/components/automation/__init__.py", line 381, in action
    await script_obj.async_run(variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 131, in async_run
    await self._handle_action(action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 210, in _handle_action
    action, variables, context)
  File "/usr/src/app/homeassistant/helpers/script.py", line 299, in _async_call_service
    context=context
  File "/usr/src/app/homeassistant/helpers/service.py", line 88, in async_call_from_config
    domain, service_name, service_data, blocking=blocking, context=context)
  File "/usr/src/app/homeassistant/core.py", line 1138, in async_call
    self._execute_service(handler, service_call))
  File "/usr/src/app/homeassistant/core.py", line 1162, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/modbus/__init__.py", line 149, in write_register
    hub_collect[client_name].write_register(
KeyError: 'default'

Is there something I have missed in my config or automation changes?
Cheers in advance for any help with this problem!

@MartinHjelmare
Copy link
Member

Please open an issue if you suspect a bug. If you need help please use our help channels:
https://home-assistant.io/help/#communication-channels

Merged PRs should not be used for support or bug reports. Thanks!

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Mar 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants