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

Bar chart does not update on "always on" Android tablet #250

Open
FSund opened this issue Feb 14, 2023 · 11 comments
Open

Bar chart does not update on "always on" Android tablet #250

FSund opened this issue Feb 14, 2023 · 11 comments
Labels
bug Something isn't working

Comments

@FSund
Copy link

FSund commented Feb 14, 2023

Describe the bug
I have an Android tablet that I use do display my Home Assistant dashboard. I've checked "keep screen on" option in the HA companion app.

The red bars ("Forbruk") in the attached screenshot does not seem to update correctly when the screen is left on, and I have to manually close and reopen the app to fix this. I have highlighted the area with missing bars in the screenshot.

This might appear on other devices/interfaces other than Android tablets, but it's the only device I have that is kept on and not interacted with for long periods :)

Screenshots
image

yaml

The full config is pretty complex, but the config for the red bars is pretty standard

The only thing I can think of that might be causing an issue is xperiod: 3600000, which I've used to align the bars in the center between full hours, instead of on each hour.

  - entity: sensor.kaifa_active_power_import
    name: Forbruk
    yaxis: 'y'
    marker:
      color: '#FF4560'
    xperiod: 3600000
    statistic: mean
    period: hour
    type: bar
    unit_of_measurement: kWh
    filters:
      - map_y_numbers: y/1000.0

Full config:

type: custom:plotly-graph
title: Strømpris og forbruk
hours_to_show: current_day
refresh_interval: 300
defaults:
  entity:
    line:
      width: 2
config:
  staticPlot: true
layout:
  height: 320
  xaxis:
    tickformat: '%H:%M'
    tickangle: -45
    dtick: 10800000
    minor:
      showgrid: true
      griddash: dot
      dtick: 3600000
      gridcolor: '#00000020'
      ticks: outside
  yaxis:
    title:
      font:
        color: '#FF4560'
      text: Forbruk (kWh)
  yaxis2:
    title:
      text: Pris (kr/kWh)
    tickmode: sync
    tickformat: .2f
  yaxis3:
    visible: false
    range:
      - 0
      - 1
  yaxis9:
    visible: false
    range:
      - 0
      - 1
entities:
  - entity: sensor.kaifa_active_power_import
    name: Forbruk
    yaxis: 'y'
    marker:
      color: '#FF4560'
    xperiod: 3600000
    statistic: mean
    period: hour
    type: bar
    unit_of_measurement: kWh
    filters:
      - map_y_numbers: y/1000.0
  - entity: sensor.hourly_cumulative_power_import
    xperiod: 3600000
    yaxis: 'y'
    showlegend: false
    type: bar
    filters:
      - fn: |-
          ({states}) => {
            const state = states.slice(-1)[0];
            const ys = [state.state];
            let d = new Date(state.last_changed);
            //d.setHours(d.getHours(), 30, 0, 0); // 30 minutes to center bar on period
            d.setHours(d.getHours(), 0, 0, 0); // use xperiod unstead of 30 minutes offset
            const xs = [d];
            return { xs, ys };
          }
  - entity: sensor.nordpool_kwh_krsand_nok_3_10_025
    attribute: raw_today
    name: Pris
    yaxis: y2
    line:
      color: '#008FFB'
    filters:
      - fn: |-
          ({meta}) => {
            const ys = [];
            const xs = [];
            //let state = states.slice(-1)[0];
            let raw = meta.raw_today;
            for (let i = 0; i < raw.length; i++){
              let start = new Date(raw[i].start);
              xs.push(start);
              let end = new Date(raw[i].end);
              xs.push(end);
              ys.push(raw[i].value);
              ys.push(raw[i].value);
            }
            return { xs, ys };
          }
  - entity: sensor.nordpool_kwh_krsand_nok_3_10_025
    attribute: raw_tomorrow
    name: Pris i morgen
    yaxis: y2
    line:
      color: '#00E396'
    filters:
      - fn: |-
          ({meta}) => {
            const ys = [];
            const xs = [];
            //let state = states.slice(-1)[0];
            let raw = meta.raw_tomorrow;
            for (let i = 0; i < raw.length; i++){
              let start = new Date(raw[i].start);
              start.setDate(start.getDate() - 1); // subtract one day
              xs.push(start);
              let end = new Date(raw[i].end);
              end.setDate(end.getDate() - 1); // subtract one day
              xs.push(end);
              ys.push(raw[i].value);
              ys.push(raw[i].value);
            }
            return { xs, ys };
          }
  - entity: sensor.ps_lowest_price_output
    attribute: schedule
    yaxis: y3
    name: Strømsparing
    fill: tozeroy
    fillcolor: '#00FF0025'
    line:
      width: 0
    filters:
      - fn: |-
          ({states, meta}) => {
            const ys = [];
            const xs = [];
            let schedule = meta.schedule;
            for (let i = 0; i < schedule.length; i++){
              let start = new Date(schedule[i].time);
              xs.push(start);
              ys.push(schedule[i].value);
            }
            // extend to midnight
            let end = new Date(schedule.slice(-1)[0].time);
            end.setDate(end.getDate() + 1);
            xs.push(end);
            ys.push(schedule.slice(-1)[0].value);

            return { xs, ys };
          }
  - entity: ''
    name: Now
    yaxis: y9
    showlegend: false
    line:
      width: 1
      color: deepskyblue
      dash: dash
    x: $ex [Date.now(), Date.now()]
    'y':
      - 0
      - 1

Additional context
Add any other context about the problem here.

@FSund FSund added the bug Something isn't working label Feb 14, 2023
@dbuezas
Copy link
Owner

dbuezas commented Feb 14, 2023

Interesting, can you try changing to "refresh_interval: auto"?
This will use updates coming to from the websocket instead of actively making requests. If this behaves differently, it may ve a clue as to what's going wrong

@FSund
Copy link
Author

FSund commented Feb 14, 2023

I'll try auto, thanks!

The "now" line and rightmost, orange bar (sensor.hourly_cumulative_power_import) do update, by the way, if that helps.

@dbuezas
Copy link
Owner

dbuezas commented Feb 14, 2023

Got it. There may be an issue with the part of the caching system that removes duplicates, but I can't be sure

@jazzmonger
Copy link

Im having the same issue.

image

you can see all values flatline after a minute or so. then I have to reload the page. happens on all devices, all browsers.

setting it to :auto seems to resolve it, but it is nice having granular control over update time. some graphs you really want more realtime info, other can go hours before you need an update.

@dbuezas
Copy link
Owner

dbuezas commented Feb 16, 2023

other can go hours before you need an update

Note that auto does exactly that automatically. It receives updates pushed directly from home assistant. The only reason I left the update_interval option is for compatibility with the standard history card. I'll look into it when I have time, but don't be afraid of using auto :)

@FSund
Copy link
Author

FSund commented Feb 16, 2023

Quick update: auto does not seem to resolve the issue on the tablet. Any debugging steps I can do?

@dbuezas
Copy link
Owner

dbuezas commented Feb 16, 2023

That's super odd!

  • What OS does the table have?
  • Do you use the HA app or a browser (which?)
  • What kinds of entities does is happen with? (statistics, periods, etc)
  • Is it consistent?
  • Anything else you can provide

@jazzmonger
Copy link

jazzmonger commented Feb 17, 2023 via email

@FSund
Copy link
Author

FSund commented Feb 17, 2023

That's super odd!

  • What OS does the table have?

Android 12

  • Do you use the HA app or a browser (which?)

I'm using the HA app.

I'll try using Wallpanel today and see if anything changes.

  • What kinds of entities does is happen with? (statistics, periods, etc)

It seems to only happen to the statistics entity

  - entity: sensor.kaifa_active_power_import
    name: Forbruk
    yaxis: 'y'
    marker:
      color: '#FF4560'
    xperiod: 3600000
    statistic: mean
    period: hour
    type: bar
    unit_of_measurement: kWh
    filters:
      - map_y_numbers: y/1000.0
  • Is it consistent?

Yes, it's been happening since I created the plot about two weeks ago.

@dbuezas
Copy link
Owner

dbuezas commented Feb 17, 2023

Ok, I see. I have a hunch then. The API for statistics behaves somewhat different than the normal history one.
In the normal history API, you ask for an interval and the server gives you all data points within that interval.
In the statistics one, it seems to compute them on the fly and probably doesn't return anything if the interval is shorter than the requested period.
@FrnchFrgg, your contribution first introduced statistics support, do you know anything in this regard?

@dbuezas
Copy link
Owner

dbuezas commented Feb 17, 2023

(note that refresh_interval: auto doesn't actually work with statistics, it only triggers a request to the rest API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants