Need some feedback on using a custom command.
My heat pump has a special modbus implementation where some registers can only be read using a dummy 0x06 write function. The read is thus by using the echo returning the register value.
The question is thus, does custom command using a 0x06 fc return the modbus_response back for me to use a lambda sequence to extract the register value?
You can down and dirty in the lambda
lambda: |-
auto new_address = 0x03;
if(new_address < 0x01 || new_address > 0xF7) // sanity check
{
ESP_LOGE("ModbusLambda", "Address needs to be between 0x01 and 0xF7");
return;
}
esphome::modbus_controller::ModbusController *controller = id(pzem);
auto set_addr_cmd = esphome::modbus_controller::ModbusCommandItem::create_write_single_command(
controller, 0x0002, new_address);
delay(200) ;
controller->queue_command(set_addr_cmd);
ESP_LOGI("ModbusLambda", "PZEM Addr set");
This is from the pzem 004 integration and how to set it’s address when using multiple sensors on a single UART. You get the gist though, you can write a command and (hopefully) set a var to the response then return the response.
Never tried, but I would expect so.
In case it doesn’t you can get the response from uart debug.