You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.6 KiB
YAML

esphome:
name: solareco-meter
# friendly_name: SolarEco_meter
esp8266:
board: esp01_1m
# Enable logging
logger:
baud_rate: 115200
# Enable Home Assistant API
api:
encryption:
key: "<fill_your_encryption_key>"
ota:
password: "<fill_your_password>"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Solareco-Meter Fallback Hotspot"
password: "<fill_your_password>"
# global variables for downsampling and enerhy spikes
globals:
- id: latest_energy_value
type: int
restore_value: no
initial_value: '-1'
- id: downsample_counter
type: int
restore_value: no
initial_value: '0'
captive_portal:
# There is not possible to have UART read without having custom function in ESPHome,
# but there is a shortcut how to do that for easy applications with UARTDebug log functions
uart:
baud_rate: 115200
tx_pin: 15
rx_pin: 13
id: uart_2
debug:
direction: RX
dummy_receiver: true
after:
delimiter: "\n"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes);
char m[20];
char p[20];
int fan = 0;
int dc = 0;
int ac = 0;
int l = 0;
int solar = 0;
int required_voltage = 0;
int voltage = 0;
int current = 0;
int power = 0;
int frequency = 0;
int temperature = 0;
int boiler_temperature = 0;
int pulse_width = 0;
int energy = 0;
std::string str(bytes.begin(), bytes.end());
// old PCB data format.... split the data from format (b'M:4 P:1:1 R:0 F:0 U:168 168V 838mA 140W 50Hz 30C 594us 252Wh\n')
// new PCB data format (b'M:4:6 P:23:10 F1 DC1 AC0 0L 224S 224U 225V 7068mA 1586W 0:39C 7289us 3014Wh\n')
if (sscanf(str.c_str(), "M:%s P:%s F%d DC%d AC%d %dL %dS %dU %dV %dmA %dW %d:%dC %dus %dWh", m, p, &fan, &dc, &ac, &l, &solar, &required_voltage, &voltage, &current, &power, &boiler_temperature, &temperature, &pulse_width, &energy ) == 15) {
// check wrong peaks
if(id(latest_energy_value) > 1 && id(latest_energy_value) > energy ){
// new energy value is smaller than old one, no reset because its higher than 1
return;
}
// fill up current energy value
id(latest_energy_value) = energy;
id(downsample_counter) += 1;
// send every 15th sample font not that frequent communication
if(id(downsample_counter) % 15 == 0){
// publish the data
id(SOLAR_fan).publish_state(fan);
id(SOLAR_dc).publish_state(dc);
id(SOLAR_ac).publish_state(ac);
id(SOLAR_l).publish_state(l);
id(SOLAR_solar).publish_state(solar);
id(SOLAR_required_voltage).publish_state(required_voltage);
id(SOLAR_voltage).publish_state(voltage);
id(SOLAR_current).publish_state(current);
id(SOLAR_power).publish_state(power);
id(SOLAR_temperature).publish_state(temperature);
id(SOLAR_boiler_temperature).publish_state(boiler_temperature);
id(SOLAR_pulse_width).publish_state(pulse_width);
id(SOLAR_energy).publish_state(energy);
}
}
sensor:
- platform: template
name: "SolarEco-Fan"
id: "SOLAR_fan"
update_interval: never
accuracy_decimals: 0
- platform: template
name: "SolarEco-DC"
id: "SOLAR_dc"
update_interval: never
accuracy_decimals: 0
- platform: template
name: "SolarEco-AC" # relay, 1 = relay on, 0 relay off
id: "SOLAR_ac"
update_interval: never
accuracy_decimals: 0
- platform: template
name: "SolarEco-L"
id: "SOLAR_l"
update_interval: never
accuracy_decimals: 0
- platform: template
name: "SolarEco-Solar voltage"
id: "SOLAR_solar"
unit_of_measurement: 'V'
device_class: voltage
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Required voltage"
id: "SOLAR_required_voltage"
unit_of_measurement: 'V'
device_class: voltage
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Voltage"
id: "SOLAR_voltage"
unit_of_measurement: 'V'
device_class: voltage
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Current"
id: "SOLAR_current"
unit_of_measurement: 'mA'
device_class: current
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Power"
id: "SOLAR_power"
unit_of_measurement: 'W'
device_class: power
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Temperature"
id: "SOLAR_temperature"
unit_of_measurement: '°C'
device_class: temperature
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-BoilerTemperature"
id: "SOLAR_boiler_temperature"
unit_of_measurement: '°C'
device_class: temperature
update_interval: never
accuracy_decimals: 1
- platform: template
name: "SolarEco-Pulse with"
id: "SOLAR_pulse_width"
unit_of_measurement: 'us'
device_class: duration
update_interval: never
accuracy_decimals: 3
- platform: template
name: "SolarEco-Energy"
id: "SOLAR_energy"
unit_of_measurement: 'Wh'
device_class: energy
state_class: total_increasing
accuracy_decimals: 1