Jaguar InControl Binding?

Hello!

I recently found a need to pull in information from Jaguar InControl into OpenHAB. Looking into this, I found a Python library here that looks like it would do what I’d want. I know I can run the python as a script and pull in the data via the exec binding, but it sure would be nice if it were an easy binding to configure instead. Anyone out there have a similar need and the time to develop an add-on?

If this is the wrong place to post this idea, please let me know.

1 Like

Hi
Did u ever find a solution to this?

No one has developed a binding yet, to my knowledge. I did ultimately build out the scripting and use the exec binding to pull this data into OpenHAB and parse it. It’s not high quality code, but it gets the job done.

Not a binding, but in case you haven’t found an alternative solution, I’ve put together an mqtt wrapper around the library, and added basic support for corresponding “things” auto discovery in openHAB (using the HomeAssistant format support of the mqtt 2 binding): https://github.com/smar000/jlr2mqtt

1 Like

I am working on getting this working with OH2.5.3 and the MQTT Binding and embedded broker in 2.5.3. This is my first experience with MQTT, and I am struggling a little to understand how to take the wrapper you’ve written and implement it. I am sure it’s a lack of knowledge of what to even search for. Could you give me a tip or two for implementing this on 2.5.3 using PaperUI? I am trying to stay away from using v1 bindings anywhere I can.

Also, I have two vehicles I need to get JLR status from. It isn’t clear to me how to do that based on my review of the wrapper, but perhaps that’ll become more clear when I better understand how to implement this.

I’m assuming you have installed the MQTT 2 binding and that you have a working MQTT broker.

If so, once you have the python wrapper script running, it will post entries to your mqtt broker, including autodiscovery details (using the HomeAssistant format, which is one of the 2 supported auto-discovery methods supported by the MQTT 2 binding).

This in turn should automatically populate your PaperUI Inbox with the newly discovered things. If you are not getting these, I suggest checking your mqtt broker and making sure that it is receiving the data correctly from the script. In case you don’t have a suitalbe tool at hand for monitoring your broker, one good tool is MQTT Explorer (https://mqtt-explorer.com/).

I have not really factored in multiple vehicles when putting together the script. For now, simplest would be to run two separate instances of the script (put two copies in different folders, configure the mqtt topics such that they are also different between the two copies, and then just run both the instances concurrently).

1 Like

Thank you. I will give this a try. My apologies if I missed something and am asking a redundant question - how exactly are you implementing the python wrapper itself? Just an external cron job, or are you actually implementing it as an Exec “Thing” in OH itself?

I have it running as a service (on an Ubuntu server). That way the interface is available all the time. Then from openHAB, I post “commands” to the corresponding mqtt topic (e.g. refresh the status every 5 minutes, lock the doors if the car has been left unlocked for a period of time, turn on the pre-heating in the winter at scheduled times etc). The script then picks up the “command” from the mqtt topic, and processes accordingly.

1 Like

I am running into a problem with the wrapper it appears. I get this error when trying to run the script manually or as a service.

2020-04-30 11:06:18,650 - INFO - Connecting to mqtt server 127.0.0.1
Traceback (most recent call last):
  File "jlr2mqtt.py", line 579, in <module>
    mqtt_client = initialise_mqtt_client(mqtt.Client(client_id=MQTT_CLIENTID))
  File "jlr2mqtt.py", line 108, in initialise_mqtt_client
    mqtt_client.connect(MQTT_SERVER, port=1883, keepalive=0, bind_address="")
  File "/usr/local/lib/python3.6/dist-packages/paho/mqtt/client.py", line 937, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.6/dist-packages/paho/mqtt/client.py", line 1071, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python3.6/dist-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
BlockingIOError: [Errno 115] Operation now in progress

I can telnet to the MQTT server at 1883 both on localhost and the server’s LAN IP. I am using the embedded MQTT server, which shows online, and I can successfully configure a Broker connection in PaperUI which also shows online when properly configured. There is no firewall enabled on this device. Any idea on how to troubleshoot this further?

I am not really familiar with the embedded MQTT server. Can you try using mosquitto instead?

Also maybe try using the actual LAN IP address instead of localhost 127.0.0.1.

Tried this, it doesn’t work. Let me work on configuring mosquitto in that case and see if that resolves my issue.

Did this, the issue seems to persist with the same error both on the LAN IP and on the localhost IP. I can successfully subscribe and publish manually using this guide’s instructions, and I’ve properly set the username and password in the jlr2mqtt.cfg.

Do you have all of these services - mosquitto, jlr2mqtt as a service, and openHAB2 all running on the same Ubuntu box? This is my current configuration as well.

Thanks in advance, I understand you weren’t planning to provide much support on this wrapper and I do appreciate your time.

I have both mosquitto and the jlr2mqtt services on a single Ubuntu 18.04 VM (and openHAB on a separate one, but I don’t think that matters). I am also running python 3.6.8.

I am a bit tied up at the moment, but will have a look at the code again later tonight/tomorrow. As the issue is not openHAB related, can you open an issue on github until we can get you up and running. That way we can continue our discussion without cluttering this thread.

Most welcome!

1 Like

Hi @nolan_garrett

Well spotted that the connection problem you were experiencing was related to the mqtt keepalive messages! I have just uploaded a new build to the github repository accordingly.

This seems to have resolved my issue! Thank you! I don’t quite yet have any Things being autodiscovered, but I’ll work on that. Thank you for all of your help.

The autodiscovery data is only posted after your first succesful get_status command (as before that, the code doesn’t know what information is available from your vehicle).

If you have sent a get_status command, can you check your MQTT broker and make sure that (a) you have current vehicle status data under the topic jlr2mqtt, and (b) you have various sensor definition data under homeassistant/sensor/jlr2mqtt_*.

Not seeing the vehicle status data:

The above is all that is showing, and you can see I sent a get_status:
mosquitto_pub -m "{"command":"get_status"}" -t "jlr2mqtt" -u "<redacted>" -P "<redacted>"

I also tried:
mosquitto_pub -m "{\"command\":\"get_status\"}" -t "jlr2mqtt" -u "<redacted>" -P "<redacted>"

Which resulted in:
image

The jlr2mqtt.py is running on Python 3.6.9 on the console. It shows this output:

2020-05-02 11:37:40,500 - INFO - Connecting to mqtt server 127.0.0.1
2020-05-02 11:37:40,512 - INFO - Subscribing to mqtt topic ‘jlr2mqtt/command’ for inbound commands
2020-05-02 11:37:40,514 - INFO - MQTT connection established with broker

This occurs with the Moquette embedded broker as well as Mosquitto. Am I sending the get_status command correctly?

Additionally, here’s my config:

[JLR]
USER_ID = <redacted>
PASSWORD = <redacted>
PIN = <redacted>

[MQTT]
MQTT_USER           = <redacted>
MQTT_PASSWORD       = <redacted>
MQTT_PUB_TOPIC      = jlr2mqtt
MQTT_SUB_TOPIC      = jlr2mqtt/command
MQTT_SERVER         = 127.0.0.1
MQTT_CLIENTID       = jlr2mqtt
MQTT_RETAIN         = False

MQTT_KEEPALIVE      = 60

[MISC]
HOMEASSISTANT_DISCOVERY = True

DISCOVERY_SENSORS_LIST = "door_is_all_doors_locked, position"

Couple of things to note in posting your command to the mosquitto broker:

  1. The -m argument is expecting a string, but we need to send a JSON (which also uses double quotes internally to bound string items). To get around this, use single quotes around the beginning and end of the JSON and double internally within the JSON, as otherwise your JSON does not get through correctly; and

  2. the topic that is being monitored for commands is jlr2mqtt/command (can be changed in the .cfg file), and not jlr2mqtt (which is just the root topic for the data coming back from the wrapper).

You would thus use something like:

mosquitto_pub -m '{"command":"get_status"}' -t "jlr2mqtt/command" -u "<redacted>" -P "<redacted>"

Also in your config file, try commenting out the DISCOVERY_SENSORS_LIST for now, so that you get everything available from your vehicle. This way you can check whether the filtered options you have specified ( door_is_all_doors_locked, position) are actually coming through from the jlr servers. You can always filter the list later once everything is working, if you want to.

This fixed it, now I’m getting a JLR connection and some data. I am not however getting a homeassistant/sensor path as previously noted, and no items showing in the PaperUI Inbox yet.

Sorry, this seems to be step by step. Do you have any special Broker or Thing configuration in openHAB? My reading of the MQTT Binding docs led me to understand homeassistant items should just be discovered. I’m guessing they should show in MQTT Explorer first though.

Good to hear that you are now getting data into your mqtt broker.

If you run the wrapper script directly (e.g. running python3 jlr2mqtt.py directly from a shell), you should see the log messages from the script (they are also in the system logger, e.g. journalctl -f -u jlr2mqtt -n 1000 --no-pager). The first time get_status is called after starting the script, it should create the HomeAssistant entries, and post a message to the log saying that it has done so.

PaperUI Inbox should show the ‘things’ automatically as soon as we have the sensor data posted to the homeassistant topic as above.