Created
July 17, 2023 00:32
-
-
Save Elwell/3a5c20647895ea75aea7200b71426972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
esphome: | |
name: epever | |
friendly_name: epever | |
esp8266: | |
board: d1_mini | |
framework: | |
version: recommended | |
wifi: | |
ssid: !secret wifi_ssid | |
password: !secret wifi_password | |
fast_connect: true | |
api: | |
ota: | |
web_server: | |
port: 80 | |
status_led: | |
pin: | |
number: D4 | |
inverted: true | |
# Disable logging so we can use hardware UART | |
logger: | |
level: INFO | |
baud_rate: 0 | |
uart: | |
id: mod_bus | |
tx_pin: TX | |
rx_pin: RX | |
baud_rate: 115200 | |
stop_bits: 1 | |
modbus: | |
flow_control_pin: D1 | |
id: modbus1 | |
send_wait_time: 200ms | |
modbus_controller: | |
- id: epever | |
## the Modbus device addr | |
address: 0x1 | |
modbus_id: modbus1 | |
setup_priority: -10 | |
command_throttle: 200ms | |
update_interval: 30s | |
text_sensor: | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
name: "rtc_clock" | |
id: rtc_clock | |
internal: true | |
register_type: holding | |
address: 0x9013 | |
register_count: 3 | |
raw_encode: HEXBYTES | |
response_size: 6 | |
# /* | |
# E20 Real time clock 9013 D7-0 Sec, D15-8 Min | |
# E21 Real time clock 9014 D7-0 Hour, D15-8 Day | |
# E22 Real time clock 9015 D7-0 Month, D15-8 Year | |
# */ | |
on_value: | |
then: | |
- lambda: |- | |
ESP_LOGV("main", "decoding rtc hex encoded raw data: %s", x.c_str()); | |
uint8_t h=0,m=0,s=0,d=0,month_=0,y = 0 ; | |
m = esphome::modbus_controller::byte_from_hex_str(x,0); | |
s = esphome::modbus_controller::byte_from_hex_str(x,1); | |
d = esphome::modbus_controller::byte_from_hex_str(x,2); | |
h = esphome::modbus_controller::byte_from_hex_str(x,3); | |
y = esphome::modbus_controller::byte_from_hex_str(x,4); | |
month_ = esphome::modbus_controller::byte_from_hex_str(x,5); | |
// Now check if the rtc time of the controller is ok and correct it | |
time_t now = ::time(nullptr); | |
struct tm *time_info = ::localtime(&now); | |
int seconds = time_info->tm_sec; | |
int minutes = time_info->tm_min; | |
int hour = time_info->tm_hour; | |
int day = time_info->tm_mday; | |
int month = time_info->tm_mon + 1; | |
int year = time_info->tm_year % 100; | |
// correct time if needed (ignore seconds) | |
if (d != day || month_ != month || y != year || h != hour || m != minutes) { | |
// create the payload | |
std::vector<uint16_t> rtc_data = {uint16_t((minutes << 8) | seconds), uint16_t((day << 8) | hour), | |
uint16_t((year << 8) | month)}; | |
// Create a modbus command item with the time information as the payload | |
esphome::modbus_controller::ModbusCommandItem set_rtc_command = esphome::modbus_controller::ModbusCommandItem::create_write_multiple_command(epever, 0x9013, 3, rtc_data); | |
// Submit the command to the send queue | |
epever->queue_command(set_rtc_command); | |
ESP_LOGI("ModbusLambda", "EPSOLAR RTC set to %02d:%02d:%02d %02d.%02d.%04d", hour, minutes, seconds, day, month, year + 2000); | |
} | |
char buffer[20]; | |
// format time as YYYY-mm-dd hh:mm:ss | |
sprintf(buffer,"%04d-%02d-%02d %02d:%02d:%02d",y+2000,month_,d,h,m,s); | |
id(template_rtc).publish_state(buffer); | |
- platform: template | |
name: "RTC Time Sensor" | |
id: template_rtc | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
name: "rtc clock test 2" | |
id: rtc_clock_test2 | |
internal: true | |
register_type: holding | |
address: 0x9013 | |
register_count: 3 | |
raw_encode: HEXBYTES | |
response_size: 6 | |
switch: | |
# - platform: modbus_controller | |
# modbus_controller_id: epever | |
# id: reset_to_fabric_default | |
# name: "Reset to Factory Default" | |
# register_type: coil | |
# address: 0x15 | |
# bitmask: 1 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: manual_control_load | |
register_type: coil | |
address: 2 | |
name: "manual control the load" | |
bitmask: 1 | |
sensor: | |
- platform: wifi_signal | |
name: "WiFi Signal" | |
update_interval: 60s | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: pv_input_voltage | |
name: "PV array input voltage" | |
address: 0x3100 | |
device_class: voltage | |
unit_of_measurement: "V" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: pv_input_current | |
name: "PV array input current" | |
address: 0x3101 | |
device_class: current | |
unit_of_measurement: "A" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 2 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: pv_input_power | |
name: "PV array input power" | |
address: 0x3102 | |
device_class: power | |
unit_of_measurement: "W" | |
register_type: read | |
value_type: U_DWORD_R | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: charging_voltage | |
name: "Charging voltage" | |
address: 0x3104 | |
device_class: voltage | |
unit_of_measurement: "V" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: charging_current | |
name: "Charging current" | |
address: 0x3105 | |
device_class: current | |
unit_of_measurement: "A" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: charging_power | |
name: "Charging power" | |
address: 0x3106 | |
device_class: power | |
unit_of_measurement: "W" | |
register_type: read | |
value_type: U_DWORD_R | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: load_voltage | |
name: "Load voltage" | |
address: 0x310C | |
device_class: voltage | |
unit_of_measurement: "V" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: load_current | |
name: "Load Current" | |
address: 0x310D | |
device_class: current | |
unit_of_measurement: "A" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 2 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: load_power | |
name: "Load power" | |
address: 0x310E | |
device_class: power | |
unit_of_measurement: "W" | |
register_type: read | |
value_type: U_DWORD_R | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: battery_temperature | |
name: "Battery temperature" | |
address: 0x3110 | |
device_class: temperature | |
unit_of_measurement: °C | |
register_type: read | |
value_type: S_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: device_temperature | |
name: "Device temperature" | |
address: 0x3111 | |
device_class: temperature | |
unit_of_measurement: °C | |
register_type: read | |
value_type: S_WORD | |
accuracy_decimals: 1 | |
filters: | |
- multiply: 0.01 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: battery_soc | |
name: "Battery SOC" | |
address: 0x311A | |
device_class: battery | |
unit_of_measurement: "%" | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 0 | |
- platform: modbus_controller | |
modbus_controller_id: epever | |
id: Charger_status | |
name: "Charger status" | |
address: 0x3201 | |
register_type: read | |
value_type: U_WORD | |
accuracy_decimals: 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment