Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ongelma kellojen siirron kanssa / automaattinen aikavyöhykkeen haku #7

Closed
jisotalo opened this issue Oct 29, 2023 · 2 comments
Closed
Labels
bug Something isn't working enhancement New feature or request

Comments

@jisotalo
Copy link
Owner

jisotalo commented Oct 29, 2023

Valitettavasti kellojen siirto aiheutti ongelman skriptin kanssa, olin unohtanut sinne kiinteän aikavyöhykkeen +03:00 UTC. Onneksi varmuustuntiohjaus tuntuu toimivan kuten pitää (eli ainoastaan hintatiedot ei olleet käytössä).

Tämä on korjattu väliaikaisesti versiossa 2.6.1 muuttamalla aikavyöhyke kinteästi +02:00. Ei kuitenkaan ole hyvä ratkaisu.

https://github.com/jisotalo/shelly-porssisahko/releases/tag/v.2.6.1

Lisätään ominaisuus, että aikavyöhyke haetaan Shellyn kellon ja UTC ajan erotuksesta automaattisesti. Shelly ei valitettavasti tue suoraan Date.getTimezoneOffset() -metodia, joten haetaan se alla olevalla tavalla tms.

Piti laittaa jo versioon 2.6.1 mutta tuli jotain ongelmaa Shellyn pinomuistin tms. kanssa. Alla versio joka tuntuu toimivan mutta ajetaan ensin vähän testiä..

/**
 * Updates current timezone to state as hh:mm string format (url encoded)
 * For example if UTC time is 04:55 and local time is 06:55, tz is %2b02:00 
 * 
 * NOTE: Technically incorrect, only handles time zones with hour differences
 * 
 * @param {Date} now Current time
 * @returns 
 */
function updateTz(now) {
  //Get UTC time as string (e.g. Sun, 29 Oct 2023 04:55:00 GMT)
  let utc = now.toUTCString();

  //Extract time from UTC time string (e.g. "04:55:00 GMT")
  utc = utc.substring(utc.indexOf("" + now.getFullYear()) + 5);

  //Extract hours (e.g. "04")
  utc = Number(utc.substring(0, utc.indexOf(":")));

  //Calculate time difference
  let diff = now.getHours() - utc;

  let tz = padStart(Math.abs(diff), 2, "0") + ":00";

  if (diff < 0) {
    tz = "-" + tz;
  } else {
    tz = "%2b" + tz;
  }
  _.s.tz = tz;
}
@jisotalo jisotalo added bug Something isn't working enhancement New feature or request labels Oct 29, 2023
@jisotalo
Copy link
Owner Author

jisotalo commented Oct 29, 2023

Viimeinen versio tehty ja ratkaisu tuntuu toimivan. Ajan omassa käytössä jonkin aikaa ennen julkaisua.

/**
 * Updates current timezone to state as hh:mm string format (url encoded)
 * For example if UTC time is 04:55 and local time is 06:55, tz is %2b02:00 
 * 
 * NOTE: Technically incorrect, only handles timezones with full hour offsets
 * 
 * @param {Date} now Current time
 * @returns 
 */
function updateTz(now) {
  //Get UTC time as string (e.g. Sun, 29 Oct 2023 04:55:00 GMT)
  let utc = now.toUTCString();

  //Extract time from UTC time string (e.g. "04:55:00 GMT")
  utc = utc.substring(utc.indexOf("" + getFullYear(now)) + 5);

  //Extract hours (e.g. "04")
  utc = Number(utc.substring(0, utc.indexOf(":")));

  //Calculate time difference
  let diff = getHours(now) - utc;

  let tz = padStart(Math.abs(diff), 2, "0") + ":00";

  if (diff < 0) {
    tz = "-" + tz;
  } else if (diff > 0) {
    tz = "%2b" + tz;
  } else {
    tz = "Z";
  }
  
  if (tz !== _.s.tz) {
    //Timezone has changed -> we should get prices
    _.s.p.ts = 0;
  }

  _.s.tz = tz;
}

jisotalo added a commit that referenced this issue Nov 5, 2023
- Uusi ominaisuus: automaattinen aikavyöhyke (eli myös autom. kesä/talviaika)
  - Shelly laskee aikaeron UTC-ajan ja paikallisen ajan välillä -> Käytetään aina oikeaa aikavyöhykettä hintojen haussa
  - Jos aikaero muuttuu, haetaan hinnat uusiksi (esim. kun kesä/talviaika vaihtuu)
  - Lisätiedot: [Issue #7](#7)
- Firmware-vaatimus on 1.0.7. Vanhemmille ei luvata tukea.
  - Tässä firmisversiossa parannettiin skriptien muistinhallintaa
@jisotalo
Copy link
Owner Author

jisotalo commented Nov 5, 2023

2.7.0 julkaistu

@jisotalo jisotalo closed this as completed Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant