Open parautenbach opened 1 year ago
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
.
I think I might have a similar feature request. It would be nice if I could show or hide the entity in the graph depending on the value of an entity state. I'm unsure if there's a way to achieve this.
series:
- entity: sensor.some_sensor
show:
in_chart: '{{state_attr("sensor.some_sensor", "boolean_state")}}'```
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
It would still be nice to get more dynamic bahaviour. :-)
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
.
@parautenbach As an alternative I am using the show object to hide the senor from the chart, but use it in the fucntion.
type: custom:apexcharts-card
series:
- entity: sensor.solar_house_consumption_w
show:
in_chart: false
Maybe that can work for you use case too?
Thanks, but that's not quite what's needed here.
Perhaps a picture would help:
Here I'm displaying both a percentage of the day that's fair weather as well as the duration. Day length obviously varies over a year, so the problem is that what's 100% changes.
I managed to get this working at the time, but completely forgot to circle back here.
This post on the community forum helped.
This is my current solution, which is fine, but can definitely be more readable and digest with direct access to the states object:
- type: custom:apexcharts-card
series:
- entity: sensor.fair_weather_time
transform: "return x / parseFloat(hass.states['sensor.home_sun_daylight'].state) * 100;"
color: var(--custom-color-yellow)
min: 0
max: 100
chart_type: radialBar
apex_config:
title:
text: Fair Weather
legend:
show: false
plotOptions:
radialBar:
startAngle: -170
endAngle: 170
dataLabels:
name:
show: false
value:
show: true
fontSize: 10px
offsetY: -4
# https://community.home-assistant.io/t/apexcharts-card-a-highly-customizable-graph-card/272877/2608
# alternative chart: https://github.com/AmoebeLabs/flex-horseshoe-card
formatter: |
EVAL:function (percentage) {
// would've loved to make this snippet more readible, but getElementsByTagName returns some kind of live object
// which means you need to resolve the whole thing; can't make no hass object first.
const daylight = parseFloat(document.getElementsByTagName('home-assistant')[0].hass.states['sensor.home_sun_daylight'].state);
const value = percentage / 100 * parseFloat(daylight);
const hour = Math.floor(value);
const minute = Math.round((value - hour) * 60);
return [`${hour}h${minute.toString().padStart(2, '0')}m`, `(${percentage.toFixed(0)}%)`];
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
Please. :-)
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.
.
Checklist
dev
branchIs your feature request related to a problem? Please describe. I have a highly dynamic chart. My original idea was to allow and EVAL function to set the min and max of a radialBar chart, but I've since figured I don't need that, so instead I'd like to access another entity's value from within a
formatter
'sEVAL: function
block.My example: I have a radialBar chart that shows the percentage of fair weather for the current day. My HA template sensor doesn't take clear skies at night into account, since I'm only interested in daytime fair weather. The consequence is that the percentage of fair weather time per day is then a function of the daylength, which is dynamic. In other words, if the daylength today is 13h15 and the fair weather was 10h12, then it's 76.98%, but tomorrow the daylength will be different. I'd like to use an EVAL function then to access my daylength sensor in order to set the
max
field for the radialBar chart.Describe the solution you'd like A
states
object with access to all entities. Many custom cards, e.g., the famous custom button card and card-mod allow this.Describe alternatives you've considered I've tried a number of hacks, but nothing that could achieve this.
Additional context Nothing I can think of.