Enphase Envoy with Energy Dashboard

Ok a noob question here. You say it’s okay if my sensor says energy

  1. Does that mean I change the code in the yaml to “energy” where it says “power” or is it okay to leave it as power?

  2. Also my sensors are “sensors.enphase…” I assume I change the entry from “sensors.envoy…” to “sensors.enphase”?

And one more beginner question please.

  1. In the code where you have “sensor.envoy_SERIALNUMBER_current_power_consumption”, do I replace the SERIALNUMBER with the serial number of my Envoy or is that just calling the serial number from the already integrated system?

Yeah, when I originally started this project, as I had added my enphase envoy to Home Assistant in June 2021, mine were named …_current_energy_consumption and …_current_energy_production.
Someone mentioned the names had changed in late July 2021 however my names did not update (I assume this is only applied to newly added devices to the updated integration so it wont break anything on existing devices).
I then decided to test this and removed my enphase integration and re-added it and the names changed to …_current_power_consumption and …_current_power_production

In your case all you have to do is do a find/replace on my code whereever it says _current_power and replace with _current_energy
Alternatively, you could go into configuration / integrations / enphase / … / delete and re-setup your enphase envoy.

Yes, change the sensor names in the code to exactly match whatever your sensor names in your home assistant are. Go to developer tools / states / and confirm and make note of the sensor names containing _current

I only put SERIALNUMBER in the code as my sensor names actually had my physical envoy serial number in the sensor name. I wasnt comfortable broadcasting my envoy serial number here so I replaced my 12 digit serial number like 123456789012 with SERIALNUMBER. Go to developer tools / states / and confirm and make note of the sensor names containing _current. Your sensors may or may not have the serial number in the name.

1 Like

I have accessed this http://envoy.local/production.json file before but I never felt the need to fully understand how I would extract data from it until I read your post.

Here is some of the output when I view the .JSON file from my envoy.

Screen Shot 2021-08-16 at 11.23.41 pm

Tonight, I decided to read up on JSON format and tried to teach myself something new.

This is what I came up with

sensor:
  - platform: rest
    resource: http://envoy.local/production.json
    name: "Consumption Voltage"
    value_template: '{{ value_json.consumption[0].rmsVoltage }}'
    device_class: voltage
    unit_of_measurement: V

  - platform: rest
    resource: http://envoy.local/production.json
    name: "Consumption Power Factor"
    value_template: '{{ value_json.consumption[0].pwrFactor }}'
    device_class: power_factor
    unit_of_measurement: '%'

and this was the end result

Screen Shot 2021-08-16 at 11.20.51 pm

Screen Shot 2021-08-17 at 12.07.08 am

I’m getting a little lost here on what I ought to be doing with my Envoy-C model that’s integrated into HA. This is an older model that doesn’t have consumption data, and doesn’t expose envoy.local/production.json.

With an Envoy-C I have the following sensors:

  • sensor.envoy_{serial number}_current_energy_production
  • sensor.envoy_{serial number}_today_s_energy_production
  • sensor.envoy_{serial number}_last_seven_days_energy_production
  • sensor.envoy_{serial number}_lifetime_energy_production

Is the expectation that HA’s Enphase integration will expose these sensors with Energy in a future update?

If that is the case, am I correct that I would need some other device to monitor consumption and export?

Yes thats correct - you need a newer Envoy to allow monitor consumption or use a separate device. I have an Envoy that records consumption and production, but I also have a second way of getting this data from a device called a Flukso that counts pulses from two power meters

My envoy-s is mounted on the side of my house next to the switchboard. My Envoy-S has a CT clamp clamped around the mains wire coming out of my meter to measure consumption which then leads into the envoy-s which measures the consumption data coming from this clamp.

Envoy-S stating it does consumption

CT Clamp
image

The Envoy C appears to be a little more portable, only meant for indoors and I assume it only talks to the microinverters at the back of your solar panels.

Envoy-C not mentioning anything about the ability to read consumption.

Only the Envoy-S metered version has the Consumption Monitoring capabilty.

I found this link that confirms this.
https://www4.enphase.com/en-uk/products-and-services/envoy/family

I am not in a hurry to bruteforce my Envoy Installer Password, but I was able to create 2 sensors based on the .json that doesnt need authentication at Enphase Envoy with Energy Dashboard - #100 by del13r

If you want to connect to the installer .json, I would check this link

and try these configuration variables

authentication string (optional)
Type of the HTTP authentication. basic or digest.

username string (optional)
The username for accessing the REST endpoint.

password string (optional)
The password for accessing the REST endpoint.

Thanks for your efforts @del13r - I’ve used your code example and I also have setup sensors using the production.json file. Your help was invaluable so thanks again! I changed the frequency the file is read by including

scan_interval: 1

Also thanks for the link to the RESTful sensor - I’ve spent a few hours and have been able to access the password protected installer .json however I have come across an issue I don’t know how to fix - the json data coming from that installer json isn’t 100% formatted correctly as json - this is what comes out - note it’s missing the start and end { } and the word data isn’t enclosed in quotes "

data: {"production":{"ph-a":{"p":3621.602,"q":305.704,"s":3627.168,"v":248.652,"i":14.582,"pf":1.0,"f":50.0},"ph-b":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0},"ph-c":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0}},"net-consumption":{"ph-a":{"p":-3195.826,"q":-686.842,"s":3277.01,"v":248.674,"i":13.17,"pf":-0.98,"f":50.0},"ph-b":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0},"ph-c":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0}},"total-consumption":{"ph-a":{"p":425.776,"q":-992.546,"s":351.08,"v":248.663,"i":1.412,"pf":1.0,"f":50.0},"ph-b":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0},"ph-c":{"p":0.0,"q":0.0,"s":0.0,"v":0.0,"i":0.0,"pf":0.0,"f":0.0}}}

It should look like this:

{"data":{"production":{"ph-a":{"p":3621.602,"q":305.704,"s":3627.168,"v":248.652,"i":14.582,"pf":1,"f":50},"ph-b":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0},"ph-c":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0}},"net-consumption":{"ph-a":{"p":-3195.826,"q":-686.842,"s":3277.01,"v":248.674,"i":13.17,"pf":-0.98,"f":50},"ph-b":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0},"ph-c":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0}},"total-consumption":{"ph-a":{"p":425.776,"q":-992.546,"s":351.08,"v":248.663,"i":1.412,"pf":1,"f":50},"ph-b":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0},"ph-c":{"p":0,"q":0,"s":0,"v":0,"i":0,"pf":0,"f":0}}}}

Which then formats correctly as:

{
  "data": {
    "production": {
      "ph-a": {
        "p": 3621.602,
        "q": 305.704,
        "s": 3627.168,
        "v": 248.652,
        "i": 14.582,
        "pf": 1,
        "f": 50
      },
      "ph-b": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      },
      "ph-c": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      }
    },
    "net-consumption": {
      "ph-a": {
        "p": -3195.826,
        "q": -686.842,
        "s": 3277.01,
        "v": 248.674,
        "i": 13.17,
        "pf": -0.98,
        "f": 50
      },
      "ph-b": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      },
      "ph-c": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      }
    },
    "total-consumption": {
      "ph-a": {
        "p": 425.776,
        "q": -992.546,
        "s": 351.08,
        "v": 248.663,
        "i": 1.412,
        "pf": 1,
        "f": 50
      },
      "ph-b": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      },
      "ph-c": {
        "p": 0,
        "q": 0,
        "s": 0,
        "v": 0,
        "i": 0,
        "pf": 0,
        "f": 0
      }
    }
  }
}

My level of skills on Home Assistant are quite low - I know how to fix this in php or in a bash script but I’m struggling on how to fix it in Home Assistant - would I use a value template or something else?

Cheers

1 Like

Instead of focusing on trying to insert a missing character at the start, try figuring out how to ignore the string data: or the first 5 characters (6 including the space). The great news is that data: only appears once at the very beginning.

ive removed that string from the beginning of the JSON and your JSON is valid after that.

Screen Shot 2021-08-18 at 6.43.57 am

This approach might be easier as I feel that filtering a response is easier than modifying a response.

Maybe something like

sensor:
  platform: command_line
  command: curl ... | jq 

https://curl.se/docs/manual.html

https://stedolan.github.io/jq/manual/

1 Like

Thanks so much for the pointer @del13r - yes your suggestion to simply trim is a much better solution - I’ll investigate this now.

Thanks for that - I just did some testing too - I can’t use jq as it requires a properly formatted json input, however I haev had luck with sed

curl --anyauth -u installer:installerpassord --silent envoy.local/stream/meter --stderr - | sed 's/data://'

This strips the data: and leaves nicely formatted json as you predicted. I’m just about to create a sensor with this.

1 Like

maybe try adding ^ so that it only checks the start of the string and a space after data to be like this so it gets rid of the space

sed 's/^data: //'

even this first 6 character delete will work for what you are trying to do

sed 's/^......//'
1 Like

Not much luck - seems teh curl command fails

2021-08-18 14:17:47 ERROR (SyncWorker_1) [homeassistant.components.command_line] Timeout for command: curl --anyauth -u installer:Password --silent envoy/local/stream/meter --stderr - | sed 's/data: //'
2021-08-18 14:17:47 WARNING (SyncWorker_1) [homeassistant.components.command_line.sensor] Empty reply found when expecting JSON data

I noticed if I run that entire curl command from terminal within HA or another unix system that it sometimes runs and other times it doesn’t. Strange cause going to the url in a browser works 100% every time. I wonder if I need to fool it to think I’m accessing via a web-browser - I’ll check to see if curl allows this.

try removing --anyauth and test

and then try --digest
https://curl.se/docs/manpage.html#--digest

image

qop refers to digest

I’m still getting timeout when I try --digest, however from terminal it works 100% every time so that’s weird … I’m going to try a REST sensor instead of a command_line and see what happens

maybe try replacing envoy.local with static IP (I hope it is static) of envoy just incase its a dns issue

Yes I have that already - I change it to envoy.local when posting here to not confuse people with my internal ip … and of course rest: won’t work as I can’t use curl with that so I’m stumped

what is --stderr doing for you?
Also, have we confirmed sed is installed/available in home assistant?

I was looking at different online examples and saw that outputting to -stderr helps when piping commands so that the next command isn’t overloaded. I’ll try without it and see. sed seems to be installed - if I go to terminal within Home assistant I can run the command and it works fine. I assume of course that the terminal has the same environment that the sensors etc have?

Yeah, just troubleshooting and trying to eliminate the difference between why your terminal works but home assistant doesn’t.
I wasnt sure if your terminal testing was just trying the commands from another machine or the terminal of home assistant.
Perhaps try testing sed against the production.json as it doesnt have authentication it could be easier to test with before progressing to installer.json

image

image