homebridge-mqttthing icon indicating copy to clipboard operation
homebridge-mqttthing copied to clipboard

mqttthing and Victron Venus OS support

Open houser42 opened this issue 5 years ago • 15 comments

Just a general wish for device support for the Victron Venus OS. I have it up and running, with the usual caveats of having to use temp and humidity for voltage and state of charge etc. Would be very useful and possibly for many people. FWIW.

I used this to gets started, it is for openhab, but is pretty relevant as a starting point to the mqttthing plugin: https://community.openhab.org/t/mqtt-1-x-2-x-interface-to-victron-ccgx/43888 Some info on the open source victron protocols if someone wants to have a look: https://www.victronenergy.com/live/open_source:start Thanks again for a great plugin!

houser42 avatar Apr 19 '20 13:04 houser42

It would also be really great if a specific keep alive function string/command could be set from within the mqttthing plugin. The Victron gear wants a keep alive every 60 secs. Other than that, this works great.. many thanks.

houser42 avatar May 07 '20 17:05 houser42

You can send a keep-alive by using a codec. For example, place this file (keep-alive-codec.js) next to your config.json file:

// keep-alive-codec.js
module.exports = {
    init: function( params ) {
        let { config, publish } = params;

        // publish keep-alive topic at regular interval
        if( config.keepAliveTopic ) {
            let keepAlivePeriod = config.keepAlivePeriod || 60;
            let keepAliveMessage = config.keepAliveMessage || '';
    
            setInterval( () => {
                publish( config.keepAliveTopic, keepAliveMessage );
            }, keepAlivePeriod * 1000 );
        }
    
        // no encode/decode in this codec
        return {};
    }
};

... then add this to your accessory configuration:

            "codec": "keep-alive-codec.js",
            "keepAliveTopic": "keep/alive",
            "keepAlivePeriod": 30,
            "keepAliveMessage": "Keep-alive!"

arachnetech avatar May 07 '20 18:05 arachnetech

Many thanks, will try this right away! When you write "add this to your accessory configuration" what file do you mean that goes into? config.json? Thanks again!

houser42 avatar May 07 '20 19:05 houser42

Yes. I tested it with this:

        {
            "accessory": "mqttthing",
            "type": "lightbulb-HSV",
            "name": "Test espurna Light",
            "url": "http://192.168.10.35:1883",
            "topics": {
                "getHSV": "test/hsvlight2/hsv",
                "setHSV": "test/hsvlight2/hsv/set",
                "getOn": "test/hsvlight2/on",
                "setOn": "test/hsvlight2/on/set"
            },
            "logMqtt": true,
            "integerValue": true,
            "codec": "keep-alive-codec.js",
            "keepAliveTopic": "keep/alive",
            "keepAlivePeriod": 30,
            "keepAliveMessage": "Keep-alive!"
        }

arachnetech avatar May 07 '20 23:05 arachnetech

This works great! Have had it running for a few hours so far with zero issues. It solves my issue 100% to automate some vital things based on a few parameters in the Venus OS. And it will be 100% neat when there are other icons and parameters in Home kit itself at some point. Many thanks again. Really appreciate this! Made my day!

houser42 avatar May 08 '20 07:05 houser42

Still working great here.. Related Q: Is it possible to add a client certificate file file via the mqtt options? If so, some code would be great if possible? Many thanks.

houser42 avatar May 10 '20 08:05 houser42

The only mention of certificates I can see at https://www.npmjs.com/package/mqtt#client is to disable rejection of self-signed server certificates. I'm not sure that MQTT supports client certificates.

arachnetech avatar May 10 '20 11:05 arachnetech

Ok. Then it is probably above my skillset to figure out I'm afraid.. I'll definitely give it a shot on my setup if someone can provide an example for config.json to try out. The Victron Venus public MQTT server requires the use of a client certificate. The local connection to a Venus gx does not. So my local connection works great as is with mqttthing. FWIW.

houser42 avatar May 10 '20 12:05 houser42

Sorry, I take that back! TLS options are passed straight through to https://nodejs.org/api/tls.html#tls_tls_connect_options_callback.

Looking at https://github.com/mqttjs/MQTT.js/issues/1077 I'll need to add a way for you to specify filenames that mqttthing loads.

arachnetech avatar May 10 '20 12:05 arachnetech

I see. Here is the .crt file that Victron uses if that helps for the specific case of the Venus OS: https://github.com/victronenergy/dbus-mqtt I'll definitely try it if you get to it. Many thanks.

houser42 avatar May 10 '20 12:05 houser42

The latest release (v1.1.19) now allows certificate files to be loaded for MQTT. See https://github.com/arachnetech/homebridge-mqttthing/blob/v1.1.19/docs/Configuration.md#mqtt-settings for details.

arachnetech avatar Aug 14 '20 00:08 arachnetech

@houser42 could you post your config for this? I've tried to replicate what is detailed here but it seems I never get any actual values from MQTT.

baroldgene avatar Jun 04 '23 07:06 baroldgene

Hello @baroldgene I have taken a different path and is using a different combo and config so I'm afraid I can't help with this anymore. If you are generally trying to get a Venus GX device working with MQTT and Node Red, I might be able to answer a q or two?

houser42 avatar Jun 04 '23 07:06 houser42

Ah gotcha. Sadly I'm just trying to get my Ruuvi temp sensors (connected to my Cerbo GX) to show in homekit. Seems a futile effort maybe.

baroldgene avatar Jun 04 '23 07:06 baroldgene

That should be reasonably straight forward if you are using Venus OS Large and Node red. I do tons of that sort of thing, translating the IOT thingamajigs to HomeKit in Node red. Both for simple display and also switching. Never used the Ruuvi sensors, but if they are cumbersome, there are many cheap temp sensors (I tend to use mostly use €15 Shelly Wifi sensors but anything that has a decent NR package should work) that will allow you to get temps humidity and such into HK without paying a fortune. This might be useful to you also: https://community.victronenergy.com/questions/194264/control-mppt-relay-via-ruuvi-temperature-in-node-r.html

houser42 avatar Jun 04 '23 07:06 houser42