PLCHome / growatt

38 stars 9 forks source link

Start and End dates working strangely #27

Closed Dizzybacon closed 8 months ago

Dizzybacon commented 8 months ago

Describe your inverter

Inverter model DNAA025100

Describe the bug
Trying to retrieve the historyAll data for a specific day. Setting startDate and endDate the same day and using offsets works sometimes, but sometimes returns the wrong day.

To Reproduce

This is my growatt.js script:

"use strict"
const api = require('growatt')
const user = "*********************"
const passwort = "*****************"

const startDate = new Date (process.argv[3])

const offset = process.argv[2]

const options={
  "historyAll": true,
  "historyLast": false,
  "historyLastStartDate": startDate,
  "historyLastEndDate": startDate,
  "historyStart": offset,
  "weather": false,
  "deviceData": false,
  "statusData": false,
  "totalData": false
}

async function getHistory() {
  const growatt = new api ({})
  let login = await growatt.login(user,passwort).catch(e => {console.log(e)})
  let getAllPlantData = await growatt.getAllPlantData(options).catch(e => {console.log(e)})
  console.log(JSON.stringify(getAllPlantData,null,' '));
  let logout = await growatt.logout().catch(e =>{console.log(e)})
}

getHistory()

Running this with node growatt.js 0 2023-12-10 returns the last 80 records for 2023-12-10, using the offset I can get the rest of the day.

Running this with node growatt.js 0 2024-1-23 returns the last 80 records for 2024-1-22!!

These are two specific examples but it seems to be inconsistent around different dates. For the most part I get the second result now, I have to offset the date by one day to get the data I want, but I don't seem to be able to rely on this as sometimes I get the other behaviour.

Expected behavior
startDate and endDate should consistently control the dates data is returned for.

Screenshots & Logfiles
If applicable, add screenshots and logfiles to help explain your problem.

Versions:

Additional context
I don't know if the problem is in my script, the PLCHome app or Growatt. My suspicion is that it's Growatt based on how flaky they seem to be with their API, but I can't see this raised by anyone else.

PLCHome commented 8 months ago

It can't be a problem with the node. The date is only passed to the server. But if the start and end dates are the same, the server does strange things. Please try to query the day correctly.

historyLastEndDate: new Date().setDate(startDate.getDate() + 1);

Dizzybacon commented 8 months ago

The server seems to do strange things regardless of if the start and end dates are the same! If I give different start and end dates and cycle through the offsets until I get no data I get two days worth of data, but not the ones I'd expect.

const startDate = new Date ('2024-3-19')
const endDate = new Date('2024-3-20')

returned data for the 18th and the 19th!

Using the wrong date seems to work consistently at the moment at least, but I'm surprised this hasn't been raised before.