Dear HA enthusiasts,
i need your trustable support on the following topic/project.
Currently i am trying to control my DPM8624 DCDC via Modbus using ESPHome and an ESP32. So far i managed to read out all the data and write a fixed value to the DPM using the “write_multiple_command”.
Now i would like to control it via HA. Therefore the plan is to create a sensor in HA, where i can e.g. define an output voltage for the DPM. This value shall then be transfered from HA → ESP32 → DPM.
But here is the point where i am a bit lost.
My .yaml looks like this:
uart:
id: mod_bus
tx_pin: 17
rx_pin: 16
baud_rate: 9600
stop_bits: 1
parity: none
modbus:
id: modbus1
uart_id: mod_bus
modbus_controller:
- id: epever
address: 0x1
modbus_id: modbus1
command_throttle: 1000ms
update_interval: 10s
setup_priority: -10
sensor:
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Set Voltage"
id: dpm_set_voltage
register_type: holding
address: 0x0000
unit_of_measurement: "V"
accuracy_decimals: 2
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Set Current"
id: dpm_set_current
register_type: holding
address: 0x0001
unit_of_measurement: "A"
accuracy_decimals: 2
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Output Voltage"
id: dpm_output_voltage
register_type: holding
address: 0x1001
unit_of_measurement: "V"
accuracy_decimals: 2
filters:
- multiply: 0.01
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Output Current"
id: dpm_output_current
register_type: holding
address: 0x1002
unit_of_measurement: "A"
accuracy_decimals: 2
filters:
- multiply: 0.001
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Temperature"
id: dpm_temperature
register_type: holding
address: 0x1003
unit_of_measurement: "°C"
accuracy_decimals: 1
- platform: modbus_controller
modbus_controller_id: epever
name: "DPM Out Switch"
id: dpm_out_switch
register_type: holding
address: 0x0002
- platform: modbus_controller
modbus_controller_id: epever
name: "Write DPM Output Voltage"
id: DPM_set_output_voltage
register_type: holding
address: 0x0000
on_value:
then:
- lambda: |-
esphome::modbus_controller::ModbusController *controller = id(epever);
std::vector<uint16_t> VOut = {3590};
esphome::modbus_controller::ModbusCommandItem set_output_voltage_command =
esphome::modbus_controller::ModbusCommandItem::create_write_multiple_command(controller, 0x0000, VOut.size(), id(VOut).state);
epever->queue_command(set_output_voltage_command);
The idea now is to create a variable “Vout” which is used in the “write_multiple_command” and is updated from the value received from HA.
Could it look like this?
globals:
- id: VOut
type: int
sensor:
- platform: mqtt_subscribe
name: "set output voltage command"
id: mqtt_dpm_set_output_voltage
topic: dpm-8624/number/dpm_set_output_voltage
on_value:
then:
- globals.set:
id: VOut
value: !lambda |-
return id;
It does not work like this, because i guess i did something wrong
Could you please provide me with some feedback? I would highly appreciate any help, since i have tried already since couple days and did not get any further.
Additionally, might there be a “better” way? I know that there are always many ways to go.
Thank you very much!
Felix