Enphase Envoy - D7 firmware with JWT - A Different Approach

Here is my current setup for the enphase style view.

Setup the helpers in configuration.yaml

input_select:
  statistics_chart_range:
    initial: day
    options:
      - day
      - week
      - month
      - year

input_datetime:
  statistics_chart_date:
    has_date: true
    has_time: false

Verified they were setup
image

Then setup the template sensors in configuration.yaml

template:

  - sensor:
      - name: statistics_chart_grouping
        unique_id: statistics_chart_grouping
        state: |
          {% set grouping={
            'day':'h',
            'week':'d',
            'month':'d',
            'year':'d'}
          %}
          {% set range = states('input_select.statistics_chart_range') %}
          {{ grouping[range] }}
      - name: statistics_chart_span
        unique_id: statistics_chart_span
        state: |
          {% macro last_date_in_range(date_str,range) -%}
            {% set date=as_timestamp(date_str)|timestamp_local()|as_datetime() -%}
            {% if range=='day' -%}
              {% set end_date=date -%}
            {% elif range=='week' -%}
              {% set end_date=date + timedelta(days=(6-date.weekday())) -%}
            {% elif range=='month' -%}
              {% set month=(date.month % 12) + 1 -%}
              {% set year=date.year+iif(date.month==12,1,0) -%}
              {% set end_date=strptime(year|string + '-' + month|string + '-01', '%Y-%m-%d')-timedelta(days=1) -%}
            {% elif range=='year' -%}
              {% set end_date=strptime(date.year|string + '-12-31', '%Y-%m-%d') -%}
            {% endif -%}
            {{ as_timestamp(end_date)|timestamp_local() -}}
          {% endmacro -%}
          {% set range = states('input_select.statistics_chart_range') %}
          {% set date_str = states('input_datetime.statistics_chart_date') %}
          {% set spans={
            'day':'24',
            'week':'7',
            'month':(last_date_in_range (strptime(date_str, '%Y-%m-%d'),range)|as_datetime()).day,
            'year':last_date_in_range (strptime(date_str, '%Y-%m-%d'),range)|as_timestamp(0)|timestamp_custom('%j',0)|int +1}
          %}
          {{ spans[range] }}
      - name: statistics_chart_period
        unique_id: statistics_chart_period
        state: |
          {% set periods={
            'day':'hour',
            'week':'day',
            'month':'day',
            'year':'day'}
          %}
          {% set range = states('input_select.statistics_chart_range') %}
          {{ periods[range] }}
          
  - sensor:
      - name: statistics_chart_offset
        unique_id: statistics_chart_offset
        state: |
          {% macro last_date_in_range(date_str,range) -%}
            {% set date=as_timestamp(date_str)|timestamp_local()|as_datetime() -%}
            {% if range=='day' -%}
              {% set end_date = date + timedelta(days=1) -%}
            {% elif range=='week' -%}
              {% set end_date=date + timedelta(days=(6-date.weekday())) -%}
            {% elif range=='month' -%}
              {% set month=(date.month % 12) + 1 -%}
              {% set year=date.year+iif(date.month==12,1,0) -%}
              {% set end_date=strptime(year|string + '-' + month|string + '-01', '%Y-%m-%d')-timedelta(days=1) -%}
            {% elif range=='year' -%}
              {% set end_date=strptime(date.year|string + '-12-31', '%Y-%m-%d') -%}
            {% endif -%}
            {{ as_timestamp(end_date) -}}
          {% endmacro -%}
          {% set range = states('input_select.statistics_chart_range') %}
          {% set date_str = states('input_datetime.statistics_chart_date') %}
          {% set offset = last_date_in_range(strptime(date_str, '%Y-%m-%d'),range)|int - now()|as_timestamp(0) -%}
          {% if states('sensor.statistics_chart_grouping') == 'h' %}
            {% set offset=(offset/60/60)|round(method='ceil') %}
          {% else %}
            {% set offset=(offset/60/60/24)|round(method='ceil') + 1 %}
          {% endif %}
          {{ iif(offset >= 0,'+','') }}{{ offset }}{{ states('sensor.statistics_chart_grouping') }}

Verified they were setup
image

Then added this to scripts.yaml

statistics_chart_date_browse:
  alias: statistics_chart_date_browse
  sequence:
  - service: input_datetime.set_datetime
    target:
      entity_id: input_datetime.statistics_chart_date
    data:
      datetime: "{% set range = states('input_select.statistics_chart_range') %}\n{%
        set date = states('input_datetime.statistics_chart_date')|as_datetime %}\n{%
        set direction = direction %}\n{% if range == 'day' %}\n  {% if direction >
        0 %}\n    {% set target = date + timedelta(days=1) %}\n  {% else %}\n    {%
        set target = date - timedelta(days=1) %}\n  {% endif %}\n{% elif range ==
        'week' -%}\n  {% if direction > 0 %}\n    {% set target = date + timedelta(days=7)
        %}\n  {% else %}\n    {% set target = date - timedelta(days=7) %}\n  {% endif
        %}\n{% elif range == 'month' -%}\n  {% if direction > 0 %}\n    {% set month=((date.month)
        % 12) + 1 %}\n    {% set year=date.year+iif(date.month==12,1,0) %}\n    {%
        set target=strptime(year|string + '-' + month|string + '-01', '%Y-%m-%d')
        -%}\n  {% else %}\n    {% set month=((date.month - 2) % 12) + 1 %}\n    {%
        set year=date.year+iif(date.month==1,-1,0) %}\n    {% set target=strptime(year|string
        + '-' + month|string + '-01', '%Y-%m-%d') -%}\n  {% endif %}\n{% elif range=='year'
        -%}\n  {% if direction > 0 %}\n    {% set target=strptime((date.year|int +
        1)|string + '-01-01', '%Y-%m-%d') -%}\n  {% else %}\n    {% set target=strptime((date.year|int
        - 1)|string + '-01-01', '%Y-%m-%d') -%}\n  {% endif %}\n{% endif -%}\n{% if
        direction == 0 %}\n    {% set target = now() %}\n{% endif -%}\n{{ target }}\n"
  mode: single
  icon: mdi:arrow-right-bold-outline

Verified that was setup

I made an extra automation to rollover the graph to todays date at 12:01AM

alias: Update day of apexchart at midnight
description: ""
trigger:
  - platform: time
    at: "00:01:00"
condition: []
action:
  - service: script.statistics_chart_date_browse
    data:
      direction: 0
mode: single

Then created a dashboard view

  - theme: Backend-selected
    title: Enphase
    path: enphase
    icon: mdi:solar-power
    type: sidebar
    badges: []
    cards:
      - type: custom:config-template-card
        variables:
          offset: states['sensor.statistics_chart_offset'].state
          span: states['sensor.statistics_chart_span'].state
          period: states['sensor.statistics_chart_period'].state
          grouping: states['sensor.statistics_chart_grouping'].state
        entities:
          - sensor.statistics_chart_offset
          - sensor.statistics_chart_span
          - sensor.statistics_chart_period
          - sensor.statistics_chart_grouping
        card:
          type: custom:apexcharts-card
          graph_span: 1d
          span:
            offset: ${offset}
          stacked: true
          header:
            show: false
            title: Total Power
          series:
            - entity: sensor.power_production
              type: column
              name: Produced
              color: '#01B4DE'
              group_by:
                func: avg
                duration: 5min
            - entity: sensor.power_consumption
              transform: return x *-1 ;
              type: column
              name: Consumed
              color: '#F37320'
              group_by:
                func: avg
                duration: 5min
            - entity: sensor.power_net
              type: column
              name: Imported(+)/Exported(-)
              color: '#545456'
              group_by:
                func: avg
                duration: 5min
          yaxis:
            - min: -7000
              max: 7000
              decimals: 0
      - type: custom:mod-card
        card:
          type: horizontal-stack
          cards:
            - type: entities
              entities:
                - entity: input_datetime.statistics_chart_date
                  name: date
            - type: glance
              show_name: false
              show_state: false
              entities:
                - entity: script.statistics_chart_date_browse
                  icon: mdi:chevron-left
                  tap_action:
                    action: call-service
                    service: script.statistics_chart_date_browse
                    data:
                      direction: -1
                - entity: script.statistics_chart_date_browse
                  icon: mdi:calendar-today
                  tap_action:
                    action: call-service
                    service: script.statistics_chart_date_browse
                    data:
                      direction: 0
                - entity: script.statistics_chart_date_browse
                  icon: mdi:chevron-right
                  tap_action:
                    action: call-service
                    service: script.statistics_chart_date_browse
                    data:
                      direction: 1

Verified that was good

Alternatively, if all of this is too complex, you can just have a simple card that just shows the last 24 hours using some of my older original instructions here.
https://community.home-assistant.io/t/enphase-envoy-with-energy-dashboard/328668/618?u=del13r