Hi all, for a long time I am looking for a solution to filter out some bogus data every morning at sunrise when my inverter is starting up and sending bogus total gen of the day before. This messes up my energy dashboard with peaks. I have tried multiple things but do not have a solution for it yet.
In another topic I was advised to open a new topic in esphome to ask for it.
My question is if I can get help creating a working lambda filter that filters out the bogus data every morning on sunrise.
INFO Reading configuration /config/esphome/growatt_modbus.yaml...
WARNING Found 'auto sunrise = id(sun_sun).sunrise(-0.833); //Get sunrise time
auto time = id(homeassistant_time).now(); //Get aktual time
if (!sunrise.has_value() and !time.is_valid()) //Validation sunrise and time data
return false ;
//1439 == 23:59 and 23:59 reset data to 0
if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
return true;
}
else return false;' (see binary_sensor->0->lambda) which looks like a substitution, but 'shift_sunrise' was not declared
WARNING Found 'auto sunrise = id(sun_sun).sunrise(-0.833); //Get sunrise time
auto time = id(homeassistant_time).now(); //Get aktual time
if (!sunrise.has_value() and !time.is_valid()) //Validation sunrise and time data
return false ;
//1439 == 23:59 and 23:59 reset data to 0
if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
return true;
}
else return false;' (see binary_sensor->0->lambda) which looks like a substitution, but 'shift_sunrise' was not declared
WARNING 'growatt_modbus': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Detected timezone 'Europe/Amsterdam'
INFO Generating C++ source...
INFO Compiling app...
Processing growatt_modbus (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
| |-- ESPAsyncTCP-esphome @ 1.2.3
| |-- Hash @ 1.0
| |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- ArduinoJson @ 6.18.5
Compiling /data/growatt_modbus/.pioenvs/growatt_modbus/src/main.cpp.o
/config/esphome/growatt_modbus.yaml: In lambda function:
/config/esphome/growatt_modbus.yaml:70:64: error: '$' was not declared in this scope
70 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ^
/config/esphome/growatt_modbus.yaml:70:65: error: expected ')' before '{' token
70 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ~ ^
| )
/config/esphome/growatt_modbus.yaml:70:82: error: expected primary-expression before '<' token
70 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ^
/config/esphome/growatt_modbus.yaml:74:3: error: control reaches end of non-void function [-Werror=return-type]
74 |
| ^
cc1plus: some warnings being treated as errors
*** [/data/growatt_modbus/.pioenvs/growatt_modbus/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.75 seconds ==========================
I found a mistake in filter lambda. Fixed it, tried to compile the YAML and it works now. You’ll find the code attached below. Your formatting is pretty wild.
Unfortunately, I probably can’t help with MODBUS. I would look for a connection error. Other UART settings? Can you use hardware uart wemos d1 mini? Is used? Don’t forget to set the logger to baud_rate: 0
Since I prefer this lamba on the sensor I started trying again but I get an error:
INFO Reading configuration /config/esphome/growatt_modbus.yaml...
WARNING Found 'auto sunrise = id(sun_sun).sunrise(-0.833); //Get sunrise time
auto time = id(homeassistant_time).now(); //Get aktual time
if (!sunrise.has_value() and !time.is_valid()) //Validation sunrise and time data
return 0 ;
//1439 == 23:59 and 23:59 reset data to 0
if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
return x;
}
else return 0;' (see sensor->2->energy_production_day->filters->0->lambda) which looks like a substitution, but 'shift_sunrise' was not declared
WARNING Found 'auto sunrise = id(sun_sun).sunrise(-0.833); //Get sunrise time
auto time = id(homeassistant_time).now(); //Get aktual time
if (!sunrise.has_value() and !time.is_valid()) //Validation sunrise and time data
return 0 ;
//1439 == 23:59 and 23:59 reset data to 0
if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
return x;
}
else return 0;' (see sensor->2->energy_production_day->filters->0->lambda) which looks like a substitution, but 'shift_sunrise' was not declared
WARNING 'growatt_modbus': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Detected timezone 'Europe/Amsterdam'
INFO Generating C++ source...
INFO Compiling app...
Processing growatt_modbus (board: d1_mini; framework: arduino; platform: platformio/espressif8266 @ 3.2.0)
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- ESPAsyncTCP-esphome @ 1.2.3
|-- ESPAsyncWebServer-esphome @ 2.1.0
| |-- ESPAsyncTCP-esphome @ 1.2.3
| |-- Hash @ 1.0
| |-- ESP8266WiFi @ 1.0
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- ArduinoJson @ 6.18.5
Compiling /data/growatt_modbus/.pioenvs/growatt_modbus/src/esphome/components/sun/sun.cpp.o
Compiling /data/growatt_modbus/.pioenvs/growatt_modbus/src/main.cpp.o
/config/esphome/growatt_modbus.yaml: In lambda function:
/config/esphome/growatt_modbus.yaml:132:64: error: '$' was not declared in this scope
132 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ^
/config/esphome/growatt_modbus.yaml:132:65: error: expected ')' before '{' token
132 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ^
| )
/config/esphome/growatt_modbus.yaml:132:82: error: expected primary-expression before '<' token
132 | if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
| ^
/config/esphome/growatt_modbus.yaml:136:3: error: control reaches end of non-void function [-Werror=return-type]
136 | # if (x >= 0) return x;
| ^
cc1plus: some warnings being treated as errors
*** [/data/growatt_modbus/.pioenvs/growatt_modbus/src/main.cpp.o] Error 1
========================== [FAILED] Took 2.82 seconds ==========================