esphome/modbus_relay.yaml

23 lines
758 B
YAML

switch:
- platform: modbus_controller
modbus_controller_id: ${cid}
name: ${name}
register_type: holding
address: ${register_addr}
force_new_range: true
write_lambda: |-
bool open = (x == 1);
payload.push_back(${dev_addr}); // device address
payload.push_back(0x6); // write function
payload.push_back(0); // relay select
payload.push_back(${register_addr}); //
payload.push_back(open ? 0x01 : 0x02); // Command
payload.push_back(0x00);
return open;
#lambda: |-
# if(item->start_address == 0x07)
# {
# ESP_LOGW("relay_lambda", "addr %d | x=%d , (%d, %d)", item->start_address, x, data[item->offset + 0], data[item->offset + 1]);
# }
# return (x == 1);