Show the current day from midnight to midnight #220
Replies: 8 comments 17 replies
-
Hello, Thanks for sharing, I suggest a shorter version for the time_offset and some other small improvements: type: custom:plotly-graph
time_offset: $fn () => (86400000-(Date.now() % 86400000)).toFixed(0) + 'ms'
entities:
- entity: sensor.tmp_dehors_temperature
name: Hier
time_offset: 1d
filters:
- force_numeric
- resample: 5m
- sliding_window_moving_average:
window_size: 15
extended: true
centered: true
type: line
- entity: sensor.tmp_dehors_temperature
name: Today
filters:
- force_numeric
- store_var: today
- resample: 5m
- sliding_window_moving_average:
window_size: 15
extended: true
centered: true
type: line
showlegend: false
- entity: sensor.nothing_now
name: now
yaxis: y9
showlegend: false
line:
width: 1.5
dash: dot
color: '#e68a00'
filters:
- force_numeric
- fn: () => { return {xs:[Date.now(),Date.now()], ys:[0,1]} }
layout:
showlegend: true
yaxis9:
rangemode: tozero
xaxis:
nticks: 3
dragmode: false
config:
scrollZoom: false
hours_to_show: 24
refresh_interval: auto
title: $fn ( { vars } ) => 'Températures Today ' + vars.today.ys.slice(-1) + '°C' |
Beta Was this translation helpful? Give feedback.
-
Hi Miljbee, Thx for the nice suggestions! The short version: |
Beta Was this translation helpful? Give feedback.
-
Good catch, I should have think twice before posting. I will try to fix
it...
Le mar. 31 janv. 2023, 16:11, Martin ***@***.***> a écrit :
… Hi Miljbee,
Thx for the nice suggestions!
The short version: $fn () => (86400000-(Date.now() %
86400000)).toFixed(0) + 'ms' should do the job one would say, but the
graph shifts 1 hour, so the graphs starts on 1am and ends on 1am. It's a
timezone thing I think...
—
Reply to this email directly, view it on GitHub
<#220 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE3YLPVS5ZEISFHHQMYWPLWVETQLANCNFSM6AAAAAAUME35WA>
.
You are receiving this because you commented.Message ID:
<dbuezas/lovelace-plotly-graph-card/repo-discussions/220/comments/4831037@
github.com>
|
Beta Was this translation helpful? Give feedback.
-
I think this works fine: type: custom:plotly-graph
hours_to_show: 24
time_offset: |-
$fn ({ getFromConfig }) => {
const ms_to_show = getFromConfig('hours_to_show') * 60 * 60 * 1000;
const now_utc = Date.now() - new Date().getTimezoneOffset() * 60 * 1000;
return ms_to_show - now_utc % ms_to_show + 'ms'
}
title: $fn({getFromConfig}) => 'Showing ' + getFromConfig('hours_to_show')+'h'
entities:
- entity: sensor.openweathermap_temperature But it obviously doesn't work for weeks, months or years. |
Beta Was this translation helpful? Give feedback.
-
For the config support of this, I'm think of something like this to get the start of the range: // Alternatives welcome. Javascript's Date class is so cumbersome.
year = new Date(new Date().setMonth(0,1)).setHours(0,0,0,0);
month = new Date(new Date().setDate(0)).setHours(0,0,0,0);
week = new Date(new Date().setDate(new Date().getDate() + 1 - new Date().getDay())).setHours(0,0,0,0);
day = new Date().setHours(0,0,0,0);
hour = new Date().setMinutes(0,0,0);
minute = new Date().setSeconds(0,0); And similarly for the end dates. Then the equivalency should be: hours_to_show = end - start;
time_offset = end - now - timezoneOffset ; |
Beta Was this translation helpful? Give feedback.
-
From: https://github.com/dbuezas/lovelace-plotly-graph-card#dynamic-relative-time
Released in v3.1.0 |
Beta Was this translation helpful? Give feedback.
-
🤣
BlueMail voor Android downloaden
Op 31 jan. 2023 21:25, om 21:25, David Buezas ***@***.***> schreef:
…Correct, date-fns handles the offsets.
The feature looks like this:
```yaml
hours_to_show: current_day
```
And the feature is called `Dynamic Relative Time`. ChatGPT is amazing
for brainstorming names of things
<img width="608" alt="image"
src="https://user-images.githubusercontent.com/777196/215874404-ee973085-f3f6-4a0a-93ba-436843c9c8de.png">
--
Reply to this email directly or view it on GitHub:
#220 (reply in thread)
You are receiving this because you authored the thread.
Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Hi,
If you want to show the current day from midnight to midnight you will have to set hours_to_show to 24 and the time_offset to the remaining hours on the day, so this depends on what time it is when you are looking at the graph. You can calculate the remaining hours using a universal function.
Be aware that the time_offset with the universal funcion has to be before the
entities
due to order dependencies.Beta Was this translation helpful? Give feedback.
All reactions