kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.96k stars 232 forks source link

[Question] secondary Y-axis night time #903

Closed Pimentoso closed 1 year ago

Pimentoso commented 1 year ago

Hello, this is probably not the right place to ask this, feel free to redirect me somewhere else

I find adding a night overlay on 24-hour charts really useful, like in this example: https://github.com/kalkih/mini-graph-card#alternate-y-axis

Is there a way to configure the day/night axis to pull data from the sun entity?

ildar170975 commented 1 year ago

Is there a way to configure the day/night axis to pull data from the sun entity?

A graph is build based on a particular entity, not some template. You have to create a template sensor for day/night and then use this sensor for the 2nd axis.

A possible example:

template:
  - sensor:
      - name: night
        icon: mdi:power-sleep
        state: >-
          {% if is_state('sun.sun','above_horizon') -%}
          {{ 0 | int }}
          {%- else -%}
          {{ 1 | int }}
          {%- endif %}
type: custom:mini-graph-card
entities:
  - entity: sensor.processor_use
  - entity: sensor.night
    show_line: false
    show_fill: true
    show_state: false
    show_points: false
    show_legend: false
    y_axis: secondary
    color: grey
hours_to_show: 72
points_per_hour: 60
line_width: 1
smoothing: false
aggregate_func: last

image

Please ask similar questions in the Community and leave Github for reporting bugs & feature requests. Let us know if you are satisfied with this answer, then the issue will be closed. Any further discussions may be continued in the Community.

michele-ferri-iubenda commented 1 year ago

Thanks @ildar170975 I still have a long way to go with yaml sensor syntax. This example is good enough for my use! Feel free to close this. I will use the community thread next time.