esphome / esphome/feature-requests

Add Support for Writing Values to number Components from Modbus Masters

Open
#2,820 1 comment 9 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**

**Please describe your use case for this integration and alternatives you've tried:**

**Additional context**

Description:
Currently, ESPHome allows for reading values from Modbus slaves using number components, but does not support writing values to these components from Modbus masters. This feature would enable ESPHome to handle writes to number components, making it possible for Modbus masters to set values directly. This enhancement is essential for scenarios where ESPHome nodes need to receive and process input values from a Modbus master device.

Use Case:
In industrial and home automation setups, Modbus is a widely used protocol for communication between devices. Supporting write operations to number components would allow ESPHome to be more versatile in these environments. For example, an ESPHome node acting as a temperature controller could receive setpoints from a Modbus master, enabling it to adjust its operation dynamically based on external commands.

Proposed Implementation:

Extend Modbus Server Functionality:

Add a new configuration option under modbus_controller for number components that allows them to accept write commands from Modbus masters.
Implement a callback function that handles incoming Modbus write requests and updates the corresponding number component value.

Configuration Example:

uart:
id: uart_modbus
tx_pin: GPIO4
rx_pin: GPIO16
baud_rate: 9600

modbus:
id: modbus_server
uart_id: uart_modbus
role: server

modbus_controller:
id: modbus_device
modbus_id: modbus_server
address: 0x01
server_registers:
- address: 0x0003
value_type: U_WORD
lambda: |-
return id(modbus_setpoint).state;
write_lambda: |-
id(modbus_setpoint).publish_state(x);
return x;

number:
- platform: template
name: "Modbus Setpoint"
id: modbus_setpoint
min_value: 0
max_value: 100
step: 1
optimistic: true
update_interval: 1s

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the modbus_controller server_registers configuration and the number template example, focusing on the proposed write_lambda behavior for a server register. Review how incoming Modbus write requests are handled and how number component values are published. Done means a Modbus master can write the configured register and update the corresponding number component value.

Written by the indexing model from the issue text.

Assessment

Domain
embedded-iot, networking
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.