dgthomson / nodered-shellrecharge

A subflow for Nodered to control Shell Recharge car charging equipment.
GNU General Public License v3.0
20 stars 7 forks source link

Feature Request: KwH meter #17

Closed hjnijlunsing closed 12 months ago

hjnijlunsing commented 1 year ago

Thank for you this interesting integration!

I was wondering if it would be possible to add a function to retrieve the total number of KwH delivered for a set charging point. This way it could be used in HomeAssistant as a meter sensor to calculate KwH per day / week / month and added to the energy dashboard.

In the Shell Interface you have the ability to set a custom filter, and doesn't seem to come with any limitations; Thus if you set the start date to the date where the charging point is installed and the end-date to today you would get an absolute measurement.

With Chrome Dev-Tools network; it seems to already return the information in JSON ready format like this:

https://account.shellrecharge.com/user/{USERID}/dashboard/chargevisual.json?pointId=&chargeCardRfid=&type=point&from=1533420000000&to=1693691999999&_=1693732790492

Response: { "chartTotal": { "totalkWh": "79,290", "totalkgCO2": "66,009", "totalTime": 34314, "totalSessions": 2 }, ... }

dgthomson commented 1 year ago

A chunk of this work has been done already, but I pulled it as it was very unreliable. Unfortutatley I don't have much time at the moment to play with it but watch this space.

dgthomson commented 1 year ago

@hjnijlunsing I have uploaded a version for you to the repository. The instructions for energy consumption data retrieval are embedded inside the flow's help.

hjnijlunsing commented 12 months ago

Hi DgThomson,

Initial testing looks great! First I got an error: "HTTP Error [ETIMEDOUT:energy]" But second time injecting with the same payload I received the chart data back!

chartTotal: object totalkWh: "149,780" totalkgCO2: "124,692" totalTime: 106121 totalSessions: 5

I will continue to test and check the integration with HA.

Many thanks!

hjnijlunsing commented 12 months ago

Quick check: It seems the output is only coming from the "Debug" output, but not from the "Output" output. Is this the expected behaviour?

The above had puzzled me for a bit as I was trying to get everything from Output ;-)

I am able to inject the current "now" timestamp, with a fixed start timestamp (time when I got my charger) into the payload and post it to the MQTT broker.

Now the last step is getting MQTT back into Homeassistant and make the graphs but that should not be too difficult.

dgthomson commented 12 months ago

yeah, that was intentional. 'Output' was always meant to give a charging signal and nothing else.

Watch the output it does give, though... the kWh values are strings, potentially with commas and other formatting, so it needs some processing before going into a HA sensor node. This jssonata works.

$number($replace($.payload.chartTotal.totalkWh,/[^\d.-]/, "$1"))

hjnijlunsing commented 12 months ago

Thanks for the tip! Feature request for future it would be great if we perhaps van have a third output for the wh :) Since the debug also contains messages like: "false", "expired api token", "login...", "true", "got token :)"

Anyway I have it working now;

I will add a second inject node for the "Charging", "Available" to retrieve the status.

Excellent work and thanks again for your help in making this possible!

dgthomson commented 12 months ago

no problem. you should use a switch node wired to the debug output to filter on msg.topic to pull out the type of information you need. anything regarding energy has msg.topic = "energy" 😉

also, you could avoid all the MQTT work by using https://github.com/zachowj/node-red-contrib-home-assistant-websocket.

hjnijlunsing commented 11 months ago

Ok, so the above worked for about a week then I had to reset my password. I was request the status every 15 minutes and the used KwH every hour.

Do you have any similar experience? ;-) (Probably they are not very keen for API usage)

dgthomson commented 11 months ago

it has been working ok. I get energy statistics after the car finishes charging overnight. there was a password issue one night so a charge was missed, but shell had announced that they were going some login work and I was expecting things to break in a more spectacular way.