NS SolarRank API

Automated Submission Guide

01. Request API Key

02. Integration Methods

Step 1: Add to configuration.yaml

Add this rest_command to your config and restart Home Assistant.

rest_command:
  upload_solar_yield:
    url: "https://solarrank.scottbrookesdesigns.com/automate.php?key={{ key_pass }}"
    method: POST
    payload: "name={{ name_pass }}&size={{ size_pass }}&output={{ output_pass }}&dir={{ direction }}"
    content_type: "application/x-www-form-urlencoded"

Step 2: Create Automation

Create a new automation and switch to YAML Mode to paste the following:

alias: "Push Daily Solar Data"
description: "Uploads data after sunset"
triggers:
  - trigger: sun
    event: sunset
    offset: "00:30:00"
actions:
  - delay:
      minutes: "{{ range(0, 50) | random }}"
      seconds: "{{ range(0, 60) | random }}"
  - action: rest_command.upload_solar_yield
    data:
      key_pass: "YOUR_KEY"
      name_pass: "YOUR_SITE_NAME"
      size_pass: SITE_KW_SIZE
      output_pass: "{{ states('sensor.DAILY_KWH_SENSOR') }}"
      direction: "S"

Enphase IQ Gateway: Local Integration

1 Find your Gateway's IP & Serial Number

Use the Enphase App to find your local details:

  1. Open Enphase App: Menu > System > Devices > Gateway.
  2. Click "Connect Locally". Once detected, click Connect.
  3. A browser window will open (likely with a security warning). Note the IP address in the URL bar.
  4. Continue to get your Gateway Serial Number. Copy it for Step 2.

Alternative: If supported by your network, you can use envoy.local as the IP.

2 Generate a Security Token

Login to Enlighten on your browser, then click this link (replace SERIAL with your serial):

Get My Security Token

⚠️ Note: This token expires after 1 year. You must renew it annually.

3 Create & Configure your Python Script

Copy the code below into a new text file and save it as solar.py on your computer or server. Ensure you have the requests library installed (pip install requests).

Edit the "USER CONFIGURATION" section in the code with your specific details:

import requests
import time
import random

# --- USER CONFIGURATION ---
GATEWAY_IP = "192.168.x.x" # The IP from Step 1
TOKEN      = "PASTE_TOKEN_HERE" # The Token from Step 2
API_KEY    = "YOUR_RANK_KEY" # The Key from Step 01 above
SITE_NAME  = "Your System Name"
SITE_SIZE  = 10.5
DIRECTION  = "S"

# Delay 1-180 mins to stagger updates
time.sleep(random.randint(1, 180) * 60)

requests.packages.urllib3.disable_warnings()
headers = {'Authorization': f'Bearer {TOKEN}'}

try:
    r = requests.get(f"https://{GATEWAY_IP}/ivp/pdm/energy", headers=headers, verify=False, timeout=10)
    wh_today = r.json()['production']['pcu']['wattHoursToday']
    kwh_today = round(wh_today / 1000, 3)

    payload = {'name': SITE_NAME, 'size': SITE_SIZE, 'output': kwh_today, 'dir': DIRECTION}
    requests.post("https://solarrank.scottbrookesdesigns.com/automate.php?key="+API_KEY, data=payload)
except Exception as e:
    print(f"Error: {e}")
4 Automate Daily Execution
  • Linux/Pi: Add a cron job (crontab -e) to run the file nightly:
    0 21 * * * /usr/bin/python3 /path/to/solar.py
  • Windows: Use Task Scheduler to run the script daily at 9:00 PM.
  • Local Network: The script runner must be on the same network as the Enphase Gateway.

Standard Python Integration

For custom setups or non-Enphase gateways.

import requests
payload = { 'name': 'Site Name', 'size': 10.5, 'output': 42.1, 'dir': 'S' }
requests.post("https://solarrank.scottbrookesdesigns.com/automate.php?key=YOUR_KEY", data=payload)

cURL Command

curl -X POST -d "name=SITE" -d "size=10" -d "output=50" -d "dir=S" "URL?key=KEY"

History Import Tool

Backfill data from a CSV export. You need a Bulk Key to use this form.

KEY IS ONLY VALID FOR 1 SUBMISSION

📋 CSV Format:
• Column 1: Date (YYYY-MM-DD or Timestamp)
• Column 2: Total kWh (Numbers only)