Skip to content

Instantly share code, notes, and snippets.

@Bwooce
Last active January 31, 2024 19:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Bwooce/7c43622dcc9bc1fbb04d7a0f1e5528df to your computer and use it in GitHub Desktop.
Save Bwooce/7c43622dcc9bc1fbb04d7a0f1e5528df to your computer and use it in GitHub Desktop.
# Lilygo T-CAN485 v1.1 config, for an external ZTS-3000-I20-485 bridge with 1-2 submersible water level sensors
substitutions:
sensor1_maxdepth: "1" # first sensor, max depth in metres.
sensor2_maxdepth: "3" # ssecond sensor, max depth in metres.
adc_minvalid: "655" # The ZTS-3000-I20-485 "12 bit" ADC min value for the 4-20ma sensors
adc_maxvalid: "3276" # The ZTS-3000-I20-485 "12 bit" ADC max value for the 4-20ma sensors
ha_encryptionkey: "yourkeyhere"
cportal_password: "password"
esphome:
name: esphome-web-6d4f20
friendly_name: shed-stormwater
on_boot:
- priority: 90
then:
- output.turn_on: modbus_en # Enable, aka RE on the MAX13487E - Drive RE high to let the AutoDirection circuit control the receiver
- output.turn_on: modbus_se # Not sleep, aka SHDN (shutdown) on the MAX13487E
- output.turn_on: modbus_5v # Provide power to the modbus chip (MAX13487E)
esp32:
board: esp32dev
framework:
type: arduino
# Logging level
logger:
#level: VERBOSE
# Enable Home Assistant API
api:
encryption:
key: ${ha_encryptionkey}
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-6D4F20"
password: ${cportal_password}
captive_portal:
uart:
id: mod_uart
tx_pin: 22
rx_pin: 21
baud_rate: 4800 # The out-of-box baud rate for my particular sensor->RS485 bridge
stop_bits: 1
parity: NONE
data_bits: 8
# debug:
# direction: BOTH
# dummy_receiver: false
# after:
# delimiter: "\n"
# sequence:
# - lambda: UARTDebug::log_string(direction, bytes);
modbus:
id: modbus1
uart_id: mod_uart
modbus_controller:
- id: water
address: 0x1 ## address of the ModBUS slave device on the bus
modbus_id: modbus1
setup_priority: -10
sensor:
- platform: modbus_controller
modbus_controller_id: water
name: "Water Level 1"
id: water_level_1
register_type: holding
address: 0x0
unit_of_measurement: "cm"
device_class: "distance"
state_class: "measurement"
accuracy_decimals: 2
value_type: U_WORD
lambda: |-
//ESP_LOGI("","Lambda incoming value=%f - data array size is %d",x,data.size());
//ESP_LOGI("","Sensor properties: address = 0x%X, offset = 0x%X value type=%d",item->start_address,item->offset,item->sensor_value_type);
if (x < ${adc_minvalid} || isnan(x) || x > ${adc_maxvalid}) {
return NAN;
}
return esphome::remap(x, float(${adc_minvalid}), float(${adc_maxvalid}), 0.0f, float(${sensor1_maxdepth}) * 100.0f); // 100 = centimetres
- platform: modbus_controller
modbus_controller_id: water
name: "Water Level 2"
id: water_level_2
register_type: holding
address: 0x1
unit_of_measurement: "cm"
device_class: "distance"
state_class: "measurement"
accuracy_decimals: 2
value_type: U_WORD
lambda: |-
//ESP_LOGI("","Lambda incoming value=%f - data array size is %d",x,data.size());
//ESP_LOGI("","Sensor properties: address = 0x%X, offset = 0x%X value type=%d",item->start_address,item->offset,item->sensor_value_type);
if (x < ${adc_minvalid} || isnan(x) || x > ${adc_maxvalid}) {
return NAN;
}
return esphome::remap(x, float(${adc_minvalid}), float(${adc_maxvalid}), 0.0f, float(${sensor2_maxdepth}) * 100.0f); // 100 = centimetres
light:
- platform: esp32_rmt_led_strip
rgb_order: GRB # The correct ordering
pin: 4
num_leds: 1
rmt_channel: 0
chipset: ws2812
name: "Light"
# These could be implemented as inverted so they didn't need explict enablement above i.e. disabled = HIGH
output:
- platform: gpio
pin: 17
id: modbus_en
- platform: gpio
pin: 19
id: modbus_se
- platform: gpio
pin: 16
id: modbus_5v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment