-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
header.show_states
does not display current value when using data_generator
#840
Comments
So the workaround worked for you too? :) |
Same issue:
The workaround seems to work (the "Oggi" value in the second chart's header value return the correct value), but it messes up the line chart. type: custom:apexcharts-card
graph_span: 1d
span:
start: day
update_interval: 10min
now:
show: true
label: Adesso
color: "#ffbc15"
header:
show: true
title: Costo elettricità
show_states: true
colorize_states: true
title_actions:
tap_action:
action: navigate
navigation_path: energy
cache: true
apex_config:
legend:
show: true
grid:
show: false
chart:
foreColor: "#999999"
dataLabels:
enabled: true
style:
fontSize: 10px
background:
opacity: 0.7
stroke:
curve: stepline
show:
last_updated: true
experimental:
color_threshold: true
all_series_config:
unit: €/kWh
header_actions:
tap_action:
action: navigate
navigation_path: energy
show:
legend_value: false
extremas: true
yaxis:
- decimals: 3
series:
- entity: sensor.pun_prezzo_zonale
data_generator: >
const hourlyValues = [];
const currentDate = new Date();
currentDate.setHours(0, 0, 0, 0);
for (let hour = 0; hour < 24; hour++) {
const hourStr = String(hour).padStart(2, '0');
const value = entity.attributes[`oggi_h_${hourStr}`];
if (value !== undefined) {
const time = new Date(currentDate);
time.setHours(hour, 0, 0, 0);
hourlyValues.push([time.getTime(), value]);
}
}
const priceNow = hourlyValues[currentDate.getHours()];
hourlyValues[currentDate.getHours()] = hourlyValues[23];
hourlyValues[23] = priceNow;
return hourlyValues;
name: Oggi
type: line
color: "#f44336"
unit: €/kWh
stroke_width: 3
float_precision: 5
- entity: sensor.pun_prezzo_zonale
data_generator: >
const hourlyValues = [];
const currentDate = new Date();
current date and time currentDate.setHours(0, 0, 0, 0);
for (let hour = 0; hour < 24; hour++) {
const hourStr = String(hour).padStart(2, '0');
const value = entity.attributes[`domani_h_${hourStr}`];
if (value !== undefined) {
const time = new Date(currentDate);
time.setHours(hour, 0, 0, 0);
hourlyValues.push([time.getTime(), value]);
}
}
return hourlyValues;
name: Domani
type: line
color: "#999999"
unit: €/kWh
stroke_width: 1
stroke_dash: 5
float_precision: 5 |
I ended up stylizing it with card-mod just to overwrite those values: Here's my final snippet if anyone is interested: type: custom:apexcharts-card
graph_span: 1d
span:
start: day
update_interval: 10min
now:
show: true
label: Adesso
color: "#ffbc15"
header:
show: true
title: Costo elettricità
show_states: true
colorize_states: true
title_actions:
tap_action:
action: navigate
navigation_path: energy
cache: true
apex_config:
legend:
show: true
grid:
show: false
chart:
foreColor: "#999999"
dataLabels:
enabled: true
style:
fontSize: 10px
background:
opacity: 0.7
stroke:
curve: stepline
show:
last_updated: true
experimental:
color_threshold: true
all_series_config:
unit: €/kWh
header_actions:
tap_action:
action: navigate
navigation_path: energy
show:
legend_value: false
extremas: true
yaxis:
- decimals: 3
series:
- entity: sensor.pun_prezzo_zonale
data_generator: >
const hourlyValues = []; const currentDate = new Date(); // Get the
current date and time currentDate.setHours(0, 0, 0, 0); // Set the time
to midnight (start of the day)
for (let hour = 0; hour < 24; hour++) {
const hourStr = String(hour).padStart(2, '0');
const value = entity.attributes[`oggi_h_${hourStr}`];
if (value !== undefined) {
const time = new Date(currentDate); // Copy of the midnight date
time.setHours(hour, 0, 0, 0); // Set hours, minutes, seconds, and milliseconds
hourlyValues.push([time.getTime(), value]); // Push timestamp and value
}
}
return hourlyValues;
name: Oggi
type: line
color: "#f44336"
unit: €/kWh
stroke_width: 3
float_precision: 5
- entity: sensor.pun_prezzo_zonale
data_generator: >
const hourlyValues = []; const currentDate = new Date(); // Get the
current date and time currentDate.setHours(0, 0, 0, 0); // Set the time
to midnight (start of the day)
for (let hour = 0; hour < 24; hour++) {
const hourStr = String(hour).padStart(2, '0');
const value = entity.attributes[`domani_h_${hourStr}`];
if (value !== undefined) {
const time = new Date(currentDate); // Copy of the midnight date
time.setHours(hour, 0, 0, 0); // Set hours, minutes, seconds, and milliseconds
hourlyValues.push([time.getTime(), value]); // Push timestamp and value
}
}
return hourlyValues;
name: Domani
type: line
color: "#999999"
unit: €/kWh
stroke_width: 1
stroke_dash: 5
float_precision: 5
card_mod:
style: >
#header__states > div:nth-child(1) > div:nth-child(1) >
span:nth-child(1)::after { content: "{{ '%.5f' |
format(states('sensor.pun_prezzo_zonale') | float) }}";
visibility: visible;
display: block;
text-align: left;
position: absolute;
left: 0;
top: 0px;
}
#header__states > div:nth-child(1) > div:nth-child(1) > span:nth-child(1) {
visibility: hidden;
display: block;
}
#header__states > div:nth-child(2) > div:nth-child(1) >
span:nth-child(1)::after { content: "{{ '%.5f' |
format(state_attr('sensor.pun_prezzo_zonale', 'domani_h_' ~
now().strftime('%H')) | float) }}";
visibility: visible;
display: block;
text-align: left;
position: absolute;
left: -45px;
top: 0px;
}
#header__states > div:nth-child(2) > div:nth-child(1) > span:nth-child(1) {
visibility: hidden;
display: block;
}
#header__states > div:nth-child(1) > div:nth-child(1) > span:nth-child(2) {
position: absolute;
right: -45px;
top: 3px; // Align to the same height as the first styled element
}
#header__states > div:nth-child(2) > div:nth-child(1) > span:nth-child(2) {
position: absolute;
right: 0px;
top: 3px; // Align to the same height as the first styled element
}
#header__states > div.actions:nth-child(2) > div:nth-child(2) {
position: absolute;
right: 98px !important;
top: px; // Align to the same height as the first styled element
} |
Researching the same issue, I came across this comment. Using 'in_header: raw' solved the problem for me without the need of any workaround. |
Doesn't seems to work for me unfortunately: I'm using EDIT: show:
in_header: before_now
|
Checklist
Describe the bug
The value
show_states
does not show the current state of a sensor when using thedata_generator
.Instead. it uses the last value in the list provided.
Version of the card
Version: v2.1.2
To Reproduce
This is the configuration I used:
Screenshots


This screenshot was taken around 12:30, but we can see that the price in the header does not reflect the current price.
In this image we can see that the price does equal the last value in the list.
Expected behavior
I expect the header value to be the current value of the sensor or the value closest to now.
Desktop (please complete the following information):
Irrelevant but
Additional context
For now, the issue can be fixed by making sure the last entry in the list to be the value you want to be displayed in the state header.
I can add this to the README as a quick and dirty fix.
For instance, I fixed it by adding:
The text was updated successfully, but these errors were encountered: