Hi there,
I need help with following:
Got an ELWA DC heater and successfully installed an IR head on an ESP32 running ESPhome. With the UART reading example template I got things running and see the raw string data getting into HomeAssistant.
Since then I tried to get along with the ESPhome YAML configuration to get the the most important values (voltage, current, etc.) out of the bunch of \t delimitted readings from string but I am just to dumb I guess and my programming skills are about 20 years old.
I would be happy if someone could help, cause I guess this is just an easy finger-play for someone who knows how to deal with lambda, sequence, etc. which for me is cracy⌠If this could work and we get single variables out of the string to be used in HomeAssistant I would be happy to provide this due to the fact that for ELWA DC I could not find an IR reading solution with ESPhome so far.
This is the current ESPhome YAML where I can see all relevant values each 10sec within the rawString:
esphome:
name: esphome-web-4d3a10
friendly_name: ElwaDC PV Zaehler
esp32:
board: esp32dev
framework:
type: arduino
# Enable Home Assistant API
api:
encryption:
key: "NOTSHOWN"
ota:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-4D3A10"
password: "OgwoufPoY2vv"
captive_portal:
# ---------------------------
logger:
baud_rate: 9600
uart:
baud_rate: 9600
tx_pin: 17
rx_pin: 16
debug:
direction: RX
dummy_receiver: true
after:
delimiter: "\r\n"
#delimiter: "\t"
sequence:
- lambda: |-
UARTDebug::log_string(direction, bytes); //Still log the data
int sensorID=0;
float sensorTEMP=0;
//Example to convert uart text to string
std::string str(bytes.begin(), bytes.end());
id(rawString).publish_state(str.c_str());
//watch for potential problems with non printable or special characters in string
//Sample uart text protocol that sends id:temperature\r\n packets
if (sscanf(str.c_str(), "%d:%f", &sensorID, &sensorTEMP) == 0 ) {
if(sensorID==0)
id(temp1).publish_state(sensorTEMP);
}
text_sensor:
- platform: template
name: "Raw String"
id: "rawString"
sensor:
- platform: template
name: "Temp 1"
id: "temp1"
#if you need to send a request periodically to get response from the uart device
interval:
- interval: 10s
then:
#//"ping" request for getting just an OK
#- uart.write: [0x72, 0x72, 0x71, 0x0D, 0x0A]
- uart.write: [0x72, 0x73, 0x0D, 0x0A]
I get this UART debug:
[13:00:22][D][sensor:094]: 'Temp 1': Sending state 0.00000 with 1 decimals of accuracy
[13:00:22][W][component:214]: Component uart took a long time for an operation (0.15 s).
[13:00:22][W][component:215]: Components should block for at most 20-30ms.
[13:00:22][D][uart_debug:158]: <<< "dr\tV1.31\t127\t12\t1\t1\t1\t420\t300\t425\t650\t500\t30\t8"
[13:00:22][D][text_sensor:064]: 'Raw String': Sending state 'dr V1.31 127 12 1 1 1 420 300 425 650 500 30 8'
And the rawString in HomeAssistant looks like this:
(I guess it is too long?)
When sun is down the ESP just delivers an ârsâ in rawString.
Following mapping would be there if sun is up:
msg.payload;\nvar parts = str.split(/\\x09/);\nmsg.payload = {\n name: parts[0],\n
Firmware: (parts[1]),\n
Betriebstag: parseInt(parts[2]),\n
Status_MPP_Rack: parseInt(parts[3]),\n
DC_Trenner: parseInt(parts[4]),\n
DC_Relais: parseInt(parts[5]),\n
AC_Relais: parseInt(parts[6]),\n
Temperatur: parseInt(parts[7]),\n
Temp_min: parseInt(parts[8]),\n
Temp_max: parseFloat(parts[9]),\n
Temp_Soll: parseInt(parts[10]),\n
Temp_Soll_Netz: parseInt(parts[11]),\n
Temp_Geraet: parseInt(parts[12]),\n
ISO_Messung: parseInt(parts[13]),\n
item14: parseInt(parts[14]),\n
Spannung: parseInt(parts[15]),\n
Strom: parseFloat(parts[16]),\n
Leistung: parseFloat(parts[17]),\n
Solarenergie_heute: parseInt(parts[18]),\n
Solarenergie_gesamt: parseInt(parts[19]),\n
Netzenergie_heute: parseInt(parts[20]),\n
item21: (parts[21]),\n
item22: (parts[22]),\n
item23: (parts[23]),\n
item24: (parts[24]),\n
Laufzeit_heute_Minuten: parseInt(parts[25]),\n
Netzladung_Beginn: (parts[26]),\n
Position_unten: (parts[27]),\n
Serien_Nr: parseInt(parts[28]),\n
item29: (parts[29]),\n
item30: (parts[30]),\n
status: parts[31],\n}\nreturn msg;",
Most important values for sure will be [15], [16] and [17] (voltage, current, power).
Would be very happy if you could push me into right direction or help with the right code to seperate the raw string into the right real variables to be used in HA.
Thanks so far!