Can you show me the whole yaml file?
esphome:
name: growatt_modbus
platform: ESP8266
board: d1_mini
substitutions:
esp_name: Growattmodbus
#Shift sunrise on minutes
shift_sunrise: '10'
wifi:
ssid: "SSID"
password: !secret wifi_key
use_address: 192.168.6.42
domain: !secret domain
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${esp_name} fb Hotspot"
password: !secret Fallback_Hotspot
captive_portal:
# Enable logging
logger:
# level: VERBOSE
# baud_rate: 0
# Enable Home Assistant API
api:
ota:
time:
- platform: homeassistant
id: homeassistant_time
#on_time:
# Every morning on weekdays reset ID todaygen
# - seconds: 0
# minutes: 0
# hours: 0
# #days_of_week: MON-SUN
# then:
# - lambda: id(todaygen).publish_state(0);
sun:
latitude: !secret latitude_data
longitude: !secret longitude_data
id: sun_sun
uart:
- id: uart1
baud_rate: 9600
tx_pin: D1
rx_pin: D2
# stop_bits: 1
modbus:
uart_id: uart1
web_server:
port: 80
binary_sensor:
- platform: template
id: enable_sun_sensor
lambda: |-
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;
sensor:
- platform: wifi_signal
name: "${esp_name} - ESP WiFi Signal"
update_interval: 60s
- platform: uptime
name: "${esp_name} - ESP Uptime"
icon: mdi:clock-outline
update_interval: 60s
- platform: growatt_solar
update_interval: 3s
protocol_version: RTU2
inverter_status:
name: "${esp_name} - Status Code"
id: inverter_status
phase_a:
voltage:
name: "${esp_name} - AC Voltage"
current:
name: "${esp_name} - AC Current"
active_power:
name: "${esp_name} - AC Power"
filters:
- filter_out: NaN
pv1:
voltage:
name: "${esp_name} - PV1 Voltage"
current:
name: "${esp_name} - PV1 Current"
active_power:
name: "${esp_name} - PV1 Power"
pv2:
voltage:
name: "${esp_name} - PV2 Voltage"
current:
name: "${esp_name} - PV2 Current"
active_power:
name: "${esp_name} - PV2 Power"
active_power:
state_class: "measurement"
name: "${esp_name} - Output Power"
filters:
- lambda: |-
if (x <= 5500 && x >= 0) return x;
else return 0;
#- lambda: |-
# if (x <= 5500) return x;
# else return {};
pv_active_power:
name: "${esp_name} - Input Power"
frequency:
name: "${esp_name} - Grid Frequency"
energy_production_day:
name: "${esp_name} - Today Gen"
id: todaygen
filters:
- lambda: |-
if (enable_sun_sensor) return x; else
{if (x >= 0) return x;
else return 0;}
#- lambda: |-
# if(id(sun_sun).elevation() < 1.0 && id(sun_sun).elevation() > -0.8) return 0; else
# {if (x >= 0) return x;
# else return 0;}
#lambda: |-
# if (id(inverter_status).state != 0) {
# return x;
# }
# return {};
# - lambda: "if (x - id(todaygen).state) > 0.5) return {}; return x;"
# https://github.com/esphome/feature-requests/issues/607
#- lambda: auto s = id(${todaygen}_skips); if(s->state > 100) { return x; } else { s->publish_state(s->state+1); return {}; }
#state_class: total
#state_class: total_increasing # was empty
# https://developers.home-assistant.io/docs/core/entity/sensor/#how-to-choose-state_class-and-last_reset
total_energy_production:
name: "${esp_name} - Total Gen"
#state_class: "measurement"
#device_class: energy
accuracy_decimals: 1
inverter_module_temp:
name: "${esp_name} - Temperature"
switch:
- platform: restart
name: "${esp_name} - ESP Restart"
text_sensor:
- platform: wifi_info
ip_address:
name: "${esp_name} IP Address"
ssid:
name: "${esp_name} Connected SSID"
bssid:
name: "${esp_name} Connected BSSID"
mac_address:
name: "${esp_name} Mac Wifi Address"
- platform: version
name: "${esp_name} - ESPHome Version"
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.
esphome:
name: growatt-modbus
platform: ESP8266
board: d1_mini
substitutions:
esp_name: Growattmodbus
#Shift sunrise on minutes
shift_sunrise: '10'
wifi:
ssid: "SSID"
password: !secret wifi_key
use_address: 192.168.6.42
domain: !secret domain
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "${esp_name} fb Hotspot"
password: !secret Fallback_Hotspot
captive_portal:
# Enable logging
logger:
# level: VERBOSE
# baud_rate: 0
# Enable Home Assistant API
api:
ota:
time:
- platform: homeassistant
id: homeassistant_time
#on_time:
# Every morning on weekdays reset ID todaygen
# - seconds: 0
# minutes: 0
# hours: 0
# #days_of_week: MON-SUN
# then:
# - lambda: id(todaygen).publish_state(0);
sun:
latitude: !secret latitude_data
longitude: !secret longitude_data
id: sun_sun
uart:
- id: uart1
baud_rate: 9600
tx_pin: D1
rx_pin: D2
# stop_bits: 1
modbus:
uart_id: uart1
web_server:
port: 80
binary_sensor:
- platform: template
id: enable_sun_sensor
lambda: |-
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;
sensor:
- platform: wifi_signal
name: "${esp_name} - ESP WiFi Signal"
update_interval: 60s
- platform: uptime
name: "${esp_name} - ESP Uptime"
icon: mdi:clock-outline
update_interval: 60s
- platform: growatt_solar
update_interval: 3s
protocol_version: RTU2
inverter_status:
name: "${esp_name} - Status Code"
id: inverter_status
phase_a:
voltage:
name: "${esp_name} - AC Voltage"
current:
name: "${esp_name} - AC Current"
active_power:
name: "${esp_name} - AC Power"
filters:
- filter_out: NaN
pv1:
voltage:
name: "${esp_name} - PV1 Voltage"
current:
name: "${esp_name} - PV1 Current"
active_power:
name: "${esp_name} - PV1 Power"
pv2:
voltage:
name: "${esp_name} - PV2 Voltage"
current:
name: "${esp_name} - PV2 Current"
active_power:
name: "${esp_name} - PV2 Power"
active_power:
state_class: "measurement"
name: "${esp_name} - Output Power"
filters:
- lambda: |-
if (x <= 5500 && x >= 0) return x;
else return 0;
#- lambda: |-
# if (x <= 5500) return x;
# else return {};
pv_active_power:
name: "${esp_name} - Input Power"
frequency:
name: "${esp_name} - Grid Frequency"
energy_production_day:
name: "${esp_name} - Today Gen"
id: todaygen
filters:
- lambda: |-
if (enable_sun_sensor) return x;
else return 0;
#- lambda: |-
# if(id(sun_sun).elevation() < 1.0 && id(sun_sun).elevation() > -0.8) return 0; else
# {if (x >= 0) return x;
# else return 0;}
#lambda: |-
# if (id(inverter_status).state != 0) {
# return x;
# }
# return {};
# - lambda: "if (x - id(todaygen).state) > 0.5) return {}; return x;"
# https://github.com/esphome/feature-requests/issues/607
#- lambda: auto s = id(${todaygen}_skips); if(s->state > 100) { return x; } else { s->publish_state(s->state+1); return {}; }
#state_class: total
#state_class: total_increasing # was empty
# https://developers.home-assistant.io/docs/core/entity/sensor/#how-to-choose-state_class-and-last_reset
total_energy_production:
name: "${esp_name} - Total Gen"
#state_class: "measurement"
#device_class: energy
accuracy_decimals: 1
inverter_module_temp:
name: "${esp_name} - Temperature"
switch:
- platform: restart
name: "${esp_name} - ESP Restart"
text_sensor:
- platform: wifi_info
ip_address:
name: "${esp_name} IP Address"
ssid:
name: "${esp_name} Connected SSID"
bssid:
name: "${esp_name} Connected BSSID"
mac_address:
name: "${esp_name} Mac Wifi Address"
- platform: version
name: "${esp_name} - ESPHome Version"
Linking .pioenvs/growatt-modbus/firmware.elf
RAM: [==== ] 43.0% (used 35232 bytes from 81920 bytes)
Flash: [===== ] 45.5% (used 474841 bytes from 1044464 bytes)
Building .pioenvs/growatt-modbus/firmware.bin
esp8266_copy_factory_bin([".pioenvs/growatt-modbus/firmware.bin"], [".pioenvs/growatt-modbus/firmware.elf"])
======================== [SUCCESS] Took 323.95 seconds ========================
INFO Successfully compiled program.
esohome v2022.12.3
Flashing… will repott next days the result
oh oh
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:54][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! F66B!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:31:57][W][modbus:105]: Modbus CRC Check failed! A45!=C700
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=822
[16:32:00][W][modbus:105]: Modbus CRC Check failed! 3760!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! 3ADA!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:00][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=2200
[16:32:03][W][modbus:105]: Modbus CRC Check failed! 3078!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=00
[16:32:03][W][modbus:105]: Modbus CRC Check failed! C071!=7500
[16:32:03][W][modbus:105]: Modbus CRC Check failed! 53E3!=F9
flashed back old code works…
Nemáte ve staré verzi jinak nastaveny :
uart:
- id: uart1
baud_rate: 9600
tx_pin: D1
rx_pin: D2
# stop_bits: 1
modbus:
uart_id: uart1
Yes they are as wellin old as in new:
uart:
- id: uart1
baud_rate: 9600
tx_pin: D1
rx_pin: D2
# stop_bits: 1
modbus:
uart_id: uart1
That needs to be in at least to get the values
Zmínka tady: SDM meter modbus CRC errors · Issue #3912 · esphome/issues · GitHub
and Modbus CRC Error after update to latest ESPHome version 2022.12.0 - #8 by Crazymonster999
Můžete zkusit přidat
modbus:
send_wait_time: 500ms
Just to let you know, I changed the _ to - (underscores should not be used in domain names).
name: growatt-modbus
Of course, Lambda can be used directly in the filter, there’s no need to create an extra binary sensor.
energy_production_day:
name: "${esp_name} - Today Gen"
id: todaygen
filters:
lambda: |-
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;
Hm how strange. Old yaml with latest esphome has no problem
Seen it, I cant oversee the consequences
Indeed, I prefer that
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
Nothing should happen
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 ==========================
Is the character ( " ) or ( ’ ) missing in the script? I tried it now and it’s ok.
Linking .pioenvs/growatt-modbus/firmware.elf
RAM: [==== ] 42.9% (used 35168 bytes from 81920 bytes)
Flash: [===== ] 45.1% (used 470897 bytes from 1044464 bytes)
Building .pioenvs/growatt-modbus/firmware.bin
esp8266_copy_factory_bin([".pioenvs/growatt-modbus/firmware.bin"], [".pioenvs/growatt-modbus/firmware.elf"])
======================== [SUCCESS] Took 130.31 seconds ========================
INFO Successfully compiled program.
This is ok with me
esphome:
name: growatt-modbus
platform: ESP8266
board: d1_mini
substitutions:
esp_name: Growattmodbus
#Shift sunrise on minutes
shift_sunrise: '10'
wifi:
ssid: "SSID"
password: !secret wifi_key
use_address: 192.168.6.42
domain: !secret domain
ap:
ssid: "${esp_name} fb Hotspot"
password: !secret Fallback_Hotspot
captive_portal:
logger:
api:
ota:
time:
- platform: homeassistant
id: homeassistant_time
sun:
latitude: !secret latitude_data
longitude: !secret longitude_data
id: sun_sun
uart:
- id: uart1
baud_rate: 9600
tx_pin: D1
rx_pin: D2
modbus:
uart_id: uart1
web_server:
port: 80
sensor:
- platform: wifi_signal
name: "${esp_name} - ESP WiFi Signal"
update_interval: 60s
- platform: uptime
name: "${esp_name} - ESP Uptime"
icon: mdi:clock-outline
update_interval: 60s
- platform: growatt_solar
update_interval: 3s
protocol_version: RTU2
inverter_status:
name: "${esp_name} - Status Code"
id: inverter_status
phase_a:
voltage:
name: "${esp_name} - AC Voltage"
current:
name: "${esp_name} - AC Current"
active_power:
name: "${esp_name} - AC Power"
filters:
- filter_out: NaN
pv1:
voltage:
name: "${esp_name} - PV1 Voltage"
current:
name: "${esp_name} - PV1 Current"
active_power:
name: "${esp_name} - PV1 Power"
pv2:
voltage:
name: "${esp_name} - PV2 Voltage"
current:
name: "${esp_name} - PV2 Current"
active_power:
name: "${esp_name} - PV2 Power"
active_power:
state_class: "measurement"
name: "${esp_name} - Output Power"
filters:
- lambda: |-
if (x <= 5500 && x >= 0) return x;
else return 0;
pv_active_power:
name: "${esp_name} - Input Power"
frequency:
name: "${esp_name} - Grid Frequency"
energy_production_day:
name: "${esp_name} - Today Gen"
id: todaygen
filters:
lambda: |-
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;
total_energy_production:
name: "${esp_name} - Total Gen"
accuracy_decimals: 1
inverter_module_temp:
name: "${esp_name} - Temperature"
switch:
- platform: restart
name: "${esp_name} - ESP Restart"
text_sensor:
- platform: wifi_info
ip_address:
name: "${esp_name} IP Address"
ssid:
name: "${esp_name} Connected SSID"
bssid:
name: "${esp_name} Connected BSSID"
mac_address:
name: "${esp_name} Mac Wifi Address"
- platform: version
name: "${esp_name} - ESPHome Version"
It compiles… now let’s see tomorrow morning
I think today it worked. I keep watching it and report back.
Additionally I have 2 questions.
- Now when “the lambda” is in the is “no value”, can it send out 0 during tha time?
- during power loss/esp power down/esp unavailability the output in HA goes back to “no value” effective 0. How can I overcome that?
1,
filters:
lambda: |-
auto sunrise = id(sun_sun).sunrise(-0.833);
auto time = id(homeassistant_time).now();
if(sunrise.has_value() && time.is_valid()){
if((sunrise.value().hour * 60 + sunrise.value().minute + ${shift_sunrise}) < (time.hour*60+time.minute) && (time.hour*60+time.minute) < 1439) {
if(String(id(todaygen).state) == "nan") return 0;
else return x;
}
else return 0;
}
else return 0;
2,
I´m not sure, but it will doesn´t work probably.