Add data_age=0 as events requirement.
This commit is contained in:
parent
40c81c0bb3
commit
0e491612dd
1 changed files with 4 additions and 3 deletions
7
main.go
7
main.go
|
@ -212,7 +212,7 @@ func handleMessage(message []byte, db *sql.DB) {
|
|||
// Check conditions for recording data
|
||||
for _, inverter := range liveData.Inverters {
|
||||
// Record events data
|
||||
if inverter.Events > 0 && inverter.Events > getPreviousEventsCount(db, inverter.Serial) {
|
||||
if inverter.DataAge == 0 && inverter.Events > 0 && inverter.Events > getPreviousEventsCount(db, inverter.Serial) {
|
||||
// Query the endpoint for events
|
||||
events, err := queryEventsEndpoint(inverter.Serial)
|
||||
if err != nil {
|
||||
|
@ -445,6 +445,7 @@ func queryEventsEndpoint(inverterSerial string) (*EventsResponse, error) {
|
|||
}
|
||||
|
||||
// The events counter reported by OpenDTU resets every day.
|
||||
// To account for possible time drifts, the first and last 10 minutes of the day are excluded.
|
||||
// Longest day NL: sun up 4:16, sun down 22:50
|
||||
// Shortest day NL: sun up 8:44, sun down 16:25
|
||||
func getPreviousEventsCount(db *sql.DB, inverterSerial string) int {
|
||||
|
@ -453,8 +454,8 @@ func getPreviousEventsCount(db *sql.DB, inverterSerial string) int {
|
|||
SELECT COUNT(*)
|
||||
FROM opendtu_events
|
||||
WHERE inverter_serial = $1
|
||||
AND timestamp >= CURRENT_DATE + INTERVAL '9 hours'
|
||||
AND timestamp < CURRENT_DATE + INTERVAL '23 hours'
|
||||
AND timestamp >= CURRENT_DATE + INTERVAL '10 minutes'
|
||||
AND timestamp < CURRENT_DATE + INTERVAL '23 hours 50 minutes'
|
||||
`, inverterSerial).Scan(&count)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
logger.Error("Error querying previous events count", "error", err)
|
||||
|
|
Loading…
Reference in a new issue