My Mitsubishi PHEV integration, via MQTT

Hi,

I wrote a small utility for communicating natively with my (MY18) Outlander PHEV via the Remote Control Wifi interface and integrating it into HA via MQTT and auto-discovery. This can be run on a Pi using its Wifi to talk to the car and ethernet to the MQTT broker.

With this, I can do the following:

  • Fetch battery level, charge status, charge cable status.
  • Trigger charging (via ‘cancel charge timer’ function)
  • Query and trigger parking/headlights
  • Query and trigger climate
  • Query door and lock status

It’s inspired by the Phev Remote work, but written from scratch and includes more functionality and responsiveness.

It’s very usable and responsive as is (~0.5s to change lights) but would love to get more contributions for decoding further features as well as verifying on other model year cars.

Setup docs are included - I also include a bunch of information on the proprietary car protocol.

11 Likes

This looks excellent and the timing is ideal, I’ll have more of a look when my PHEV arrives next weekend :smiley:

Awesome, be great to see if it works, especially if it’s a different model year.

Thank you… I thought this would have been impossible as the Outlander is the AP. Very excited to try this!

Yes as it’s the AP you need something like a Pi with both Wifi and Ethernet so that the Pi can connect to the car’s AP and talk to it, as well as reach the MQTT server over the ethernet.

Well, after some fun and games getting my raspberry pi connected to the WiFi (obviously nothing to do with your software, I’m pleased to say getting this up and running was very simple. Haven’t done a great deal more than just connect it up and can see all the MQTT messages flowing out. Amazing job. I’m afraid mine’s the same model as yours though. I’ll have more of a poke about now :smiley:

1 Like

Well Done ! :drooling_face:
I’m not so lucky as you with my Outlander PHEV 2015.

Everything’s ok until the last command ( ./phev2mqtt client mqtt --mqtt_server tcp://<your_mqtt_address:1883/ [--mqtt_username <mqtt_username>] [--mqtt_password <mqtt_password>] ) give me this :

timed out waiting for start
dial tcp 192.168.8.46:8080: connect: connection refused

So sad… I was so excited to make it work.

Perhaps try a few troubleshooting steps first before giving up:

  • Make sure the official app does work with the car, it may have not registered properly.

  • Do you see the Pi associated with the PHEV? Run iwconfig wlan0 to check.

  • Is the PI MAC address the same as the device you registered using the official app? Run ifconfig wlan0 to check, it’s the line with ‘ether’.

  • Can you ping the PHEV? ping 192.168.8.46

  • Is the official app still connected/running? The car might only allow one connection.

If none of these show the problem, perhaps that year’s model uses a different port? You could try scanning the car apt install nmap ; nmap 192.168.8.46 or even sniff the app as described at the bottom of the repo’s README.

Good luck!

1 Like

@buxtronix - I’ve created (quite a noddy) local addon for the phev2mqtt client side of things, I’ve been trying to also get the wlan changes working too but that’s a bit harder due to permissions in the docker container. But it seems to work reasonably well, lets you set some parameters and keeps it running. Is that worth adding to the same repo for people to use/improve or should I do that separately?

FYI - might also be worth mentioning needing to add the button-card component to add the lovelace.yaml to the dashboard.

@martin_john sounds great, I’m definitely happy to integrate any PRs to improve this! Especially a Dockerfile to take care of the build and run.

Just tried this, seems to work fine. I’ll do more testing later this week, since some of my issues might be because how I started and what was the initial state of PHEV.

Because of this, all the things I noticed should be taken with a pinch of salt :).

  1. responsiviness seems great! However, lovelace toggles for lights seem to lag (ie. they change back to previous state, and only after a while to reflect real state, logs seem to indicate also reconnect).
  2. with fully charged i get battery state 94.
  3. cable is shown to be unplugged, even though it is plugged. (However, car was already fully charged whe n I first run phev2mqtt, this may be the cause?)

( 4) is there ”recipe” for the lovelace setup shown in the first message somewhere? :wink: ) EDIT: just noticed the included lovelace.yaml :wink:

My phev is MY19 model, I think the only difference to MY18 might be the battery size?

All in all, just beautiful work!

After few hours, even though phev2mqtt was still running in my raspi I got error’s setting register xx when trying to change anything. Manually restarting phev2mqtt helped.

Haven’t yet physically unplugged the charging cable or anything like that, but noticed that when setting climate mode to cool (which worked, but slightly with the same lagging effect like with lights) following happened as well:

  • battery level dropped from 94 to 5 immediately
  • charge time raised from 0 to 1200 and charging from ‘not charging’ to ‘charging’ and charger connected from ‘unplugged’ to ‘plugged’ a bit later

Disabling phev cool retuned those values back in reverse order.

1 Like

Thanks for the feedback, yes some of these issues are known:

  1. Setting the registers is a bit hit and miss

The algorithm used to choose the xor encryption key is something I haven’t been able to figure out yet. So I set to an arbitrary value, and the car response with the expected value, so I re-send with that value and it usually works. However the code can then go out of sync again and will re-connect to sync up.
I would love for someone with more expertise to try and crack this one.

  1. Fully charged at 94%.

This is correct, but perhaps I can just offset the value to make 94% = 100%, but I need to figure out any possible problems with this.

  1. Charge value sometimes jumping to 5% then back.

This is just what the car sometimes sends. Even the official app glitches like this and shows low charge value briefly. Maybe some smoothing algorithm could help?

  1. Setting climate mode makes other values glitch.

This would be a side effect of (1). When setting the register, the data sometimes goes out of sync and the code will reconnect to the car, sometimes the car will then send those glitched values.

  1. On ‘error setting register’ it should eventually reconnect with the car and sync back up. It generally doesnt remain in an errored state.

I have also just yesterday merged a feature to attempt wifi restart if there are too many connection failures (bearing in mind that this will be triggered a lot if the car is not nearby).

Thanks! I can live with those, now that I know it is just not me :).

  1. intresting: I assume phev-remote suffers from this same problem?
  2. I agree, battery level is better to be smoothed on UI level with filter sensor or similar. No need to offset it on sensor-level
  3. and 4. maybe fiddling with some higher level smoothing could make these nicer on UI-level too like in (2)
  4. Yes, infact I was using the version with wifi restart, but still it required me to re-run phev2mqtt to clear this.

Btw, any recommendation to figure out if car is present?

I guess vehicle presence can be done by checking the presence of the Wifi (iwlist scan or similar).

phev2mqtt does provide an availability topic also, though it’s not just based on Wifi presence, but TCP connectivity to the car.

1 Like

I am trying to use this addon for days, but still struggling with the same error

root@raspberrypi:/usr/local/phev2mqtt# ./phev2mqtt client watch
INFO[0000] %PHEV_TCP_CONNECTED%                         
panic: timed out waiting for start

goroutine 1 [running]:
github.com/buxtronix/phev2mqtt/cmd.Run(0x764110, 0xac44fc, 0x0, 0x0)
	/usr/local/phev2mqtt/cmd/watch.go:50 +0x514
github.com/spf13/cobra.(*Command).execute(0x764110, 0xac44fc, 0x0, 0x0, 0x764110, 0xac44fc)
	/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:860 +0x1f4
github.com/spf13/cobra.(*Command).ExecuteC(0x763e80, 0x0, 0x4aac0, 0x0)
	/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:974 +0x280
github.com/spf13/cobra.(*Command).Execute(...)
	/root/go/pkg/mod/github.com/spf13/[email protected]/command.go:902
github.com/buxtronix/phev2mqtt/cmd.Execute()
	/usr/local/phev2mqtt/cmd/root.go:55 +0x20
main.main()
	/usr/local/phev2mqtt/main.go:22 +0x14
root@raspberrypi:/usr/local/phev2mqtt# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:e0:4c:36:07:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.39/24 brd 192.168.2.255 scope global dynamic noprefixroute eth0
       valid_lft 863255sec preferred_lft 863255sec
    inet6 2a02:a454:f728:1:3954:fb90:a04f:6ce4/64 scope global dynamic noprefixroute 
       valid_lft 7002sec preferred_lft 3402sec
    inet6 fe80::ccee:b90d:7d3b:885/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 30:ab:6a:c5:6e:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.47/24 brd 192.168.8.255 scope global dynamic noprefixroute wlan0
       valid_lft 86022sec preferred_lft 86022sec
    inet6 fe80::4a5f:a189:3e3e:ebae/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Hope one of you can help me out :smiley:

Looks like it initially connects to the car, but the car won’t talk.

Is the Mac address of the wifi interface set to whatever your phones was when the official app was registered with the car?

Here u Find out mycar Mac address. I have run nmap and it says 8080/TCP open http-proxy

I even tried to tot set the connection to AP with nmtui command.

Looks like you have registered with the phone Mac address. Mac address type should be random, then re register. Else it will clash with the real phone Mac when you copy to the pi.

Also, what year is the car?

The car is from 2015, and i have tried it before with the random Mac addr, but with the same error.