Enphase - Envoy V7 local API to CURL-JSON on Windows

I have an Enphase Envoy hub for my solar PV system and I’m trying to get the local data into openHAB 3 running on Window 10.

I have the CURL command and token part working and if I run the following in an elevated Windows command prompt I get an output:

curl -f -k -H "Accept: application/json" -H "Authorization: Bearer eyJra***" -X GET https://192.168.1.***/ivp/meters/readings
    {
        "eid": 70***,
        "timestamp": 1681544341,
        "actEnergyDlvd": 151670.391,
        "actEnergyRcvd": 0.000,
        "apparentEnergy": 175245.540,
        "reactEnergyLagg": 31045.032,
        "reactEnergyLead": 0.094,
        "instantaneousDemand": 2276.366,
        "activePower": 2276.366,
        "apparentPower": 2276.366,
        "reactivePower": 85.737,
        "pwrFactor": 1.000,
        "voltage": 248.142,
        "current": 9.176,
        "freq": 50.000,
        "channels": [
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 151670.391,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 175245.540,
                "reactEnergyLagg": 31045.032,
                "reactEnergyLead": 0.094,
                "instantaneousDemand": 2276.366,
                "activePower": 2276.366,
                "apparentPower": 2276.366,
                "reactivePower": 85.737,
                "pwrFactor": 1.000,
                "voltage": 248.142,
                "current": 9.176,
                "freq": 50.000
            },
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 78.489,
                "actEnergyRcvd": 0.000,
                "apparentEnergy": 206.950,
                "reactEnergyLagg": 14.369,
                "reactEnergyLead": 0.059,
                "instantaneousDemand": 0.100,
                "activePower": 0.100,
                "apparentPower": 0.987,
                "reactivePower": 0.000,
                "pwrFactor": 0.000,
                "voltage": 6.227,
                "current": 0.158,
                "freq": 50.000
            },
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 59.741,
                "apparentEnergy": 94.512,
                "reactEnergyLagg": 14.336,
                "reactEnergyLead": 0.035,
                "instantaneousDemand": 0.000,
                "activePower": 0.000,
                "apparentPower": 0.435,
                "reactivePower": -0.000,
                "pwrFactor": 0.000,
                "voltage": 3.308,
                "current": 0.132,
                "freq": 50.000
            }
        ]
    },
    {
        "eid": 70***,
        "timestamp": 1681544341,
        "actEnergyDlvd": 60008.786,
        "actEnergyRcvd": 79539.115,
        "apparentEnergy": 233910.345,
        "reactEnergyLagg": 32.593,
        "reactEnergyLead": 149246.902,
        "instantaneousDemand": -1196.775,
        "activePower": -1196.775,
        "apparentPower": 1354.263,
        "reactivePower": -440.696,
        "pwrFactor": -0.881,
        "voltage": 248.214,
        "current": 5.458,
        "freq": 50.000,
        "channels": [
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 60008.786,
                "actEnergyRcvd": 79539.115,
                "apparentEnergy": 233910.345,
                "reactEnergyLagg": 32.593,
                "reactEnergyLead": 149246.902,
                "instantaneousDemand": -1196.775,
                "activePower": -1196.775,
                "apparentPower": 1354.263,
                "reactivePower": -440.696,
                "pwrFactor": -0.881,
                "voltage": 248.214,
                "current": 5.458,
                "freq": 50.000
            },
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 600.245,
                "apparentEnergy": 0.790,
                "reactEnergyLagg": 14.147,
                "reactEnergyLead": 0.013,
                "instantaneousDemand": 0.000,
                "activePower": 0.000,
                "apparentPower": -0.000,
                "reactivePower": -0.000,
                "pwrFactor": 0.000,
                "voltage": 1.192,
                "current": -0.000,
                "freq": 50.000
            },
            {
                "eid": 17***,
                "timestamp": 1681544341,
                "actEnergyDlvd": 0.000,
                "actEnergyRcvd": 798.429,
                "apparentEnergy": 194.534,
                "reactEnergyLagg": 14.156,
                "reactEnergyLead": 0.000,
                "instantaneousDemand": -0.585,
                "activePower": -0.585,
                "apparentPower": 0.917,
                "reactivePower": 0.000,
                "pwrFactor": 0.000,
                "voltage": 4.946,
                "current": 0.186,
                "freq": 50.000
            }
        ]
    }
]

Looking at various other posts I can either:

  1. Run the CURL command in a .rule and store the output into a STRING to be processed by JASONPATH transformation. I have so far:
rule "Solar Test Rule"
when
	Item Solar_test received command ON
then

var String test = executeCommandLine(Duration.ofSeconds(5), "curl","-f","-k","-H","Accept: application/json","-H","Authorization: Bearer eyJra***","-X","-G", "https://192.168.1.***/ivp/meters/readings")
logInfo("Log", test)

end

When I run the .rule by switching the ‘Solar_test’.item to ON (auto OFF after 1 second) I get:

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 183 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (22) The requested URL returned error: 500
  1. Another post looks to use a .thing and batch file. I have tried:
Thing exec:command:solar_readings [command='"G:"\"openHAB"\"conf"\"scripts"\"solar_readings_curl.bat", interval=900, timeout=30, autorun=true']

which has the following in the batch file:

curl -f -k -H "Accept: application/json" -H "Authorization: Bearer eyJra***" -X GET https://192.168.1.***/ivp/meters/readings

and I get:

2023-04-15 08:54:01.975 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'solar_test.things' has errors, therefore ignoring it: [1,44]: Character array is missing "e" notation exponential mark.

I don’t know if the .thing route is the best way to go?

  1. Most people suggest putting the CURL commands in a batch file and running that from within a .rule and running the transformation in the rule. As I’m on Windows, I’m struggling to get the .bat file to output into a temporary variable for openHAB to process.

My .bat files contains:

@echo off

SET Solar_panel_reading=curl -f -k -H "Accept: application/json" -H "Authorization: Bearer eyJra***" -X GET https://192.168.1.***/ivp/meters/readings

echo Solar_panel_reading is: %Solar_panel_reading%

but all that gets printed is the curl request, not the output.

Can anyone please help as to the best direction to take and assist in the correct syntax etc?

Why not using the http binding? :thinking:

To suppress the progress status add the option -s to curl command.

In

Thing exec:command:solar_readings [command='"G:"\"openHAB"\"conf"\"scripts"\"solar_readings_curl.bat", interval=900, timeout=30, autorun=true']

The single quotes are wrong. Should be something like:

Thing exec:command:solar_readings [command="G:\openHAB\conf\scripts\solar_readings_curl.bat", interval=900, timeout=30, autorun=true]

or

Thing exec:command:solar_readings [command="G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat", interval=900, timeout=30, autorun=true]

What if this is executed without elevated privileges ?

That seems to have fixed that error. I’ll try and add an item to get to the data.

I am having issues getting the ‘whitelist’ to work though.

I thought you needed to run command as Admin to get CURL to work, but you dont. It works with a normal command prompt window.

This hasa now just given me:

-

at the log output.

I haven’t looked at the http binding.

Would I just use:

curl -f -k -H "Accept: application/json" -H "Authorization: Bearer eyJra***" -X GET https://192.168.1.***/ivp/meters/readings

as the baseURL?

baseURL is

https://192.168.1.***/ivp/meters/readings

…and your headers go into the, um, headers section.

Here’s an example for a different but related API, with headers:

Those Things also include Channels which grab specific bits of the JSON, such as

stateTransformation = "JSONPATH:$.data.grid.voltage"

What did you try ?
Possible entries:

G:/openHAB/conf/scripts/solar_readings_curl.bat
G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat
solar_readings_curl.bat

I have tried individually:

"G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat"
G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat
G:/openHAB/conf/scripts/solar_readings_curl.bat
'G:\openHAB\conf\scripts\solar_readings_curl.bat'
solar_readings_curl.bat

Nothing worked. Notepad++ shows LF at each end instead of CRLF. I don’t know it that is still an issue?

Does the log file state something about that the updated file was read ?
Does it still show a message about an entry has to be added to the whitelist ?

If I rename to .whitelis and rename back to .whitelist it’ll show:

2023-04-15 16:01:53.277 [WARN ] [c.internal.ExecWhitelistWatchService] - Cannot read whitelist file, exec binding commands won't be processed: G:\openHAB\conf\misc\exec.whitelist
2023-04-15 16:02:01.217 [WARN ] [ng.exec.internal.handler.ExecHandler] - Tried to execute 'G:\openHAB\conf\scripts\solar_readings_curl.bat', but it is not contained in whitelist.

It doesn’t show in the logs ‘loading exec.whitelist’ like it would when adding a .things file.

One of these worked :slight_smile:

"G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat"
"G:\openHAB\conf\scripts\solar_readings_curl.bat"
G:\\openHAB\\conf\\scripts\\solar_readings_curl.bat
G:\openHAB\conf\scripts\solar_readings_curl.bat
'G:\openHAB\conf\scripts\solar_readings_curl.bat'
G:\openHAB\conf\scripts\solar_readings_curl.bat

I am now getting:

Couldn't transform response because transformationService of type 'REGEX' is unavailable

and events.log is showing:

G:\openHAB\userdata>curl -f -k -H "Accept: application/json" -H "Authorization: Bearer eyJra***" -X GET https://192.168.1.***/ivp/meters/readings
'curl' is not recognized as an internal or external command,
operable program or batch file.
'curl' is not recognized as an internal or external command,
operable program or batch file.

Install the REGEX Transformation Service from within openHAB.

Though that might be that issue :wink:

Getting somewhere now. I’ll look at the next stage later in the day.

Thanks all for your help so far.

Any reason you are not using the enphase binding - you can get all this information much easier than using http request locally - i started the same way and realized it is much easier with the binding. The only tricky part is finding the admin password and there is a lot of information int he web on how to reverse engineer the password from the serial number. You can get inverter status/power/everything is there, let me know if you need any help

strong text

If you want to use http request you can use the http binidng with a JSON definition like this

Thing http:url:EnvoyProd "Envoy Production" [
	baseURL="http://192.168.***.22/production.json",
	refresh=30] {
		Channels:
			Type number  : Prod "Production" [ stateTransformation="JSONPATH:$..production[1].wNow" ]
			Type number  : Use "Consumption 0" [ stateTransformation="JSONPATH:$..consumption[0].wNow" ]
			Type number  : Net "Consumption 1" [ stateTransformation="JSONPATH:$..consumption[1].wNow" ]
}

I only use it to tract production because data in binding updates every five minutes but production is close to real time.

1 Like

@LORDUDE
What firmware version do you have on your Envoy? Mine has V7 which has changed from V5 with how you access the local API data. To the best of my knowledge you need to get a token and request the data using CURL commands.

The current version of the Enphase binding doesn’t work with V7. Its being looked at but the fix hasn’t been pushed to the stable build yet.

Web page says → Software Version R5.0.55 (4f2662)

If binding is locked you might be able to use http binding with json definition

You will find that if your Envoy gets updated to V/R7.*** the binding in its current state will fail.

I’m trying to get the http binding to work!