I know there is a lot of confusion with all of the forks of the Enphase integration because of the authentication switch with the update to firmware 7.x. I was able to solve this using the REST sensor - no enphase integration needed.
Get a Token
All local API access now needs a token to use. For some reason the website to get the token does not work for me. So if you try that and it doesn’t work, there’s a simple way to do it via an easy python script:
import json
import requests
# REPLACE ITEMS BELOW
user='[email protected]'
password='password'
envoy_serial='your_envoy_serial_number'
# DO NOT CHANGE ANYTHING BELOW
data = {'user[email]': user, 'user[password]': password}
response = requests.post('https://enlighten.enphaseenergy.com/login/login.json?',data=data)
response_data = json.loads(response.text)
data = {'session_id': response_data['session_id'], 'serial_num': envoy_serial, 'username':user}
response = requests.post('https://entrez.enphaseenergy.com/tokens', json=data)
token_raw = response.text
print(token_raw)
You need to fill in your username, password, and the serial number of your envoy box. You can find the serial number in the enlighten app by going to Menu->Devices->Gateway.
When you run this script it will print out your token. It will look something like:
eyJraWQiOiI3ZDEwMDA1ZC03ODk5LTRkMGQtYmNiN......<trucated for clarity>
According to the docs, this token is good for 1yr at which point you will need to get another one. I just put a reminder on my calendar at 11 months to do it to ensure I don’t miss any data. So save the script so you can just run it again the next time you need a token
Make the REST sesnor in HA
Once you have the token, then you can make a rest sensor in HA:
sensor:
- platform: rest
resource: https://envoy.local/ivp/meters/readings
name: Solar Power Output
unique_id: solar_array_output_id
scan_interval: 60
value_template: "{{ value_json[0].activePower | float }}"
headers:
Authorization: Bearer <token>
verify_ssl: False
state_class: measurement
device_class: power
unit_of_measurement: W
json_attributes_path: "$.[0]"
json_attributes:
- eid
- actEnergyDlvd
- timestamp
- voltage
- current
- freq
Reload the REST entities in HA and you should see the sensor appear in the state page.
The sensor state will be the current power output in W, with some other items of interest in the attributes.
Note: this assumes your envoy box is on the same LAN as your HA instance and is reachable with the default address of envoy.local
, if it isn’t, you can replace envoy.local
with the IP of your envoy box.
Make the energy sensor to use in the Energy Dashboard
If you then want an entity that works in the energy dashboard, you can use the integration platform to do it:
sensor:
- platform: integration
name: Solar Array Production
source: sensor.solar_power_output
unit_prefix: k
unit_time: h
method: left
unique_id: solar_array_production_id
The above will make a sensor that integrates the power output over time to produce the energy measurement required by the energy dashboard.
For reference, I learned how to querey the API and get the tokens from the Enphase documentation. They also show the full JSON output of the various enpoints if you want to extract other information