apexcharts-card icon indicating copy to clipboard operation
apexcharts-card copied to clipboard

Support new time zone (local/server time) feature released in 2023.7

Open jrb80 opened this issue 1 year ago • 15 comments

HA have just released an awesome new feature in 2023.7 which provides the option to select how you display time on the UI, either using the local time (default) or the server time (new). This is incredibly useful if the HA instance is in another country/time zone or if you are travelling abroad.

However, my initial testing suggests this feature isn't supported by this custom card. I show an example below showing the Apex Chart and HA History card using the server time option. The HA History (bottom) card is correctly displaying the server time, whereas the Apex Chart is still using the local client time.

image

jrb80 avatar Jul 06 '23 07:07 jrb80

This particularly annoying if you have charts that use end of day / week / month as it currently uses the browser local time and yields confusing results.

jpettitt avatar Jul 09 '23 08:07 jpettitt

+1

GitHubGoody avatar Jul 15 '23 11:07 GitHubGoody

I am guessing that https://github.com/RomRider/apexcharts-card/blob/1b63c0f53fadde489179f7c9e08d700daeb4215e/src/apexcharts-card.ts#L1444-L1463 needs to be updated, either with an explicit property like the clock weather card guys do in https://github.com/pkissling/clock-weather-card/blob/2e536aecefabf6096a4bc048b5d61736a55c348d/src/clock-weather-card.ts#L511 or by checking the 2023.7 hass preference. I don't know any typescript/javascript so am not up for it myself.

Lenbok avatar Aug 20 '23 22:08 Lenbok

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Oct 20 '23 02:10 github-actions[bot]

bump to keep alive

Lenbok avatar Oct 20 '23 04:10 Lenbok

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Dec 21 '23 02:12 github-actions[bot]

Still an issue.

Lenbok avatar Dec 21 '23 03:12 Lenbok

Discovered this today while I am in Asia and my home is in Europe.

martin3000 avatar Jan 22 '24 05:01 martin3000

Under my HA user profile I have Time Zone set to Use server time zone (Europe/London). When I am travelling my machine + browser changes to another time zone, eg. GMT-5. The following keeps the ApexChart card xaxis showing GMT. For details see datetimeUTC - https://apexcharts.com/docs/options/xaxis/ I set this using config_templates so all my charts take on this config.

apex_config:
  xaxis:
    labels:
      datetimeUTC: true

markcocker avatar Feb 18 '24 15:02 markcocker

Since I do not live in the UTC (GMT+0) time zone, this does not make sense for me.

martin3000 avatar Feb 18 '24 15:02 martin3000

I've set Server time zone and add datetimeUTC: true but i need to set UTC+8 because my iOS HA app shows wrong values on apexchart. I can only change time zone on my iPhone but it is not a solution.

budisek avatar Mar 19 '24 01:03 budisek

+1

DamienGdn avatar Mar 26 '24 14:03 DamienGdn

Here is an example of the problem using the Sun2 integration. This apexchart is viewed locally, in the same timezone as the Home Assistant server. The sunrise is shown correctly Local_View

Here is the same apexchart, viewed at the same time but from a different timezone from the Home Assistant server. You will not the sunrise is not shown correctly as the client time is used, rather than the server time Remote_View

jrb80 avatar Apr 04 '24 09:04 jrb80

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Jun 04 '24 02:06 github-actions[bot]

+1 still an issue.

Lenbok avatar Jun 04 '24 05:06 Lenbok

+1 still an issue.

NikolajChristensen avatar Jul 04 '24 16:07 NikolajChristensen

Working on it, but it's quite painful as the apexcharts library only supports displaying in browser's localtime or UTC. But I'll get there eventually.

RomRider avatar Jul 04 '24 16:07 RomRider

:tada: This issue has been resolved in version 2.1.0-dev.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 04 '24 20:07 github-actions[bot]

Please test this extensively with your setup as I might have missed edge cases !

RomRider avatar Jul 04 '24 20:07 RomRider

:tada: This issue has been resolved in version 2.1.0-dev.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jul 04 '24 21:07 github-actions[bot]

This is working well for me so far, thanks!

Lenbok avatar Jul 05 '24 06:07 Lenbok

Works well here too. Much much better experience. Thanks!

NikolajChristensen avatar Jul 05 '24 07:07 NikolajChristensen

@RomRider it works great, I've been waiting so long for this update, many thanks! Here is the same graph comparison from the original issue report, the Apex chart correctly displays the server time, brilliant!

After

jrb80 avatar Jul 05 '24 10:07 jrb80

Not sure if this is my "homemade" issue, or a general one. I have a apex card for Tibber prices forecast. Since the update it now correctly uses the server time in the card, but the chart is placed wrong. It should starting the graph from midnight, but it does start much later...


type: custom:apexcharts-card
experimental:
  color_threshold: true
all_series_config:
  unit: Cent/kWh
apex_config:
  grid:
    show: true
    borderColor: '#E0E0E0'
  chart:
    height: 250px
  tooltip:
    enabled: true
    followCursor: false
    x:
      show: false
    fixed:
      enabled: true
header:
  show: true
  title: Strompreis
  show_states: true
  colorize_states: true
  standard_format: false
graph_span: 48h
now:
  show: true
  color: 9E9E9E
span:
  start: day
series:
  - entity: sensor.tibber_prices
    show:
      in_header: before_now
      name_in_header: false
    color_threshold:
      - value: 0
        color: 4DD0E1
      - value: 10
        color: 26A69A
      - value: 15
        color: 4CAF50
      - value: 20
        color: 7CB342
      - value: 25
        color: FBC02D
      - value: 30
        color: EF6C00
      - value: 40
        color: B71C1C
    type: line
    curve: stepline
    extend_to: false
    stroke_width: 4
    float_precision: 2
    data_generator: |
      const noon = new Date()
      noon.setHours(0, 0, 0, 0)
      const prices = entity.attributes.today.concat(entity.attributes.tomorrow);
      const data = [];
      for(let i = 0; i < prices.length; i++) {
        data.push([noon.getTime() + i * 1000 * 3600, prices[i].total * 100])
      }
      return data;

image

Sammy990 avatar Jul 13 '24 09:07 Sammy990

Because new Date() followed by setHours uses your local time and not the server time. Use moment.js with moment.tz instead of the date object. Or maybe you can even use start instead.

data.push([start.getTime() + i * 1000 * 3600, prices[i].total * 100])

RomRider avatar Jul 13 '24 09:07 RomRider