My Mitsubishi PHEV integration, via MQTT

Hey, sorry I feel stupid but need to make sure that I got it right.

If I have my home-assistant instance installed on the raspberry, can I still use this on the same raspberry device, or do I need to get another one?

And if it is possible, could you elaborate a bit on the process how to get the broker compiled onto it? If I have understood now correctly, I should download the GO compiler on the rasberry device, download the archive and then compile it on the device itself?

Thank you for the awesome work!

Iā€™m looking to integrate this a bit different way than with raspi. Iā€™m going with old mobile phone running termux because I wanā€™t mobile connectivity and good battery life for my ā€œPHEV remoteā€ and to have the mobile as my car phone / navigator at the same time.

Iā€™ve succesfully gotten phev2mqtt running now and I can get Tasker to handle the wifi switching etc. so that I will be able to use phev2mqtt over 4G/LTE.

Now my problem is that I wonā€™t be able to use mqtt abilities because of the 4G/WIFI switching and running with Tasker. Well I might be able to achieve this by using rooted phone and by configuring ip routes to correct network interfaces but my phone at the moment is unrootable (Blackberry).

I would like to use phev2mqtt client set commands for now. Iā€™m trying to understand how to set the climate (acmode, heat/windscreenā€¦, duration). Iā€™m inspecting the mqtt file from cmd folder:

else if strings.HasPrefix(msg.Topic(), m.topic("/set/climate/")) {
		topic := msg.Topic()
		payload := strings.ToLower(string(msg.Payload()))

		modeMap := map[string]byte{"off": 0x0, "OFF": 0x0, "cool": 0x1, "heat": 0x2, "windscreen": 0x3, "mode": 0x4}
		durMap := map[string]byte{"10": 0x0, "20": 0x10, "30": 0x20, "on": 0x0, "off": 0x0}
		parts := strings.Split(topic, "/")
		state := byte(0x02) // initial.
		mode, ok := modeMap[parts[len(parts)-1]]
		if !ok {
			log.Errorf("Unknown climate mode: %s", parts[len(parts)-1])
			return
		}
		if mode == 0x4 { // set/climate/mode -> "heat"
			mode = modeMap[payload]
			payload = "on"
		}
		if payload == "off" {
			mode = 0x0
		}
		duration, ok := durMap[payload]
		if mode != 0x0 && !ok {
			log.Errorf("Unknown climate duration: %s", payload)
			return
		}
		if mode == 0x0 {
			state = 0x1
		}
		if err := m.phev.SetRegister(0x1b, []byte{state, mode, duration, 0x0}); err != nil {
			log.Infof("Error setting register 0x1b: %v", err)
			return

So for heat 20 minutes I use command ā€œphev2mqtt client set 0x1b,0x02,0x2,0x10,0x0ā€ am I correct?

Just want to make this sure so I donā€™t break anything at the PHEVā€¦

with regards to 2ā€¦ I have implemented the following code in my configuration.yaml and use this new ā€œsensor.phev_battery2ā€ for my gauge.

  • platform: template
    sensors:
    phev_battery2:
    unit_of_measurement: ā€˜%ā€™
    friendly_name: ā€œCar Batteryā€
    value_template: >
    {% if states(ā€˜sensor.phev_batteryā€™) in [ā€˜unknownā€™, ā€˜unavailableā€™, ā€˜Noneā€™] %}
    0
    {% elif states(ā€˜sensor.phev_batteryā€™)|float >94 %}
    {{(states(ā€˜sensor.phev_battery2ā€™)|float *1)}}
    {% else %}
    {{(states(ā€˜sensor.phev_batteryā€™)| float /0.94) |round(0) }}
    {% endif %}

Any advice on this. So I have RaspberryPi where phev2mqtt is installed.
I have USB WIFI dongle and set to connect to the car.
I have LAN connected to home network via router.
But I guess every time the connection is made to car my SSH connection dies and after that Iā€™m not able to connect to the Pi.
When I remove the USB WIFI dongle Iā€™m able to make the connection again.
Operating in headless so not able to say if the connection to car really works.
Topics on mqtt broker are not updated (only shows )

phev/available

10/11/2021 2:19:24 PM 
offline

I guess this is some kind of configuration/routing issueā€¦

Hi,
this is exactely what I am searching for my Outlander PHEV 21, it looks so promessing!!! :slight_smile:
I so hope to get it runningā€¦
It took me some hoursā€¦ but now I get some data from the car.

But I am stuck now.
./phev2mqtt client mqtt --mqtt_server tcp://IP:1883 [ā€“mqtt_username XXX] [ā€“mqtt_password XXX]
It does not work, I always get ā€œError: not Authorizedā€
Any ideas?
Thanks, Michael

I was setting up this earlier today and got the same error. I was using the mqtt user for the Mosquitto broker add-on, but when I added a dedicated PHEV MQTT user to HA it worked.

It works very well so far and seems very responsive, great work! Running in a container on my Proxmox host and using an old wireless D-link router with dd-wrt as a wireless bridged from the Outlander to my cabled network.

I keep getting a lot of errors, but it re-connects, so still works fine:

kristian@phev2mqtt ~$ sudo systemctl status phev2mqtt
[sudo] password for kristian: 
* phev2mqtt.service - phev2mqtt
   Loaded: loaded (/etc/systemd/system/phev2mqtt.service; disabled; vendor preset: enabled)
   Active: active (running) since Thu 2021-12-02 11:58:02 CET; 8h ago
 Main PID: 1686 (phev2mqtt)
    Tasks: 5 (limit: 4915)
   Memory: 10.0M
   CGroup: /system.slice/phev2mqtt.service
           `-1686 /usr/local/bin/phev2mqtt client mqtt --mqtt_server tcp://<hassip>:1883/ --mqtt_username phevmqtt --mqtt_password MySecretPassword -v info

Dec 02 19:40:39 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:40:39+01:00" level=error msg="Disconnecting due to too many errors"
Dec 02 19:40:40 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:40:40+01:00" level=info msg="%PHEV_TCP_CONNECTED%"
Dec 02 19:45:56 phev2mqtt phev2mqtt[1686]: Short msg
Dec 02 19:46:07 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:46:07+01:00" level=error msg="Disconnecting due to too many errors"
Dec 02 19:46:08 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:46:08+01:00" level=info msg="%PHEV_TCP_CONNECTED%"
Dec 02 19:56:35 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:56:35+01:00" level=error msg="Disconnecting due to too many errors"
Dec 02 19:56:36 phev2mqtt phev2mqtt[1686]: time="2021-12-02T19:56:36+01:00" level=info msg="%PHEV_TCP_CONNECTED%"
Dec 02 20:01:59 phev2mqtt phev2mqtt[1686]: Short msg
Dec 02 20:02:03 phev2mqtt phev2mqtt[1686]: time="2021-12-02T20:02:03+01:00" level=error msg="Disconnecting due to too many errors"
Dec 02 20:02:04 phev2mqtt phev2mqtt[1686]: time="2021-12-02T20:02:04+01:00" level=info msg="%PHEV_TCP_CONNECTED%"

Thanks for your reply. I donā€™t use HA :sweat_smile: I use another smart home system (Loxone with Loxberry), but have mqtt running. I tried to connect to my already running mqtt Mosquitto broker/server. Maybe that is the problem. I will try to make a second Mosquitto broker/server or use a docker container for HA, but as far as I have read, it uses an external Mosquitto broker/server as well, right?
Thanks, Michael

Iā€™m getting this error, did you ever find a solution?

My Github issue, for context:

Hi @buxtronix.
I want to say that I have a PHEVā€™14 since 2019 and only recently I have found this work of yours.
After several hours I finally got it working with my HA.
I had several connections issuesā€¦ what worked for me was getting my Pi closer to the Car :slight_smile:

Congratulations on this and Thank you very much. I would like to help in any way I can. Iā€™m not familiar with GO but I can give it try. If not that then for count with me for testing :wink:

I have a question:

  • What is the refresh rate of the client? I mean, how long between updates?

Do you still have this? What worked for me was not using brackets

Is this possible?
Reading the Mitsubishi with the same computer you run home assistant and MQTT broaker on?

And does someone have an easy way to integrate this in HA?
Something like a blueprint.

thnx.

Hello.

Anyone have a YouTube movie for this?
Never done this and a newbi :slight_smile:

Yes it is possible.
That is what I have.
I had to bring my raspberry closer to the PHEV in order for it to communicate correctly.

There is no easier way then the one mentioned in the github page of this component.
The author also shares a lovelace config yaml that helps to understand how view the data in HA.
It toke me a couple of hours to get it done.
There are still a couple of bugs but we have to have hope they will get fixed.

I created a daemon service on the pi, so that this ā€œprogramā€ runs all the time and also starts at reboot.
I also created an HA restCommand so that I could restart this service in case of lost connection (it happens sometimes)
It could also help you :slight_smile:

Good Luck,
Any questions, post here, we will try to answer

Iā€™m running on debian.
Is that also possible?

Iā€™m not that good in programming, but will give it a try and probably wil have some questions again.

thnx.

Iā€™m running debian also, so yes it is possible.
Setting up is also fun :wink:

Do you have a how to install under debian?

Have you already tried the instructions in here: GitHub - buxtronix/phev2mqtt: Mitsubishi PHEV to MQTT gateway ??

Is your climate also working?

Did you find a way to use this?

Iā€™m stuck on * Download the phev2mqtt archive
Where do i download it, i canā€™t find it in the Github?