jesserockz / python-juicenet

MIT License
12 stars 10 forks source link

add support for setting max current #11

Open mbbush opened 3 years ago

mbbush commented 3 years ago

Closes #10

mbbush commented 3 years ago

@jesserockz I'd like to be able to use this code from home assistant. Could you merge and publish a new version if this looks good to you? I tested it on my system and it worked fine.

jesserockz commented 3 years ago

Hi @mbbush I didn't even get notified of this. Weird.

But I will take a look this week. Would you implement this on the HA side too?

mbbush commented 3 years ago

I was planning to do the HA side too, although I haven't started yet.

My goal is to get my Sense power monitor to talk to my Juicebox so that my car charges using excess solar power I'd otherwise be feeding back to the grid.

On Sat, Apr 17, 2021, 4:40 PM Jesse Hills @.***> wrote:

Hi @mbbush https://github.com/mbbush I didn't even get notified of this. Weird.

But I will take a look this week. Would you implement this on the HA side too?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jesserockz/python-juicenet/pull/11#issuecomment-821902873, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2UANAFIMBNQXNA4M7KNDTJIL7TANCNFSM42OAL2MA .

jesserockz commented 3 years ago

Just looking through the API doc in the repo, there is a better API call to set the charging limit

image

mbbush commented 3 years ago

I saw that, and it was the first thing I tried. It was super helpful to have the api docs committed to the repo!

When I make that api call, at least on my hardware, I get a successful response, and if I immediately call the get_state endpoint, I see the result of the updated current. But within a few seconds (and before it actually changes the power usage as measured by an external meter), the change gets automatically reverted.

Example (timestamps are approximate): Car is charging at 32A (max for my car). get_state command reports amps_limit = 40 At 12:00:00, issue set_limit command to set current to 15A. Get success response. At 12:00:01, issue get_state command. Reports amps_limit = 15 At 12:00:05, issue get_state command. Reports amps_limit = 40 Looking at actual power consumption (from my Sense energy meter), current never actually changed from 32A.

The best explanation for this that I can think of is that the cloud api accepts the new limit, updates its internal state, then pushes the change to the charger, which rejects the update for some reason, causing the cloud to revert to the previous value. I haven't sniffed the network traffic of the actual juicebox to confirm this, though.

I don't know if this behavior is true of all juicenet chargers, or just mine. (a Juicebox 40 from 2019)

I actually mentioned that this was a weird implementation in a comment on line 98, although that probably could have been more clear.

Using the set_info command to update the amps_wire_limit field seems to match what happens when I make a similar update in the app, in the only way I've found to do this manually using the JuiceNet app. That's also how I found out that it wipes some of the other fields if you don't include them in the set_info command.

jesserockz commented 3 years ago

Ah, I see. I have not actually tried any of the commands in the API, including this as I only have an 8A JuiceCord from 2016, so I cannot limit it any lower without it just turning off. I understand why this would work though because of the wire limit, but strange that the set_limit does not work properly.

I do however know the traffic from the box to the cloud which is a UDP string that I have gone back to every now and then trying to reverse engineer the checksum so that I can get rid of the cloud connection altogether. I also contacted juicenet/enelx to ask for the algorithm but as I expected they said they would not help.

jesserockz commented 3 years ago

I have just been playing around with this now and if I make the set_limit api call, I see the results between the cloud and charger instantly change to show its only allowed to have the specified amperage and it sticks too without reverting.

After setting it to 7 I see this in the response:

'charging': {'amps_limit': 7, 'amps_current': 6.4, 'voltage': 238, ...

Normally mine is set to 10A and charges at 7.4 amps

mbbush commented 3 years ago

Hmm... That's certainly what I'd expect to happen, it's just not what happens on my charger (I double checked last weekend).

I can see several options here:

I'm curious what you'd suggest. It's been a long time since I've set up a MITM for anything, and I think that it's gotten much more difficult to install custom root ssl certs on android since then, so if the app is using https, I may be out of luck. But it is something I've been wanting to play around with more.

I'd also welcome any suggestions for how to approach support on this, because I can easily see a conversation that starts with "when I manually make calls against your private api..." going nowhere.

jesserockz commented 3 years ago

The MITM on Android is how I initially created this library as I did not have the document at the time. I think yes, the android app sets only the wire amp limit using set_info as I have not found a screen that allows you to change it dynamically with the other method and I think that api function is more intended for mass control and/or controlling based on solar output etc like you want.

The MITM for the box to the cloud is easy as its a "simple" string sent via a UDP "connection" (I know UDP doesnt actually make a connection) .

Every second (almost) the cloud sends a string like CMD11032A10M10C217S261!46H$

11032 = 1 (Tuesday) 10:32am (My local time) A10 = Amps the charger is allowed to charge (Becomes 0 based on time of use and the limit settings) M10 = The Max amps the charger is allowed to charge - Always the limit including outside the time of use) C217 and S261 = Random values that I have no clue about and chage to some random number in every message. 46H = Some sort of checksum

Message from box to cloud: ********:v7,s819,u59031,V2406,L9039973,S1,T36,M10,m20,t3,i43,e0,f5004,X0,Y0!1S4:

Expand ```json { "data": { "A": [ 0.1, "amps" ], "E": [ 0.001, "session_energy" ], "L": [ 0.001, "lifetime_energy" ], "M": [ 1, "max_current" ], "S": [ [ "Standby", "Plugged-In", "Charging" ], "status" ], "T": [ 1, "temperature" ], "V": [ 0.1, "voltage" ], "X": [ 1, "X" ], "Y": [ 1, "Y" ], "e": [ 1, "e" ], "f": [ 0.01, "frequency" ], "i": [ 1, "sequence" ], "m": [ 1, "m" ], "s": [ 1, "s" ], "p": [ 1, "p" ], "t": [ 1, "update_interval" ], "u": [ 0.01, "uptime" ], "v": [ 1, "v" ] }, "custom": { "W": [ "data.voltage * data.amps", "watts" ] } } ```
clarity-phev commented 1 year ago

Gentlemen:

It has been a while since you posted this. I have been using this Juicenet API, but recently Enel-X has decided to abandon home.juice.net portal, and hence the account there and functionality of this API has ceased. This is very disappointing. They now only offer a new App 'JuicePass' (which sucks in my opinion). They have no plans to provide a new web interface, no plans for an API, and the new App lacks much of the telemetry that was previously available.

Because of all this, I have spent some time looking at the UDP packets (which seem to be sent like a heartbeat every 10 seconds from the Juicebox to the Mothership). They are 349 bytes long, and seem to be plain text, but I do NOT see the key telemetry within these messages (like Line Voltage, Current, Temperature, Power, and the like).

I just found your comments above about "Message from Box to Cloud". This is exactly what I am looking for... Can you elaborate on how / where you see the messages that you show above, as you identified here: "Message from box to cloud: **:v7,s819,u59031,V2406,L9039973,S1,T36,M10,m20,t3,i43,e0,f5004,X0,Y0!1S4:"**

Are you aware of this transition to a 'new' system on the part of Enel-X?

mbbush commented 1 year ago

I've seen the new app advertised, and I agree with you. It's a step backwards for users of their home charging products.

My home assistant integration and my "old" EV JuiceNet android app continue to work, at least so far, approximately as well as they always have, although with intermittent inexplicable failures or nonsensical behavior.

Getting a local API would be great. Based on the text based UDP comms, I think the first step would be getting a read only API that relies on MITMing the device. Then we could set up logging and get enough packets to hopefully reverse engineer the protocol and be able to send packets too.

If successful, we'd probably need to block most or all cloud traffic, which would disable some of the "smart grid" type features like demand response and charging on low carbon electricity. This has some significant downsides, at least for me, as I use and enjoy those features.

In theory, this would be possible, but I've never successfully done something like this before. I'm also likely to be getting a different EVSE soon, so my personal benefit from this project would be low.

clarity-phev commented 1 year ago

Did you receive an email from Enel-X announcing this transition to the 'new' App?

I got the email, but didn't realize it because it went to my Spam folder. They moved me to the new 'system' without giving me any notice. The old juicenet just stopped working for no apparent reason, and I had to call them to decipher what happened.

For reference, here is a copy of the email that was sent:


Hi Tom,

To provide you with the best user experience and new functionalities, we are transitioning to a new and improved platform for charging management. Your charging station will be migrated to the new JuicePass app (Enel X Way app). The EV JuiceNet app along with web browser access to your charger via home.juice.net will no longer be supported after February 20, 2023. Configurability and control of your chargers must be done via the new JuicePass app (Enel X Way app) which can be downloaded on iOS https://cbwlm04.na1.hubspotlinks.com/Ctc/W0+113/cBwLm04/VWWYrb6Jq2JfV3bRxq8jkdxPV1-ywc4V_JWmN8DGmDG3q90pV1-WJV7CgQrZW5Rs3mW2G-lZ_W34vLg97lPwGLVdSCB63KfbwwN8XNyVsmSLb4W7pdYBq5JQ0FrN1tnxQdl7VZ0W5qH1rT5HBv93W4ystLW65DD4MW13tKwg2YRRSbW2nWrpT8lWvf8W16h-BT4x7RG-W5jNd1M2kmh8pVMHhPQ18gTkDVvTYTq1Y3DtjW9b6sYg3WmvKFW14zyBP7MLTVdVz8FkX1SDW-jN4Dsd277DyyhW2BptsT89hWMxW3y77FQ4kCx5dW4__1hM2Nyw0tW79DTmq3jy2ZPVlhVV61s6RLSW5FWQKv5lb-4DW7cPX7d1wWzRxW3rD-fy6CTN-Q3b5B1 or Android https://cbwlm04.na1.hubspotlinks.com/Ctc/W0+113/cBwLm04/VWWYrb6Jq2JfV3bRxq8jkdxPV1-ywc4V_JWmN8DGmFf3q90_V1-WJV7CgzGZMtwFRVm1GPDW1WjfvV4q5g4NV8PP_Y4H4_fwW6hHWrF6RXwtBW3Ntbb97Lz48nN9d6YyXQWhRCW7F0WzC2BbZ91W1FQkW-6Q68T6W4WXKTZ2MNK-2W2lkbdY51ylpSV5dVKq4flt8kW2QWzW-4tKPgRW7_ML9q2L6gNRW1PM5B72bFJLmN8J5Wl4btP6hVC-5rZ1pkpmxW1-0Mc74JBfGhW7H3W_Z8X_W7mW4cW2KY7jHMDjW4bCjdn5wwH5jVGrKvs1-9C6CW3qz8Zd2shNN5W8lbV7v1HBkMtW9bjg571-HtKDW3_dM1C2hJJGnW7yfCKn6z_NGPW2rK-jj5NmmRQW6bbJHZ6S-4qQW46z2nn1k1qHzW7S_07n8g-4dm3px81 .

The app will allow you to manage your JuiceBox charging station at home, find public chargers on the go, or charge at work if you have access to Enel X Way commercial charging stations.

In order to provide a seamless transition and to ensure that your charging station along with its history is migrated, please use the same email and credentials you used previously. Your JuiceBox should automatically link to your Enel X Way account, so your charging station(s) will be visible immediately. If you do not see your JuiceBox in the app, please try the following:

  1. Go to the home charging tab

[image: JuicePass1-1]

  1. Click on "Start Configuration" [image: JuicePass2-1]
  2. Input your personal data when prompted [image: JuicePass3]
  3. When prompted to scan your JuiceBox, skip this step and exit set-up [image: JuicePass4]

You will be able to see your JuiceBox populated in your account after the steps above. Should you still have issues, please visit our support hub https://cbwlm04.na1.hubspotlinks.com/Ctc/W0+113/cBwLm04/VWWYrb6Jq2JfV3bRxq8jkdxPV1-ywc4V_JWmN8DGmDG3q90pV1-WJV7CgFd5W3wtZ-n8PDQS7W8r_Ds01LjF7CW6K76jH3r5F0WW6FjD3v4HZNVWW2Cj7pS7GNlMCW1sBkNW1-0GyhW4Y6GpS58G_QNW5YpW4j4-04shVBvM5b8kwNgpW1jdTtx8gHbmZW6cQ5Yn9dZYH2W5_PJgZ6VNYq1W40N26s5yym0mN1YD3w94q_2kN3StRDRWZGvVW5gSXky19yXH1W3wDzCt8Wg6CmW8R0DNC1x_PVKW8ldRGL3BnRczW64mJg089YZMKW28zbsM6Jxd_-N6rXWstLsTk9W4g1PVj1SlbNcW73n5Yd7793vkW8Yn6M31CFNlkW4vMT_s7P6_Pz3k-r1, contact our support line at +1 (844) JUICEBX or chat with us https://cbwlm04.na1.hubspotlinks.com/Ctc/W0+113/cBwLm04/VWWYrb6Jq2JfV3bRxq8jkdxPV1-ywc4V_JWmN8DGmC95nKv5V3Zsc37CgWt4W83CN4K7bsg87W8m2P7j67-90WW2rhMss1WD9ZhW2w4qhk4YH6bzW7BW2TG1vQMzpW5-gFrW3FqZ0WN34Ngx95cRHzW3VkvC196mkZ0W3ZDN756GkVFKW8kz6_T1c5DJpN5YWWLp_QMHrN11HRtHTDrnFW87mlGm5gzHL2W1w9T4x3zBBvhW43rBtq5_lTQ9W6VSP053wHyB6N8V3n_Vt4xX6W861F1D3qnz0VW2tNd4G5yNZylN3k64LY_y27YW2YQxmC1spqK4W7wQdV4606FZ2W4CcqcW9dGxHtW5LMrP857mT2pW8Vq6b587gNqyW5Qr3T561VDfvW1wM59H5cLzN-W7K-hhB76lrxtN3j74LlM7_LvW4KR4rM3VZpFTW74xLsP1VCW0zW5fM4Wq82S33V316c1 for further assistance. Responses to this email address are not monitored.

Thank you,

The Enel X Way Team [image: Enel X Way Logo-1]

Enel X Way USA, LLC

360 Industrial Road, San Carlos, CA, 94070 https://www.google.com/maps/search/360+Industrial+Road,+San+Carlos,+CA,+94070+%E2%80%93+USA?entry=gmail&source=ghttps://www.google.com/maps/search/360+Industrial+Road,+San+Carlos,+CA,+94070+%E2%80%93+USA?entry=gmail&source=g USA https://www.google.com/maps/search/360+Industrial+Road,+San+Carlos,+CA,+94070+%E2%80%93+USA?entry=gmail&source=g

https://evcharging.enelx.com https://cbwlm04.na1.hubspotlinks.com/Ctc/W0+113/cBwLm04/VWWYrb6Jq2JfV3bRxq8jkdxPV1-ywc4V_JWmN8DGmDm3q905V1-WJV7CgHGdN9lTRRRXzbnHW4y5-4q47NnM-W4vryRx5npjsCW4Q73SH5lc7J4W3tBFDT8K6Fd1MWk6DN5yWlkW8Dg4S96y8F0fVTNzZk3Xf2HtW2p-rVb3zGqz_W7HVGb274JY6YW1njrP91GdSLwW1P_gT52cQWvTW2zmTq892S4LLW6jHm2J96KRZ1VMKByx4fY7D8W7jS7vy5CFlw1W5bdg9-1wNdlpW8yq1fM61tZkZW7v-h5N7lSc04W6mmtKP8sg7gFW4g9Zc57pZ8NFN49-pdTBfG2JW4PYhTW5zF-JlW8G446N5M8fmg3b2r1

mbbush commented 1 year ago

I got that email on January 17, announcing the same Feb 20 cutover date.

tomayac commented 1 year ago

I started a reverse-engineering effort of the new Enel X Way API and have put my findings in a public Gist. Help is very much welcome! So far I have the endpoints, but need to understand authentication, potentially request signing, etc.

clarity-phev commented 1 year ago

Hello - If I am understanding you correctly, the API that you seek is already documented here: https://github.com/jesserockz/python-juicenet

Look at the file - JuiceNet API_client_12_11_2017.docx

Enel X is dropping this however, and they have a new JuicePass App with no plans to support any kind of API going forward. If you get 'migrated' to the new servers you will lose access to this API.

Am I misunderstanding your objectives?

tomayac commented 1 year ago

My reverse-engineering attempt already looks at said new API. The old API's origin is https://jbv1-api.emotorwerks.com, whereas the new Enel X Way API's origin is https://emobility.enelx.com.

clarity-phev commented 1 year ago

Got it.... I think you are on the right track, but may be an uphill battle As you say, authentication, etc. may make this virtually impossible without cooperation from Enel X...

mbbush commented 1 year ago

I'm still running just fine on the old version of the API. The only reason I can think of why they might not have migrated me is that I have a second charger on my account, which is a clipper creek model, and has an extremely intermittent internet connection.

I don't know which of those factors (more than one charger, third-party charger, device that won't update to latest firmware) is causing them to leave me on the old servers, but I'm still happily using this integration with no changes.

clarity-phev commented 1 year ago

just for reference, I struggled along with bugs for a couple of months in the new JuicePass application. Eventually EnelX tech support un-migrated me, and I am happily back to the original application and servers. It is unclear if / when they will eliminate the old setup but if you are unhappy with the new stuff, they will put you back upon request.