Nissan Leaf Component(s)/Platform

There must be another way

@BenWoodford the request lib you are talking about, is that pycarwings?

In that case we could try lowering that in the manifest file and put that in custom_components.

{
“domain”: “nissan_leaf”,
“name”: “Nissan Leaf”,
“documentation”: “https://www.home-assistant.io/integrations/nissan_leaf”,
“requirements”: [“pycarwings2==2.9”],
“codeowners”: ["@filcole"]
}

Any luck with 2020.12.0?

Let me know when you have something to share! Looks interesting and happy to try out!

Try this: https://github.com/Troon/leaf2mqtt

1 Like

Tried this and I like the idea, platform independence is good.

But I didn’t manage to do the build, I got some error messages related to signatures:

W: GPG error: Index of /ubuntu-ports groovy InRelease: At least one invalid signature was encountered.
E: The repository ‘Index of /ubuntu-ports groovy InRelease’ is not signed.
W: GPG error: Index of /ubuntu-ports groovy-updates InRelease: At least one invalid signature was encountered.
E: The repository ‘Index of /ubuntu-ports groovy-updates InRelease’ is not signed.
W: GPG error: Index of /ubuntu-ports groovy-backports InRelease: At least one invalid signature was encountered.
E: The repository ‘Index of /ubuntu-ports groovy-backports InRelease’ is not signed.
W: GPG error: Index of /ubuntu-ports groovy-security InRelease: At least one invalid signature was encountered.
E: The repository ‘Index of /ubuntu-ports groovy-security InRelease’ is not signed.

Can’t say that I’m an experiences docker user, but I’ve manage to get some containers up and running earlier.

Is this on a Pi? Perhaps look here or here? A number of similar issues seem to be caused by running out of space on a filesystem: the image is, sadly, a monster at over 700MB on my NAS. Luckily, I don’t have to care about that.

Alternatively, perhaps edit the Dockerfile to specify an older Ubuntu base, as it’s not critical.

Yeah, I came to that conclusion myself and I found the way forward, next challenge is to install dart on the pi and there I ran out of time. Let’s see when I get some more time to play around with this.

But one question, when I took a look at the files, it seems that it is only sensor? Is that correct? I.e no possiblities to start the heater/AC?

Yes, only sensor at the moment. The library has the potential to do everything the MyLeaf app can, but I haven’t exploited those at this point. UPDATE: climate now done.

any word on this, or on making it work through custom components?

As a beginner eagerly updating to the latest home assistant, I experience all too often that something breaks. One way to solve such problem is to create an additional home assistant in a docker container and share what ever sensor/switch that stoped working to your latest home assistant 2020.x.x.
This is built into home assistant, you only need to add Remote Home-Assistant integration to your primary hass.

So for example on my Raspberry Pi2 with raspian buster I install docker:
curl -fsSL http://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

And then I install whatever Home assistant version I want with:
sudo docker run --init -d --name="home-assistant-0117" -e "TZ=Europe/Oslo" -v /home/pi/homeassistant/0.117.6:/config --net=host homeassistant/raspberrypi3-homeassistant:0.117.6

To manage docker images I found this guide
Portainer.

The commands I used on my rpi2 was:
sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 \
--name portainer \
--restart always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v portainer_data:/data portainer/portainer

Then access it via http://ip.address:9000

Be aware that the leaf climate switch has a status delay when it connects to your car. This can create a on/off loop.

I’ll just manually edit the container after each update until the fix is pulled into HA build.

More info here:

Not sure how to do it through HA OS. I run it supervised, so I use “docker exec -it” command from host OS to go into the container and vi edit the file manually.

I’ve just submitted a pull request https://github.com/home-assistant/core/pull/44634, so hopefully the current breakage will be resolved in the next release of Home Assistant

2 Likes

Welcome back @filcole, we’ve been looking for you :wink:

1 Like

The pull request was included in 2020.12.2 released earlier today :+1:
Can confirm that it is working now! Thank you!

1 Like

This version actually introduced another issue for me where the switch to activate climate control is not working.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/switch.py", line 53, in async_turn_on
    if await self.car.async_set_climate(True):
  File "/usr/src/homeassistant/homeassistant/components/nissan_leaf/__init__.py", line 425, in async_set_climate
    climate_result = await self.hass.async_add_executor_job(
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py", line 263, in get_start_climate_control_result
    response = self.session._request_with_retry("ACRemoteResult.php", {
  File "/usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py", line 103, in _request_with_retry
    ret = self._request(endpoint, params)
  File "/usr/local/lib/python3.8/site-packages/pycarwings2/pycarwings2.py", line 169, in _request
    raise CarwingsError
pycarwings2.pycarwings2.CarwingsError

Anybody else experiencing this?
I’ll submit an issue on GitHub when I get the time later today.

Edit: After getting into my car it turns out the switch DID work, but I never got the status to Home Assistant.

I have 2020.12.7 and it’s not working here :frowning:

Anyone else?

OK, I’ve taken a better look at this and I’m running 2021.1.2 and the Supervisor version is 2020.12.7.

The component should be working but it’s not :frowning:

I have logging set, but it’s showing no info!

</s> <s>logger:</s> <s> default: critical</s> <s> logs:</s> <s> homeassistant.components.nissan_leaf: debug</s> <s> homeassistant.components.sensor.nissan_leaf: debug</s> <s> homeassistant.components.switch.nissan_leaf: debug</s> <s>
and here is my log, for what it’s worth.

</s> <s>2021-01-10 13:59:17 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for nissan_leaf which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.</s> <s>2021-01-10 13:59:17 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for auto_backup which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.</s> <s>2021-01-10 13:59:18 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant.</s> <s>

I had a custom_component installed :crazy_face:

Logger: homeassistant.components.nissan_leaf
Source: components/nissan_leaf/__init__.py:158 
Integration: Nissan Leaf ([documentation](https://www.home-assistant.io/integrations/nissan_leaf), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+nissan_leaf%22)) 
First occurred: 21:10:14 (1 occurrences) 
Last logged: 21:10:14

An unknown error occurred while connecting to Nissan: <class 'pycarwings2.pycarwings2.CarwingsError'>

I got an error while setting up my Nissan Leaf integration in HA. I’m totally new to HA so I don’t really know if it is my fault or something is wrong with the component. I’m running at HA version 2021.1.1

Sometimes happen. Most of the time just restarting HA and the error goes away.

By(t)e

Do you have any tips for debugging whats happening inside the docker container. This is my first time building and running a docker image and although it says it’s up nothing seems to be happening.

These are the commands I’ve used:

sudo docker build --no-cache --tag leaf2mqtt .

sudo docker create --env MQTTTOPIC=leaf --env MQTTHOST=<IP ADDRESS OF MQTT> --env USERNAME=<EMAIL> --env PASSWORD=<PASSWORD> leaf2mqtt

sudo docker start <NAMES>