MQTT Auto discovery json python template?

Does there exist a json template (for python) that can be used to auto discover mqtt devices?.
I found a github where this nice fellow has made a python wrapper for a Horman Bisecur device that I have.
The github page is here: GitHub - smar000/bisecur2mqtt: MQTT wrapper to Hormann Bisecur Gateway Library
There is a home assistant auto discovery part in there, but it’s not been tested properly.
And when I try it, the Biscur is discovered as a single entity, and not as a device with multiple entities.
I suspect this comes down to proper json formatting, but I don’t know where to start.

The current code looks like this:

def init_ha_discovery():
    payload = {"door_commands_list": ["impulse",
                                      "up", "down", "partial", "stop", "light"],
               "json_attributes_topic": f"{MQTT_TOPIC_BASE}/attributes",
               "name": "Bisecur Gateway: Garage Door", "schema": "state",
               "supported_features": ["impulse", "up", "down", "partial", "stop", "light", "get_door_state", "get_ports", "login", "sys_reset"],
               "availability_topic": f"{MQTT_TOPIC_BASE}/state",
               "payload_available": "online",
               "payload_not_available": "offline",
               "unique_id": "bs_garage_door",
               "device_class": "garage",
               "payload_close": "down",
               "payload_open": "up",
               "payload_stop": "impulse",
               "position_open": 100,
               "position_closed": 0,
               "position_topic": f"{MQTT_TOPIC_BASE}/garage_door/position",
               "state_topic": f"{MQTT_TOPIC_BASE}/garage_door/state",
               "command_topic": f"{MQTT_TOPIC_BASE}/{MQTT_COMMAND_SUBTOPIC}/command"}
    bisecur_mac = config.get("bisecur_mac", "").replace(':', '')
    bisecur_ip = config.get("bisecur_ip", None)
    payload["connections"] = ["mac", bisecur_mac, "ip", bisecur_ip]
    payload["sw_version"] = VERSION
    # _, payload["gw_hw_version"] = get_gw_version()
    payload["gw_hw_version"] = '1.0.0'

    mqtt_topic_HA_discovery = config.get("mqtt_topic_HA_discovery", "homeassistant")
    publish_to_mqtt("cover/bisecur/config", json.dumps(payload), f"{mqtt_topic_HA_discovery}")
    publish_to_mqtt("attributes/system_version", VERSION)
    publish_to_mqtt("attributes/gw_ip_address", bisecur_ip)
    publish_to_mqtt("attributes/gw_mac_address", bisecur_mac)

Any pointers is greatly appreciated.
Thanks

I’ve been staring at this for days now, but it still partially works.
The current code looks like this:


{
  "availability": [
    {
      "topic": "bisecur2mqtt/garage_door/state",
      "payload_available": "online",
      "payload_not_available": "offline"
    }
  ],
  "command_topic": "bisecur2mqtt/garage_door/commands",
  "device": {
    "identifiers": [
      "Hörmann Bisecur Gateway"
    ],
    "name": "Bisecur Gateway",
    "manufacturer": "Hörmann",
    "model": "Bisecur Gateway",
    "sw_version": "2.50.0"
  },
  "json_attributes_topic": "bisecur2mqtt/garage_door",
  "name": "Bisecur Garage door - Door",
  "value_template": "{{ value_json.position }}",
  "state_topic": "bisecur2mqtt/garage_door",
  "unique_id": "0x001ec0edd909_door_bisecur2mqtt",
  "device_class": "garage",
  "position_template": "{{ value_json.value | round(0) }}",
  "position_topic": "bisecur2mqtt/garage_door/position",
  "set_position_topic": "bisecur2mqtt/garage_door/position",
  "position_open": 100,
  "position_closed": 0,
  "payload_close": "down",
  "payload_open": "up",
  "payload_stop": "impulse",
  "platform": "mqtt"
}

This is sent to the topic: homeassistant/cover/bisecur2mqtt/garage_door/config

In HA, I can now see this:
image

The garage door opens when I press the arrow, and closes when I press the same button again.
The stop button also works

Things that must be fixed:

  • The icon always shows the garage door as open.
  • The up arrow does not change to the down arrow when the port is open
  • The position slider does not work either
  • When I add this to the dashboard using a mushroom cover card, it says that the state is Unknown
  • I cannot see the activity / position of the garage port anywhere. I mean when it is closing / opening, etc.

Preferrably, I would like to use the discovery topic: homeassistant/cover/bisecur2mqtt/garage_door/door/config, since this device also have a light. But if I change it to this, no discovery happens at all

What am I doing wrong? Going slightly insane here.

@Dal
I would like to use this feature as well. How did you “install” the custom mqtt wrapper library?

Br
christian

@Dal I’m interested in using this too, how did you install wrapper?

Hi
I downloaded the wrapper from here:

Dal, Thanks for your help, as that’s a different (docker) repository from the HA originally posted one , Did you change to using this with docker on a pi instead?

Hmm, try here:

and I downloaded it using:

mkdir bisecur2mqtt
cd bisecur2mqtt/
git clone https://github.com/smar000/bisecur2mqtt.git

I hope you figure out how to use this. I had to give up after countless hours.

Thanks,I have the BiSecur gateway so I’m giving it a go, as it’s not a HASS custom-component, I’ve been trying to run it within hass using Pyscript, however not having much success with that so far. Can you clarify Did you just run it as a python script from the terminal? Did you have to first import the pysecur3 module using PIP or other?

I just ran it using python3 bisecur2mqtt.py
But I had to install all the dependencies first, like paho-mqtt
You also need to fill out bisecur2mqtt.conf with your own information

Has anyone gotten further on this? I am new to HA and have Horman gate and bought the gateway to try to get the integration working. Not that experienced with python, but will give it a shoot :slight_smile:

Currently installed the bisecure2mqtt wrapper from github to unbuntu VM. Created a separate user in the bisecure app. Updated the .conf file with relevant info. Running the script it seems like it is able to connect to the gateway and get the status of the gate. It tries to connect to the mqtt broker - but gets errors. So I need to look into how to proceed from here. I will try to update as I, hopefully, move forward on this.

Did anyone get any further trying to integrate the bisecur Gateway in HA?