OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
Apache License 2.0
133 stars 32 forks source link

Plot not drawing a line #95

Closed MartinAirN closed 6 months ago

MartinAirN commented 6 months ago

Describe the bug Using the new Plot feature the graph appears as expected, however the line is not drawn. Tested with sensors:

To Reproduce Steps to reproduce the behavior:

  1. Create an automation with:
    background: white
    rotate: 0
    payload:
    - type: plot
    x_start: 10
    y_start: 20
    x_end: 199
    y_end: 119
    duration: 3600
    low: -2
    high: 8
    ylegend:
      position: left
      color: red
    data:
      - entity: sensor.power_consumption
        width: 3
  2. View the plot

Expected behavior A plot appears with a line drawn in.

Screenshots History of sensor: image

Plot: Graph Not Working

Additional context HomeAssistant Core: 2023.12.3 (docker) HomeAssistant Frontend 20231208.2 OpenEPaperLink 0.4.1.1

Installed through HACS

jonasniesner commented 6 months ago

can you try duration: 36000 ?

MartinAirN commented 6 months ago

can you try duration: 36000 ?

This indeed does work, interesting.

(also noted the example code has 3600: https://github.com/jonasniesner/open_epaper_link_homeassistant/blob/main/docs/drawcustom/supported_types.md#plot)

edit: Well, i said work:

using 100000: Graph Not Working - 100000

But using 6000: Graph Not Working - 6000

It seems the lower the number the less of the graph it fills.

jonasniesner commented 6 months ago

I think this is the recorder not having the data ready because most on the front

MartinAirN commented 6 months ago

I think this is the recorder not having the data ready because most on the front

Hmmm, any way to make sure this is the case? As when I use the config below it does seem to update according correctly matching the history.

background: white
rotate: 0
payload:
  - type: icon
    value: flash
    x: 4
    "y": 0
    size: 40
    color: black
  - type: text
    value: Power Consumption &
    x: 48
    "y": 4
    size: 15
    color: black
  - type: text
    value: Solar Generation
    x: 130
    "y": 24
    size: 15
    color: red
  - type: plot
    x_start: 10
    y_start: 44
    x_end: 284
    y_end: 119
    duration: 100000
    low: -2
    high: 8
    ylegend:
      position: left
      color: red
    data:
      - entity: sensor.power_consumption
        width: 1
      - entity: sensor.solar_power_in_kw
        color: red

Graph Not Working - With Data

jonasniesner commented 6 months ago

yes, i am sure, your picture confirms it. With longer durations, there is less missing data at the start

MartinAirN commented 6 months ago

yes, i am sure, your picture confirms it. With longer durations, there is less missing data at the start

But isnt the new data being added on the right? image

image

I would therefore expect the data is there but not requested or displayed.

MartinAirN commented 6 months ago

Looking at the code, and seeing as it is exactly one hour difference I am thinking it is due to UTC vs local timezone.

            end = dt.now()
            start = end - duration

My local timezone is UTC+1. However, the docker is running UTC. So if dt.now() returns UTC+1 but the input to all_states = get_significant_states(hass, start_time=start, entity_ids=[plot["entity"] for plot in element["data"]], significant_changes_only=False, minimal_response=True, no_attributes=False) expects UTC then it effectively requests with start_time=now.

Unless of course the start time is more subtracted from UTC+1, as then it requests more of the past which is then overlapping with available data.

jonasniesner commented 6 months ago

Thank you for this tip, fixed in 70ee3f1