Home Assistant Mitsubishi Outlander PHEV Car is Home Detector

Home Assistant Mitsubishi Outlander PHEV Detector

Home Assistant - Mitsubishi Outlander PHEV

I have created a project here on GitHub that allows me to detect if my Mitsubishi Outlander PHEV is home or not.

This is essentially a WiFi scanner that will look for my car’s WiFi access point and update Home Assistant with a status of ‘home’ or ‘away’.

Prerequisites

Software

  • Arduino IDE - I’m using v1.8.12
  • Arduino JSON - v6.15.1
  • PubSubClient - v2.7.0
  • ESP8266WiFi
  • ArduinoOTA

Hardware

Integrating with Home Assistant

The simplest way to integrate with Home Assistant is to turn on MQTT discovery. With this activated the device will be added automatically.

Alternatively you can add a new binary_sensor to the configuration.yaml like this:

    binary_sensor:
    - platform: mqtt
      name: Car Home Sensor
      state_topic: "car/home"
      qos: 1
      payload_on: "home"
      payload_off: "away"
      device_class: presence

For a more interesting integration you can take it one step further with a sensor that will change the displayed status from on/off to Home/Away and change the icon from a house to a car respectively.

    sensor:
      - platform: template
        sensors:
          car_home_sensor:
            friendly_name: Car Home Sensor
            entity_id: binary_sensor.car_home_sensor
            value_template: >
                {% if is_state('binary_sensor.car_home_sensor', 'on') %}
                  Home
                {% else %}
                  Away
                {% endif %}
            icon_template: >
                {% if states('binary_sensor.car_home_sensor') == 'on' %}
                    mdi:home
                {% else %}
                    mdi:car
                {% endif %}

Finally here is a really basic lovelace card:

Hi.

Thanks for this.
I had some issues with WiFi not reconnecting, but I see this is resolved in latest version.

I have installed the needed libraries as per the readme on github, and settings is per the readme as well.

However I get error on declaration of payloadON and payloadOff within scanResult() and sendConfigDetailsToHA()

In function 'void scanResult(int)':

outlander_detector:195:33: error: 'payloadOn' was not declared in this scope

     const char* currentStatus = payloadOn;

                                 ^

outlander_detector:197:23: error: 'payloadOff' was not declared in this scope

       currentStatus = payloadOff;

                       ^

In function 'void sendConfigDetailsToHA()':

outlander_detector:246:27: error: 'payloadOn' was not declared in this scope

     mqttConfig["pl_on"] = payloadOn;

                           ^

outlander_detector:247:28: error: 'payloadOff' was not declared in this scope

     mqttConfig["pl_off"] = payloadOff;

                            ^

Ahh this was totally my fault. I didn’t update the helper class.

I’ve updated the code on Gihub but to save you the effort append the following lines of code under payloadNotAvailable in the My_Helper.h file:

const char* payloadOn = "home";
const char* payloadOff = "away";

Hope this helps.

Thanks. That sovled that issue.

It does however break after Home Assistant restart. (Unavailable)

Arduino IDE serial shows no change, still scanning WiFi.
After a while I get these MQTT messages :

2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/availability: b''
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/config: b'{\r\n  "name": "Car Home Sensor",\r\n  "dev_cla": "presence",\r\n  "stat_t": "homeassistant/binary_sensor/garage/carHomeSensor/state",\r\n  "pl_on": "home",\r\n  "pl_off": "away",\r\n  "qos": 1,\r\n  "avty_t": "homeassistant/binary_sensor/garage/carHomeSensor/availability",\r\n  "uniq_id": "CHS",\r\n  "dev": {\r\n    "name": "Car Home Sensor",\r\n    "mf": "NandPez",\r\n    "mdl": "Outlander Detector",\r\n    "sw": "1.5",\r\n    "ids": [\r\n      "CHS",\r\n      "RstCHS"\r\n    ]\r\n  }\r\n}'
2020-11-12 20:35:10 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: binary_sensor garage carHomeSensor
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to homeassistant/binary_sensor/garage/carHomeSensor/availability, mid: 52
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to homeassistant/binary_sensor/garage/carHomeSensor/state, mid: 53
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/state (retained): b'home'
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/switch/garage/carHomeSensor/config: b'{\r\n  "name": "Reset",\r\n  "ic": "mdi:lock-reset",\r\n  "cmd_t": "homeassistant/switch/garage/carHomeSensor/set",\r\n  "stat_t": "homeassistant/switch/garage/carHomeSensor/state",\r\n  "avty_t": "homeassistant/binary_sensor/garage/carHomeSensor/availability",\r\n  "uniq_id": "RstCHS",\r\n  "dev": {\r\n    "name": "Car Home Sensor",\r\n    "mf": "NandPez",\r\n    "mdl": "Outlander Detector",\r\n    "sw": "1.5",\r\n    "ids": [\r\n      "CHS",\r\n      "RstCHS"\r\n    ]\r\n  }\r\n}'
2020-11-12 20:35:10 INFO (MainThread) [homeassistant.components.mqtt.discovery] Found new component: switch garage carHomeSensor
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to homeassistant/binary_sensor/garage/carHomeSensor/availability, mid: 54
2020-11-12 20:35:10 DEBUG (MainThread) [homeassistant.components.mqtt] Subscribing to homeassistant/switch/garage/carHomeSensor/state, mid: 55
2020-11-12 20:35:15 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/state: b''
2020-11-12 20:35:15 INFO (MainThread) [homeassistant.components.mqtt.binary_sensor] No matching payload found for entity: Car Home Sensor with state topic: homeassistant/binary_sensor/garage/carHomeSensor/state. Payload: ''

Then every once in a while I get :

2020-11-12 20:41:12 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/state: b'away'
2020-11-12 20:41:18 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on homeassistant/binary_sensor/garage/carHomeSensor/state: b'home'

Before HA restart I tried physically blocking the Wemos WiFi signal, and it reconnects and function as intended afterwards.

If I restart HA it becomes unavailable, but if I then proceed to restart the Wemos it works again.

Ok, so I think it’s appearing as unavailable because it’s sending an empty string as the state. The empty state is the hardcoded prevStatus.

You could try changing const char* prevStatus = ""; to const char* prevStatus = "off"; .

This should stop the unavailable message and then change to home when the car is detected again. Otherwise it will just stay as away.

If this doesn’t work you could add an automation at start up to restart the Wemos by calling the reset switch.

Sorry, this is more a work around than a fix at this stage. But once i get time i will add a feature to save the last state, but for now it’s hard coded.

The reset switch is greyed out and not functioning while unavailable.
Changing prevStatus didn’t resolve it, neither did car/home/debug with payload reset.

When the Wemos publishes changes in state I can see messages coming in to MQTT Explorer in Windows, but nothing in HA when I sub to
homeassistant/binary_sensor/garage/carHomeSensor/state

In my case it seems HA is unsubscribing the topic on startup, following a restart.
When I publish homeassistant/binary_sensor/garage/carHomeSensor/availability with payload online it works again.

As a workaround I put client.publish(availabilityTopic, payloadAvailable, true); within the startWiFiScan function/loop, and now it’s worked for the last day or so, across multiple restarts.

void startWiFiScan(){
  //start a scan of available WiFi networks
  Serial.println("Scanning WiFi Networks");
  WiFi.scanNetworksAsync(scanResult);
  client.publish(availabilityTopic, payloadAvailable, true);
}

In case it’s relevant. I am running Mosquitto on Windows. MQTT integration in HA is added via Configuration --> Integration --> +

Finally got time to look into this today and I’m a bit stumped as I can’t replicate it. Is it still an issue for you?

I’ve had it disconnected for a while now, but I’ve spun it up again and restarted HA 4 times now. It survived all 4 restarts, so far so good :+1:

1 Like

oo that’s good. fingers crossed.