Dzień dobry wszystkim.
Od jakiegoś czasu walczę z czujnikiem poziomu z Ali.
Podłączyłem to do nodeMCU z esp32 przez adapter rs485 → ttl i staram się zmusić to do działania ale bez skutku. Dodam, że jest to moja pierwsza styczność z modbus.
Znalazłem na zagranicznych forach kod yaml do esphome - ktoś to uruchomił z powodzeniem jednak mi nie idzie
Tak to podłączyłem:
Kod:
sensor:
# Reports how long the device has been powered (in minutes)
- platform: uptime
name: Uptime
filters:
- lambda: return x / 60.0;
unit_of_measurement: minutes
- platform: uptime
id: uptime_s
name: $device_name - Uptime
# WiFi Signal sensor.
- platform: wifi_signal
id: wifi_signal_db
name: $device_name - WiFi Signal
update_interval: 10s
- platform: copy # Reports the WiFi signal strength in %
source_id: wifi_signal_db
name: "$device_name - WiFi Signal Percent"
filters:
- lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
unit_of_measurement: "%"
entity_category: "diagnostic"
# water level sensor
# https://esphome.io/components/sensor/modbus_controller.html
- platform: modbus_controller
modbus_controller_id: qd
name: "Water level"
id: modbus_water_level
custom_command: [ 0x01, 0x03, 0x00, 0x04, 0x00, 0x01, 0xC5, 0xCB]
unit_of_measurement: "cm"
value_type: S_WORD
- platform: modbus_controller
modbus_controller_id: qd
name: “water tan address change”
id: tan_address_change
custom_command: [ 0x01, 0x03, 0x00, 0x04, 0x00, 0x01, 0xC5, 0xCB]
value_type: U_WORD
# Reports the WiFi signal strength
- platform: wifi_signal
name: Wifi Signal
update_interval: 60s
text_sensor:
- platform: version
name: ESPHome Version
- platform: wifi_info
ip_address: # exposes the IP Address when connected
internal: true
id: wifi_ip_addr
name: "IP Address"
- platform: version
name: $device_name - ESPHome Version
# Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
name: $device_name - IP
update_interval: 10s
ssid:
name: $device_name - SSID
update_interval: 10s
bssid:
name: $device_name - BSSID
update_interval: 10s
- platform: template
name: $device_name - uptime
lambda: |-
uint32_t dur = id(uptime_s).state;
int dys = 0;
int hrs = 0;
int mnts = 0;
if (dur > 86399) {
dys = trunc(dur / 86400);
dur = dur - (dys * 86400);
}
if (dur > 3599) {
hrs = trunc(dur / 3600);
dur = dur - (hrs * 3600);
}
if (dur > 59) {
mnts = trunc(dur / 60);
dur = dur - (mnts * 60);
}
char buffer[17];
sprintf(buffer, "%ud %02uh %02um %02us", dys, hrs, mnts, dur);
return {buffer};
icon: mdi:clock-start
uart:
id: mod_bus
tx_pin: GPIO17
rx_pin: GPIO18
baud_rate: 9600
data_bits: 8
stop_bits: 1
parity: NONE
debug:
modbus:
id: modbus1
uart_id: mod_bus
send_wait_time: 500ms
modbus_controller:
- id: qd
address: 0x01
modbus_id: modbus1
setup_priority: -10
update_interval: 5s
dodatkowo mam dokumentację pdf od producenta.
Na adapterze miga dioda TX ale niczego nie odbieram. Dodam, że jest to już drugi czujnik