fsaris / home-assistant-zonneplan-one

Unofficial Zonneplan integration for Home Assistant
https://github.com/fsaris/home-assistant-zonneplan-one
MIT License
104 stars 17 forks source link

Way to update Zonneplan value to start charging #75

Closed Arnoudd closed 9 months ago

Arnoudd commented 12 months ago

Not really an issue but more a feature request for the laadpaal. :)

I've been trying to create an automation that starts charging when the car is plugged in, and current_tariff prices are low. The easiest way to do this would be to update the binary sensor "binary_sensor.charge_point_plug_and_charge" to "on". If this would be possible it would start to charge.

Obviously if I change the binary sensor it doesn't really change the Zonneplan registered value. So I would need to make an api call to really update that value at Zonneplan. Would something like this be possible?

rutgersmit commented 10 months ago

That would be great (came here to find out if it's possible while creating the same type of automation). I'm afraid the current implementation is a read-only one.

rutgersmit commented 10 months ago

Ok, ik heb de call naar de API gevonden. Ga deze hier echter niet delen zonder overleg met @fsaris

Arnoudd commented 10 months ago

Goed bezig. Zou mooi zijn als die api call ingebouwd zou kunnen worden. Dan kunnen we 's avonds inpluggen en automatisch laden in de goedkoopste uurtjes. Ideaal.

holobeer commented 10 months ago

I tried running your latest commit (Initiate buttons} The Zonneplan app is configured to only start charging using the app or a schedule (so not when connecting the cable) image

The start and stop buttons appear after reloading HA. After manually enabling them i can press the start button: image

The Zonneplan app shows the charging is starting.

2023-11-08 22:07:15.014 INFO (MainThread) [custom_components.zonneplan_one.api] POST: /charge-points/0e5eda79-3006-4f74-bf80-582ec82e2bc6/actions/start_boost 2023-11-08 22:07:15.286 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response header: <CIMultiDictProxy('Server': 'nginx', 'Date': 'Wed, 08 Nov 2023 21:07:15 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, private', 'x-ratelimit-limit': '120', 'x-ratelimit-remaining': '105', 'Strict-Transport-Security': 'max-age=63072000')> 2023-11-08 22:07:15.286 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response status: 200 2023-11-08 22:07:15.286 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response body: {} The charging works (confirmed by checking my energy usage and car app) But after about 10 seconds it stops charging again.

@fsaris if you need further testing the start/stop charging button I will be happy to help.

Arnoudd commented 10 months ago

This looks promising. So the update sets a "start charge" value?

Did it also add a stop charge value? If not that could be the problem?

rutgersmit commented 10 months ago

Can not replicate the issue @holobeer mentions. My car (Tesla) keeps charging after being started from HA. Would be very interesting to find out who stops the charging. Can be stopped on the car side and on the charger side.

No stop charging calls in the log I assume? And when you hit the start charging button in the Zonneplan app the charging continues after 10 seconds?

Arnoudd commented 10 months ago

I just installed the version too. I will check if it works in the evening.

I do get an error pressing the start charge button but it could be caused by the simple fact that there's no car plugged in. Maybe there needs to be some error handling in place for this situation. [...] 400, message='Bad Request', url=URL('https://app-api.zonneplan.nl/connections/.../actions/start_boost')

edit: Just checked with the car plugged in. I'm not getting an error, but my car isn't charging either.

edit2: The log: 2023-11-09 16:17:17.159 INFO (MainThread) [custom_components.zonneplan_one.api] POST: /charge-points/.../actions/start_boost 2023-11-09 16:17:17.432 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response header: <CIMultiDictProxy('Server': 'nginx', 'Date': 'Thu, 09 Nov 2023 15:17:17 GMT', 'Content-Type': 'application/json', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache, private', 'x-ratelimit-limit': '120', 'x-ratelimit-remaining': '119', 'Strict-Transport-Security': 'max-age=63072000')> 2023-11-09 16:17:17.432 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response status: 200 2023-11-09 16:17:17.432 DEBUG (MainThread) [custom_components.zonneplan_one.api] ZonneplanAPI response body: {}

Looks kinda simular to @holobeer 's log. But my car doesn't start charging at all.

edit3: And after a reboot of the charger it suddenly does respond to the start charge triggers. It seems to be working. :)

holobeer commented 10 months ago

I have tested the button again today and now it keeps charging. Not sure what changed, Will keep testing.

fsaris commented 9 months ago

Okay, about current status.

After some investigation done by @rutgersmit we know now what calls to make to start/stop charging.

With that info I added the 2 buttons for now. And seems that works so next step is to make it a little more error prone. You should only be able to start charging when connected and stop charging when it's currently in charging state.

Current idea is to change the 2 buttons into 1 switch

Arnoudd commented 9 months ago

Okay, about current status.

After some investigation done by @rutgersmit we know now what calls to make to start/stop charging.

With that info I added the 2 buttons for now. And seems that works so next step is to make it a little more error prone. You should only be able to start charging when connected and stop charging when it's currently in charging state.

Current idea is to change the 2 buttons into 1 switch

Sounds good! It's working great in a automation I made.

Only weird thing that I had was when I pressed the start charge button a couple of times, while the car was unplugged. After that I actually had to reboot the charger because it was acting weird. So the extra check of a plugged car before sending the start trigger is probably a good idea.

Thanks for your work!

holobeer commented 9 months ago

I use the charge buttons in combination with the ev smart charging addon over the past week and it has been working great. No problems at this moment.

fsaris commented 9 months ago

@Arnoudd @holobeer could you check current version and check if the status check to enable/disable the buttons work?

Arnoudd commented 9 months ago

@Arnoudd @holobeer could you check current version and check if the status check to enable/disable the buttons work?

I'm getting this error: Logger: homeassistant.setup Source: setup.py:359 First occurred: 18:24:55 (1 occurrences) Last logged: 18:24:55

Unable to prepare setup for platform zonneplan_one.button: Platform not found (cannot import name 'BUTTON_TYPES' from 'custom_components.zonneplan_one.const' (/config/custom_components/zonneplan_one/const.py)).

If I take an older version of the const.py the error is gone. Will check nore later this evening.

fsaris commented 9 months ago

@Arnoudd are you sure you used the latest version of branch charge-start-stop?

Arnoudd commented 9 months ago

@Arnoudd are you sure you used the latest version of branch charge-start-stop?

No. I'm not sure. I made an error with selecting some versions. I just checked all my versions again and it looks better. Will check some more later this evening.

fsaris commented 9 months ago

I created a beta release that can be install using HACS, use version 0.0.21b1

See https://github.com/fsaris/home-assistant-zonneplan-one/tree/0.0.21b1#installing-mainbeta-version-using-hacs for info about installing a beta

Arnoudd commented 9 months ago

I created a beta release that can be install using HACS, use version 0.0.21b1

See https://github.com/fsaris/home-assistant-zonneplan-one/tree/0.0.21b1#installing-mainbeta-version-using-hacs for info about installing a beta

Thanks, that makes it a lot easier. 😬

Just verified that both buttons are disabled when there's no car plugged in. When I plug in the car the start charge becomes available.

I can't test the stop button since it's already fully charged.

Arnoudd commented 9 months ago

Just checked the stop button and it's working too. It's disabled when it's not charging and it works when the car is charging. 👍

fsaris commented 9 months ago

Please test 0.0.21b2

See https://github.com/fsaris/home-assistant-zonneplan-one/tree/0.0.21b1#installing-mainbeta-version-using-hacs for info about installing a beta

Arnoudd commented 9 months ago

Just installed it. Will do some testing and report back.

rutgersmit commented 9 months ago

Shouldn't the start charging button be disabled if no car is detected?

fsaris commented 9 months ago

@rutgersmit that is currently the case isn't?

Else could you share a dumb of the logging so we can check what values to check?

Arnoudd commented 9 months ago

Same here. It was disabled this morning when it was charging. But when I unplugged the car it enabled itself again.

What variables are you using to check if a car is plugged in?

rutgersmit commented 9 months ago

AFAIK checking if a car is detected to enable the button was not implemented yet. The API returns a boolean whether a car is detected or not. So not something new since the last update.

Arnoudd commented 9 months ago

AFAIK checking if a car is detected to enable the button was not implemented yet. The API returns a boolean whether a car is detected or not. So not something new since the last update.

I have seen it disabled earlier when there was no car plugged in. But it looks like it's not always working like that.

fsaris commented 9 months ago

@rutgersmit @Arnoudd can you provide the api response? Or are you talking about 1 of the existing sensors?

Arnoudd commented 9 months ago

@rutgersmit @Arnoudd can you provide the api response? Or are you talking about 1 of the existing sensors?

I'm guessing @rutgersmit is talking about the "sensor.charge_point_state" sensor? "Standby" means there's no car plugged in where "VehicleDetected" and "Charging" means there is a car plugged in.

image

I do believe I've also seen an error state. In short the only time the Start_charge button should be enabled is when the state of the "sensor.charge_point_state" sensor is "VehicleDetected".

rutgersmit commented 9 months ago

@fsaris the response from https://app-api.zonneplan.nl/connections/GUID/charge-points/GUID has the property 'state'. My car is not connected and shows the state Standby. When a car is connected the state is VehicleDetected. When the car is charging the state is Charging

Don't know if there are any other states.

{
  "data": {
    "contracts": [
      {
        "uuid": "GUID",
        "label": "Charge laadpaal",
        "type": "charge_point_installation",
        "start_date": "2023-10-08T22:00:00.000000Z",
        "end_date": null,
        "meta": {
          "serial_number": "TACW11123456",
          "identifier": "TACW11411223456",
          "show_in_contract_screen": true
        },
        "state": {
          "connectivity_state": true,
          "state": "Standby",
          "power_actual": 0,
          "energy_delivered_session": 0,
          "can_charge": true,
          "can_schedule": true,
          "charging_manually": false,
          "charging_automatically": false,
          "plug_and_charge": false,
          "overload_protection_active": false,
          "dynamic_load_balancing_health": "HEALTHY"
        },
        "charge_schedules": []
      }
    ]
  }
}
rdgout commented 9 months ago

These are the possible states right now:

Starting should only work when VehicleDetected and stopping should only be possible when Charging In any of the other states the request you should not assume the charger to do anything when sending requests.

fsaris commented 9 months ago

Released https://github.com/fsaris/home-assistant-zonneplan-one/discussions/86