# Power Monitor

A home-energy card that shows solar production on an LCD panel. The big reading, home use, battery charge and export drift gently on their own while the card is live. Move the pointer over the pixel chart, drag on it, or focus it and use the arrow keys to move the time cursor; the big reading then shows the value for that column. The segmented control switches the chart between a day, a week, a month and a year.

<demo-power-monitor>



</demo-power-monitor>

## Installation

```bash
npx shadcn-vue@latest add "https://nxui.geoql.in/r/power-monitor.json"
```

## Usage

```vue
<script setup lang="ts">
  import { ref } from 'vue';
  import PowerMonitor from '~/components/ui/power-monitor/PowerMonitor.vue';
  import type { PowerMonitorRange } from '~/components/ui/power-monitor/types';

  const range = ref<PowerMonitorRange>('day');
</script>

<template>
  <PowerMonitor
    v-model:range="range"
    :solar="4.82"
    :peak="5.7"
    :home="2.14"
    :to-battery="1.96"
    :export-power="0.72"
  />
</template>
```

Pass your own chart data with `series`. Each entry holds the columns for one range: `solar` and `home` values, a cursor label per column, axis ticks, the index of "now" and the summary rows. Columns after `now` are drawn dimmed as a forecast. Without `series` the card uses a generated sample day, week, month and year.

## Props

<table>
<thead>
  <tr>
    <th>
      Prop
    </th>
    
    <th>
      Type
    </th>
    
    <th>
      Default
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        range
      </code>
    </td>
    
    <td>
      <code>
        PowerMonitorRange
      </code>
    </td>
    
    <td>
      <code>
        'day'
      </code>
    </td>
    
    <td>
      <code>
        v-model:range
      </code>
      
      . The active range.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        title
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Power now'
      </code>
    </td>
    
    <td>
      Card title.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        subtitle
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      —
    </td>
    
    <td>
      Replaces the automatic "Live · updated 2 s ago" line.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        status
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        'Live'
      </code>
    </td>
    
    <td>
      Text in the status pill.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        solar
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        4.82
      </code>
    </td>
    
    <td>
      Solar production now, in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        peak
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        5.7
      </code>
    </td>
    
    <td>
      Peak production today, in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        home
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        2.14
      </code>
    </td>
    
    <td>
      Home use now, in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        to-battery
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        1.96
      </code>
    </td>
    
    <td>
      Power going into the battery, in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        export-power
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        0.72
      </code>
    </td>
    
    <td>
      Power exported to the grid, in kW.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        live
      </code>
    </td>
    
    <td>
      <code>
        boolean
      </code>
    </td>
    
    <td>
      <code>
        true
      </code>
    </td>
    
    <td>
      Live values drift gently. Pauses while the card is offscreen.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        interval
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        3000
      </code>
    </td>
    
    <td>
      Milliseconds between live updates.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        series
      </code>
    </td>
    
    <td>
      <code>
        PowerMonitorSeries[]
      </code>
    </td>
    
    <td>
      sample data
    </td>
    
    <td>
      Chart data per range.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        rows-up
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        11
      </code>
    </td>
    
    <td>
      Pixel rows above the baseline.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        rows-down
      </code>
    </td>
    
    <td>
      <code>
        number
      </code>
    </td>
    
    <td>
      <code>
        8
      </code>
    </td>
    
    <td>
      Pixel rows below the baseline.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#ff9a2e'
      </code>
    </td>
    
    <td>
      Solar and LCD accent colour.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        home-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#e9e9e9'
      </code>
    </td>
    
    <td>
      Home use colour.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        battery-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#4ade80'
      </code>
    </td>
    
    <td>
      "To battery" reading colour.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        export-color
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        '#7ea6ff'
      </code>
    </td>
    
    <td>
      "Export" reading colour.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        class
      </code>
    </td>
    
    <td>
      <code>
        string
      </code>
    </td>
    
    <td>
      <code>
        ''
      </code>
    </td>
    
    <td>
      Extra classes for the root element.
    </td>
  </tr>
</tbody>
</table>

## Events

<table>
<thead>
  <tr>
    <th>
      Event
    </th>
    
    <th>
      Payload
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        update:range
      </code>
    </td>
    
    <td>
      <code>
        PowerMonitorRange
      </code>
    </td>
    
    <td>
      Fires when the range changes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        cursor
      </code>
    </td>
    
    <td>
      <code>
        PowerMonitorCursor | null
      </code>
    </td>
    
    <td>
      Fires when the time cursor moves, with the column index, label, values and a forecast flag. <code>
        null
      </code>
      
       when it returns to now.
    </td>
  </tr>
</tbody>
</table>

## Accessibility

- The chart is a focusable `role="slider"`. Arrow keys move the cursor one column, Page Up and Page Down move it by a larger step, Home and End jump to the ends, and Escape returns it to now. `aria-valuetext` gives the column time.
- The range switch is a `tablist` with arrow-key navigation and `aria-selected`.
- The LCD digits carry an accessible label with the value and unit.
- With reduced motion, the chart reveal and cursor transitions are turned off.
