kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
3k stars 233 forks source link

mini-graph-card switch state history renders differently on RPi Chromium Browser #994

Closed wombat70 closed 1 year ago

wombat70 commented 1 year ago

Hi,

HA versions:

Home Assistant 2023.7.0
Frontend 20230705.0 - latest
mini-graph-card v0.11.0

browsers:

desktop: Google Chrome version 114.0.5735.198
Android HA app: 2023.7.5-full
RaspberryPi: Chromium Browser version Chromium 104.0.5112.105, Debian 11

I recently made a mini-graph-card for my HA installation, which I typically view in three places (HA Android app, desktop, and a Raspberry Pi kiosk display). It displays the graph of my Octopus energy price history, together with a zero-line. I recently added a Tuya switch which controls the electrical immersion heater in our hot-water tank, so I recently added that switch entity as a secondary axis to the graph.

The problem I am seeing is that the graph data looks different on the Raspberry Pi kiosk display than it does on the desktop browser and Android app (see attached). In the RaspberryPi kiosk graph, there is a period where the state of the switch data is wrong (looks like it remained on when it was really off); it's almost like the mini-graph-card is using its own copy of the switch state history data (and then got itself out of sync).

Google Chrome desktop Android app RPi kiosk Chromium

I was recently playing with other parts of the HA configuration (related to a Modbus controller), so I was restarting HA quite a lot, which was when the issue started.

Any clues as to why the card would look different on my RPi kiosk?

My card config looks like:

views:
  - theme: Backend-selected
    title: Octopus
    layout:
      max_cols: 1
    type: custom:horizontal-layout
    badges: []
    cards:
      - type: custom:mini-graph-card
        name: Current Electricity Price (last 24 hours)
        hours_to_show: 24
        hour24: true
        smoothing: false
        points_per_hour: 20
        line_width: 2
        decimals: 4
        show:
          labels: true
        state_map:
          - value: 'off'
            label: 'Off'
          - value: 'on'
            label: 'On'
        entities:
          - entity: >-
              sensor.octopus_energy_electricity_REDACTED_current_rate
            name: Current rate
            color: '#4a45e3'
            show_state: true
            show_fill: false
            show_points: false
            y_axis: primary
          - entity: input_number.zero
            color: green
            show_state: false
            show_fill: false
            show_points: false
            y_axis: primary
          - entity: switch.immersion_heater_tuya
            show_state: true
            show_fill: false
            show_points: false
            y_axis: secondary
wombat70 commented 1 year ago

Interestingly, if enable or disable show_state in my config, the card renders the switch.immersion_heater_tuya state history differently on my RPi kiosk (Chromium Browser):

...
          - entity: switch.immersion_heater_tuya
            show_state: true
...
RPi kiosk Chromium

Compared to:

...
          - entity: switch.immersion_heater_tuya
            show_state: false
...
RPi kiosk Chromium
akloeckner commented 1 year ago

I think, mini-graph-card does indeed use a cached history. So, it might get out of sync. Restarting HA seems a possible cause for this, because state updates (to which the card subscribes) just don't arrive anymore. Reloading the page should re-initialize everything. As does (probably) changing options, which explains your observation in the second comment.

I think, there is nothing that should be done about it. Fetching the complete history is relatively compute-intense. So, using a local cache is a good thing. Maybe, the complete history could be re-fetched when re-connecting. But I have not yet found where this is done.

wombat70 commented 1 year ago

I just returned to this issue...it turns out that there was bad data in the browser cache. I've adjusted the chromium-browser settings to CHROMIUM_FLAGS="--disk-cache-dir=/dev/null --disk-cache-size=1" (completely disable cache) and the graph looks OK now.

Closing issue.