Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Add optional check for HA remote_rpi_gpio connectivity #95

Open
andystewart999 opened this issue Jun 30, 2021 · 0 comments

Comments

@andystewart999
Copy link

Hi there,

HA's remote_rpi_gpio integration is great but it's not very robust... if the endpoint Pi reboots it never reconnects and the 'parent' HA instance needs to be restarted.

I've added a check to system_sensors to see if there is an active connection on the remote GPIO port from the parent HA instance, and include that flag in the MQTT output. I'm offering it for consideration as a feature update.

Under updateSensors()

    if "check_remote_gpio" in settings and settings["check_remote_gpio"]:
        payload_str = payload_str + '", "remote_gpio": "' + check_remote_gpio()

The function itself:

def check_remote_gpio():
    temp = check_output(['bash', '-c', "netstat -tWn" ]).decode('utf-8')
    if ":8888" in temp:
        temp = check_output(['bash', '-c', "netstat -tW | grep 8888" ]).decode('utf-8')
        if settings["remote_gpio_ip"] not in temp:
            return "Not connected"
        else:
            return "Connected"
    else:
        return "Not connected"

Defining the new MQTT field metadata:

    if "check_remote_gpio" in settings and settings["check_remote_gpio"]:
        mqttClient.publish(
            topic="homeassistant/sensor/"
            + deviceName
            + "/"
            + deviceName
            + "RemoteGPIO/config",
            payload='{"name":"'
            + deviceName
            + 'RemoteGPIO","state_topic":"system-sensors/sensor/'
            + deviceName
            + '/state","value_template":"{{ value_json.remote_gpio}}","unique_id":"'
            + deviceName.lower()
            + '_sensor_remote_gpio","device":{"identifiers":["'
            + deviceName.lower()
           + '_sensor"],"name":"'
            + deviceName
            + 'Sensors","model":"RPI '
            + deviceName
            + '","manufacturer":"RPI"}, "icon":"mdi:swap-horizontal"}',
            qos=1,
            retain=True,
        )

New values in settings.yaml:

check_remote_gpio: true
remote_gpio_ip: 192.168.11.

Thanks again for your continued efforts,
Andy

@andystewart999 andystewart999 changed the title [Feature update] Add optional check for HA remote_rpi_gpio connectivity [Feature request] Add optional check for HA remote_rpi_gpio connectivity Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant