Git Product home page Git Product logo

hass_openwrt's Introduction

Home Assistant integration with OpenWrt devices

hacs_badge

Features

  • Sensors:
    • Wireless clients counters
    • Number of connected mesh peers
    • Signal strength of mesh links
    • mwan3 interface online ratio
    • WAN interfaces Rx&Tx bytes counters (if configured)
  • Switches:
    • Control WPS status
  • Binary sensors:
    • mwan3 connectivity status
  • Services:
    • Reboot device: openwrt.reboot
    • Execute arbitrary command: openwrt.exec (see the configuration below)
    • Manage services using command-line: openwrt.init (see the configuration below)

Installing

  • OpenWrt device(s):

    • Make sure that uhttpd uhttpd-mod-ubus rpcd packages are installed (if you use custom images)
      • If you use mesh networks, install rpcd-mod-iwinfo package
    • Make sure that ubus is available via http using the manual: https://openwrt.org/docs/techref/ubus
      • To make it right, please refer to the Ubus configuration section below
  • Home Assistant:

    • Add this repo as a custom integration using HACS
    • Restart server
    • Go to Integrations and add a new OpenWrt integration

Ubus configuration

  • Create new file /usr/share/rpcd/acl.d/hass.json:
{
  "hass": {
    "description": "Home Assistant OpenWrt integration permissions",
    "read": {
      "ubus": {
        "network.wireless": ["status"],
        "network.device": ["status"],
        "iwinfo": ["info", "assoclist"],
        "hostapd.*": ["get_clients", "wps_status"],
        "system": ["board"],
        "mwan3": ["status"]
      },
    },
    "write": {
      "ubus": {
        "system": ["reboot"],
        "hostapd.*": ["wps_start", "wps_cancel"]
      }
    }
  }
}
  • Add new system user hass (or do it in any other way that you prefer):
    • Add line to /etc/passwd: hass:x:10001:10001:hass:/var:/bin/false
    • Add line to /etc/shadow: hass:x:0:0:99999:7:::
    • Change password: passwd hass
  • Edit /etc/config/rpcd and add:
config login
        option username 'hass'
        option password '$p$hass'
        list read hass
        list read unauthenticated
        list write hass
  • Restart rpcd: /etc/init.d/rpcd restart

Executing command

In order to allow ubus/rpcd execute a command remotely, the command should be added to the permissions ACL file above. The extra configuration could look like below (gives permission to execute uptime command):

{
  "hass": {
    "write": {
      "ubus": {
        /* ... */
        "file": ["exec"]
      },
      "file": {
        /* ... */
        "/usr/bin/uptime": ["exec"]
      }
    },
  }
}

Manage services using command-line

In order to allow ubus/rpcd execute a command remotely, the command should be added to the permissions ACL file above. The extra configuration could look like below (gives permission to manage presence-detector service. Start, stop, restart, enable and disable system services.):

{
  "hass": {
    "write": {
      "ubus": {
        /* ... */
        "rc": ["init"]
      },
      "rc": {
        /* ... */
        "/etc/init.d/presence-detector": ["init"]
      }
    },
  }
}

Screenshots

Screenshot 2021-10-11 at 14 07 34

Screenshot 2021-10-11 at 14 08 15

hass_openwrt's People

Contributors

cewbdex avatar dckiller51 avatar kvj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hass_openwrt's Issues

WPS switches not available

Sample settings. When adding integration, the WPS checkbox is checked. There are no vps switches in objects.
image
image

Support PoE sensor

I have two OpenWrt-based managed switches with 24/48 PoE ports. I would like to monitor the power consumption within Home Assistant, thus it makes a lot of sense to integrate them into this project.
My switches are Realtek-based and require the realtek-poe package to support PoE. This package provides a ubus call poe info command to get, amongst others, power statistics.

Is this enough to create a HA sensor for it?

Thanks

rpc error: 3

Trying to set up the integration, I get this error:
2021-10-24 10:22:17 WARNING (MainThread) [homeassistant.config_entries] Config entry 'OpenWRT Router - 192.168.0.1' for openwrt integration not ready yet: OpenWrt communication error: rpc error: 3; Retrying in background 2021-10-24 10:22:22 ERROR (MainThread) [custom_components.openwrt.coordinator] Device [OpenWRT Router] async_update_data error: rpc error: 3 Traceback (most recent call last): File "/config/custom_components/openwrt/coordinator.py", line 207, in async_update_data result['wireless'] = await self.update_ap(wireless_config['ap']) File "/config/custom_components/openwrt/coordinator.py", line 154, in update_ap result[item['ifname']] = await self.update_hostapd_clients(item['ifname']) File "/config/custom_components/openwrt/coordinator.py", line 114, in update_hostapd_clients response = await self._ubus.api_call( File "/config/custom_components/openwrt/ubus.py", line 41, in api_call return await self._api_call(rpc_method, subsystem, method, params) File "/config/custom_components/openwrt/ubus.py", line 121, in _api_call raise ConnectionError(f"rpc error: {result[0]}") ConnectionError: rpc error: 3

I followed the installation instructions, and I seem to be able to authenticate using the http method here
curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "secret" } ] }' http://your.server.ip/ubus

Refactor `openwrt.reboot` service into a button entity

Hello, first thanks a lot for your integration. I am planning to build a script to simplify the router configuration for this integration, so that it can be easily ran through something like SSH.

I have a suggestion for you: refactor openwrt.reboot service into a button entity.

Some other router integrations have this as well, and I think it fits the purpose more nicely and they are simpler to integration in the dashboard.

WPS vs AP mode

Hi and thanks for this great integration, on my OpenWRT instance I don't have WPS so I hade to disable this part in the code:

        macs = dict()
        for key, value in response['clients'].items():
            macs[key] = dict(signal=value.get("signal"))
        #response = await self._ubus.api_call(
        #    f"hostapd.{interface_id}",
        #    'wps_status',    
        #    dict()
        #)                           
        return dict(
            clients=len(macs),
            macs=macs,  
            # wps=response["pbc_status"] == "Active"
        ) 

I just have normal AP clients cause running in AP mode, like:

ubus call hostapd.wlan1 get_clients
{
	"freq": 2462,
	"clients": {
		"xx:xx:xx:xx:xx:xx": {
			"auth": true,
			"assoc": true,
			"authorized": true,
			"preauth": false,
			"wds": false,
			"wmm": true,
			"ht": true,
			"vht": false,
			"wps": false,
			"mfp": false,
			"rrm": [
				0,
				0,
				0,
				0,
				0
			],
			"aid": 2,
			"bytes": {
				"rx": 148449402,
				"tx": 8522063
			},
			"airtime": {
				"rx": 0,
				"tx": 0
			},
			"packets": {
				"rx": 153853,
				"tx": 99111
			},
			"rate": {
				"rx": 72200,
				"tx": 72200
			},
			"signal": -55,
			"capabilities": {
				
			}
		}
	}
}

would be great if we could add support also for this use case, thanks;)

How to Create Sensors

Hi,

I am having some trouble creating Sensors.
I have followed the steps and I can see the below:
image

I would like to create sensors for different things such as system uptime, how many dhcp leases, public ip address, etc.
I've done a bit of research but haven't had much luck.

I was able to use the openwrt.reboot service to restart OpenWRT. Can I possibly parse the output from openwrt.exec command to a sensor?

Thanks!

Unable to communicate with router SSL error

Hi!

First seems like a great intergration! Would like to test this. But not able to complete the config. Did al the steps but getting a SSL error.

Logger: custom_components.openwrt.ubus
Source: custom_components/openwrt/ubus.py:92
Integration: OpenWrt (documentation, issues)
First occurred: 16:10:27 (2 occurrences)
Last logged: 16:10:47

api_call exception: HTTPSConnectionPool(host='192.168.1.1', port=443): Max retries exceeded with url: /ubus (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))

Logger: custom_components.openwrt.coordinator
Source: custom_components/openwrt/ubus.py:93
Integration: OpenWrt (documentation, issues)
First occurred: 16:10:27 (2 occurrences)
Last logged: 16:10:47

Device [Test] async_update_data error:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 703, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 386, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 1040, in validate_conn
conn.connect()
File "/usr/local/lib/python3.9/site-packages/urllib3/connection.py", line 414, in connect
self.sock = ssl_wrap_socket(
File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl
.py", line 453, in ssl_wrap_socket
ssl_sock = ssl_wrap_socket_impl(sock, context, tls_in_tls)
File "/usr/local/lib/python3.9/site-packages/urllib3/util/ssl
.py", line 495, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock)
File "/usr/local/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/local/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/local/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 440, in send
resp = conn.urlopen(
File "/usr/local/lib/python3.9/site-packages/urllib3/connectionpool.py", line 785, in urlopen
retries = retries.increment(
File "/usr/local/lib/python3.9/site-packages/urllib3/util/retry.py", line 592, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='192.168.1.1', port=443): Max retries exceeded with url: /ubus (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/config/custom_components/openwrt/ubus.py", line 90, in _api_call
response = await self.executor_job(post)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/openwrt/ubus.py", line 84, in post
return requests.post(
File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 117, in post
return request('post', url, data=data, json=json, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 529, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/sessions.py", line 645, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python3.9/site-packages/requests/adapters.py", line 517, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.1.1', port=443): Max retries exceeded with url: /ubus (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1129)')))

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/config/custom_components/openwrt/coordinator.py", line 243, in async_update_data
self._apis = await self.load_ubus()
File "/config/custom_components/openwrt/coordinator.py", line 232, in load_ubus
return await self._ubus.api_call("*", None, None, "list")
File "/config/custom_components/openwrt/ubus.py", line 44, in api_call
await self._login()
File "/config/custom_components/openwrt/ubus.py", line 48, in _login
result = await self._api_call(
File "/config/custom_components/openwrt/ubus.py", line 93, in _api_call
raise ConnectionError from err
ConnectionError

Logger: homeassistant.config_entries
Source: config_entries.py:370
First occurred: 16:10:47 (1 occurrences)
Last logged: 16:10:47

Config entry 'Test - 192.168.1.1' for openwrt integration not ready yet: OpenWrt communication error: ; Retrying in background

image

I don't use any certificate, no HTTPS. What am i doing wrong? Can u help :)?

Implement ubus system uptime sensor

I note the discussion around creating sensors here #9 , and also that commit aaddd2b implemented capture of the openwrt.exec service call stdout return on the event bus.

The resulting event from calling the /usr/bin/uptime command example from the readme is:

event_type: openwrt_exec_result
data:
  address: 192.168.1.1
  id: Ntgr-X4S-R7800
  command: /usr/bin/uptime
  code: 0
  stdout: |2
     09:50:44 up 3 days, 16:23,  load average: 0.21, 0.19, 0.16
origin: LOCAL
time_fired: "2023-08-18T23:50:44.891336+00:00"
context:
  id: 01H85GXXWV1VG59SAMTENB3HBH
  parent_id: null
  user_id: null

For those with a moderate amount of Home Assistant knowledge, it should therefore be possible to setup an automation to periodically call the openwrt.exec service (https://www.home-assistant.io/docs/automation/trigger/#time-pattern-trigger), and capture the output within a template trigger sensor (https://www.home-assistant.io/integrations/template/#trigger-based-template-binary-sensors-buttons-images-numbers-selects-and-sensors). I haven't tried it yet; capturing and reformatting the output looks a little tricky, but doable.

However I have confirmed that the terminal command ubus call system info | jsonfilter -e "@['uptime']" directly returns OpenWRT system uptime in seconds, and suggest that implementing this as a sensor within the integration is a more elegant and user friendly solution.

Thank you for your work on this in any case; it is already very useful in monitoring OpenWRT connectivity within Home Assistant.

OpenWrt 19.07.8 r11364-ef56c85848 - GL iNET GL-MT300N-V2 - async_update_data error: Expecting value: line 1 column 1 (char 0)

Hi @kvj,

Thank you for your integration. When trying to set it up I get the bellow error.
The device is GL iNET GL-MT300N-V2 running OpenWrt 19.07.8 r11364-ef56c85848.
Home Assistant 2023.1.2
Supervisor 2022.12.1

Thanks in advance for your help.

This error originated from a custom integration.

Logger: custom_components.openwrt.coordinator
Source: custom_components/openwrt/ubus.py:99
Integration: OpenWrt (documentation, issues)
First occurred: 10:37:02 (36 occurrences)
Last logged: 11:18:27

Device [Climate Control Bridge] async_update_data error: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/site-packages/simplejson/decoder.py", line 372, in decode
    obj, end = self.raw_decode(s)
  File "/usr/local/lib/python3.10/site-packages/simplejson/decoder.py", line 402, in raw_decode
    return self.scan_once(s, idx=_w(s, idx).end())
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/openwrt/coordinator.py", line 245, in async_update_data
    self._apis = await self.load_ubus()
  File "/config/custom_components/openwrt/coordinator.py", line 234, in load_ubus
    return await self._ubus.api_call("*", None, None, "list")
  File "/config/custom_components/openwrt/ubus.py", line 44, in api_call
    await self._login()
  File "/config/custom_components/openwrt/ubus.py", line 48, in _login
    result = await self._api_call(
  File "/config/custom_components/openwrt/ubus.py", line 99, in _api_call
    json_response = response.json()
  File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

openwrt 22.03 stable release Device [openwrt] async_update_data error: rpc error: 2

could not connect to openwrt 22.03

home assistant giving error:
Device [openwrt] async_update_data error: rpc error: 2

logs from home assistant:

This error originated from a custom integration.

Logger: custom_components.openwrt.coordinator
Source: custom_components/openwrt/ubus.py:121
Integration: OpenWrt (documentation, issues)
First occurred: 9:33:48 AM (23 occurrences)
Last logged: 9:59:08 AM

Device [openwrt] async_update_data error: rpc error: 2
Traceback (most recent call last):
File "/config/custom_components/openwrt/coordinator.py", line 250, in async_update_data
result["wan"] = await self.update_wan_info()
File "/config/custom_components/openwrt/coordinator.py", line 215, in update_wan_info
response = await self._ubus.api_call(
File "/config/custom_components/openwrt/ubus.py", line 41, in api_call
return await self._api_call(rpc_method, subsystem, method, params)
File "/config/custom_components/openwrt/ubus.py", line 121, in _api_call
raise ConnectionError(f"rpc error: {result[0]}")
ConnectionError: rpc error: 2

acces denied

hello

i have this error in home-assistant.log

2022-10-19 22:10:21.835 ERROR (MainThread) [custom_components.openwrt.ubus] api_call rpc error: {'code': -32002, 'message': 'Access denied'}

this command with my user and password return
curl -d '{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "hass", "password": "homeassistant" } ] }' http://192.168.0.254/ubus

{"jsonrpc":"2.0","id":1,"result":[0,{"ubus_rpc_session":"c95800fca267a2bf9d90c772ccfd458f","timeout":300,"expires":299,"acls":{"access-group":{"unauthenticated":["read"]},"ubus":{"luci":["getFeatures"],"session":["access","login"]}},"data":{"username":"hass"}}]}

on my openwt router

/etc/config/rpcd

`config rpcd
option socket /var/run/ubus/ubus.sock
option timeout 30

config login
option username 'root'
option password '$p$root'
list read ''
list write '
'

config login
option username 'hass'
option password '$p$hass'
list read hass
list read unauthenticated
list write hass`

the file hass.json in /usr/share/rpcd/acl.d/

{ "hass": { "description": "Home Assistant OpenWrt integration permissions", "read": { "ubus": { "network.wireless": ["status"], "network.device": ["status"], "iwinfo": ["info", "assoclist"], "hostapd.*": ["get_clients", "wps_status"], "system": ["board"], "mwan3": ["status"] }, }, "write": { "ubus": { "system": ["reboot"], "hostapd.*": ["wps_start", "wps_cancel"] "file": ["exec"] }, "file": { "/usr/bin/uptime": ["exec"] } }, } }

the result of command "ubus call session list"

{ "ubus_rpc_session": "c95800fca267a2bf9d90c772ccfd458f", "timeout": 300, "expires": 116, "acls": { "access-group": { "unauthenticated": [ "read" ] }, "ubus": { "luci": [ "getFeatures" ], "session": [ "access", "login" ] } }, "data": { "username": "hass" } }

many thanks for your help

Does not work when multiple wifi is on same radio.

`{
"radio0": {
"up": true,
"pending": false,
"autostart": true,
"disabled": false,
"retry_setup_failed": false,
"config": {
"path": "1e140000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0",
"channel": "1",
"band": "2g",
"htmode": "HT20",
"cell_density": 0
},
"interfaces": [
{
"section": "default_radio0",
"ifname": "wlan0",
"config": {
"mode": "ap",
"ssid": "OpenWrt",
"encryption": "none",
"macfilter": "deny",
"maclist": [
"abc"
],
"network": [
"lan"
],
"mode": "ap"
},
"vlans": [

                            ],
                            "stations": [

                            ]
                    },
                    {
                            "section": "wifinet3",
                            "ifname": "wlan0-1",
                            "config": {
                                    "mode": "ap",
                                    "ssid": "Iot Devices",
                                    "encryption": "sae",
                                    "hidden": true,
                                    "key": "xyz",
                                    "mode": "ap"
                            },
                            "vlans": [

                            ],
                            "stations": [

                            ]
                    }
            ]
    },
    "radio1": {
            "up": true,
            "pending": false,
            "autostart": true,
            "disabled": false,
            "retry_setup_failed": false,
            "config": {
                    "path": "1e140000.pcie/pci0000:00/0000:00:01.0/0000:02:00.0",
                    "channel": "36",
                    "band": "5g",
                    "htmode": "VHT80",
                    "cell_density": 0
            },
            "interfaces": [
                    {
                            "section": "default_radio1",
                            "ifname": "wlan1",
                            "config": {
                                    "mode": "ap",
                                    "ssid": "OpenWrt",
                                    "encryption": "none",
                                    "macfilter": "deny",
                                    "maclist": [
                                            "abc"
                                    ],
                                    "network": [
                                            "lan"
                                    ],
                                    "mode": "ap"
                            },
                            "vlans": [

                            ],
                            "stations": [

                            ]
                    }
            ]
    }

}`

It stucks at finding network in config.

help command restart service

Hello, I have a problem successfully restarting a service. I think my configuration is not good.
Besides, with the addition of the file lines I lose access. API error

hass.json

{
  "hass": {
    "description": "Home Assistant OpenWrt integraion permissions",
    "read": {
      "ubus": {
        "network.wireless": ["status"],
        "network.device": ["status"],
        "iwinfo": ["info", "assoclist"],
        "hostapd.*": ["get_clients", "wps_status"],
        "system": ["board"],
        "mwan3": ["status"]
      },
    },
    "write": {
      "ubus": {
        "system": ["reboot"],
        "hostapd.*": ["wps_start", "wps_cancel"]
		"file": ["exec"]
      },
      "file": {
        "/etc/init.d/presence-detector": ["exec"]
      }
    },
  }
}

command test homeassistant

service: openwrt.exec
data:
  command: service presence-detector restart
target:
  entity_id: binary_sensor.openwrt_wifiap_02

write features aren't working. unable to get reboot switch

I did everything as per your instructions and I am glad it works.
But the only reason I wanted to use this because I want a restart switch to reboot my openwrt router at a specific time.
and the problem is that it doesn't show any switch only shows 4 sensors
Screenshot 2023-03-27 at 11 55 19 PM
Screenshot 2023-03-28 at 12 00 58 AM
Screenshot 2023-03-28 at 12 01 25 AM

linksys wrt1900ac v2 OpenWrt communication error: 'ifname'

hi, firstly thank you for excellent plugin you've created, been using it for awhile on openwrt 19.07 without a problem. recently upgraded to by openwrt 21.02 and the error showed up.

device : Linksys WRT1900AC v2

on openwrt 19.07 it works fine.
on openwrt 21.02 it gives error.

might be caused by transition to DSA? it is giving error " OpenWrt communication error: 'ifname'"

checked the output from ubus, it indeed does not have ifname anymore.

any idea how to fix this?

Thanks

Issues when connecting to router

Using v0.1.0 of the custom integration, and OpenWRT v23.05.2

I've configured the router with ubus/uci and it was working for a while. I did find that creating a new user called hass didn't seem to 'take' on the router, so I've ended up using the root user/password for now (I know, I know). I did have the integration working and things were great - I was able to create some firewall rules and control the 'enabled' flag using commands through the service. However, usually when HASS is updated or restarted, the integration seems to lose connections, and even if I delete and re-add, I get errors in the log.

This is an example of the error once I recreate the integration:

This error originated from a custom integration.

Logger: custom_components.openwrt.ubus
Source: custom_components/openwrt/ubus.py:105
Integration: OpenWrt (documentation, issues)
First occurred: 21:19:46 (5 occurrences)
Last logged: 21:20:21

api_call rpc error: {'code': -32000, 'message': 'Object not found'}

along with this one:

This error originated from a custom integration.

Logger: custom_components.openwrt.coordinator
Source: custom_components/openwrt/coordinator.py:298
Integration: OpenWrt (documentation, issues)
First occurred: 21:19:46 (5 occurrences)
Last logged: 21:20:21

Device [HomeNetRouter] async_update_data error: Object not found
Traceback (most recent call last):
  File "/config/custom_components/openwrt/coordinator.py", line 298, in async_update_data
    result['wireless'] = await self.update_ap(wireless_config['ap'])
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openwrt/coordinator.py", line 225, in update_ap
    result[item['ifname']] = await self.update_hostapd_clients(item['ifname'])
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openwrt/coordinator.py", line 123, in update_hostapd_clients
    response = await self._ubus.api_call(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openwrt/ubus.py", line 41, in api_call
    return await self._api_call(rpc_method, subsystem, method, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openwrt/ubus.py", line 109, in _api_call
    raise NameError(message)
NameError: Object not found

It looks like it cannot find the ap entries in the interfaces ... but I wonder if the issue is that, for some reason, I have two mode keys:

image

Anyway - happy to set up some debugging if you have a guide on how to setup an integration with HASS for debugging :) Or I can just litter the code with logging statements if that would help ... I have some Python experience but am not an expert.

OpernWRT 19.07: "ifname" unknown ?

Error on setup: Setup erneut versuchen: OpenWrt communication error: 'ifname'

well, yes, that's right for 19.07 and newer:

root@c2600_2-OpenWrt:~# ifname
-ash: ifname: not found
root@c2600_2-OpenWrt:~#
root@c2600_2-OpenWrt:~# grep ifname /etc/config/*
/etc/config/network:    option ifname 'lo'
/etc/config/network:    option ifname 'bat0 eth0 eth0.2 eth1 eth1.1 lan6 wan6'
/etc/config/network:    option ifname '@wan'
/etc/config/network:#   option ifname '@lan'
/etc/config/network:        option ifname @lan
/etc/config/network:    option ifname 'eth0.3'
/etc/config/network:    option ifname 'eth1.3'
/etc/config/wireless:   option ifname 'mesh0'
/etc/config/wireless:   option ifname 'mesh1'

so, what's wrong?

Integration fails to (re-)connect if wifi is disabled

I regularly disable Wifi on some of my access points (via ubus). When HA restarts and Wifi is disabled the extension fails to reconnect those access points. I have to manually reenable Wifi to reconnect them.

Error:

Traceback (most recent call last):
  File "/config/custom_components/openwrt/coordinator.py", line 297, in async_update_data
    wireless_config = await self.discover_wireless()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/openwrt/coordinator.py", line 57, in discover_wireless
    conf = dict(ifname=iface['ifname'],
                       ~~~~~^^^^^^^^^^
KeyError: 'ifname'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.