0.19.0 Port forwarding
2023-02-05
→ GitHub change log ←
Requirements
- Minimum Home Assistant version bumped to
2023.2.0
Features
- Finished code optimization to fulfil most of the HA Core requirements
- Added Port forwarding features (feature request #136):
- Port forwarding binary sensor / switch for the feature status
- Service to set / remove port forwarding rules. Please follow the docs to find more YAML features than available via HA frontend.
- Added Media bridge mode (feature request #494):
- The mode supports all the features of the Access point, but creates device trackers only for devices connected via wire
Documentation
- Added new Port forwarding documentation
- Updated supported devices
Dependencies
- Bumped
asusrouter
library to0.20.0
Other changes
- Refactored all the integration code
Did you know?
- In 7 days (next Sunday), it would be exactly 1 year since the first version of the AsusRouter backend library was released. Celebrating soon
- There are already 723 active AsusRouter installations as per HA Analytics
- We already got 82 votes to add AsusRouter to HA Core
Support AsusRouter
- Do you want more features to be added to AsusRotuer? Some of the features require an additional testing device. You can help me in getting one → via Donate on Buy Me a Coffee service
Also:
- Spread the word about AsusRouter
- Star AsusRouter GitHub repository
I have an automation showing a notification when devices not in my whitelist reconnects. The notification includes IP, name, mac, connection_type and guest. Yesterday I suddenly got 3 notifications with ‘None’ as IP, ‘8C:86:1E:xx:xx:xx’ as name, ‘8C:86:1E:xx:xx:xx’ as MAC and guest as False.
This got me startled for many reasons:
- I can’t remember anyone using an Apple device on my network ever (Google says 8C:86:1E is Apple).
- It was not connected to my guest network. All my visitors use the guest network.
- Why did it say None instead of showing IP and MAC address both as name and MAC? It was also not long enough on my network for me to actually see it being connected in router web page. Even though it notified me 3 times within an hour.
So… any ideas?
Automation
alias: "Notify on reconnection to WiFi"
description: ""
trigger:
- platform: event
event_type: asusrouter_device_reconnected
- platform: event
event_type: asusrouter_device_connected
condition:
- condition: template
value_template: >-
{% set allowlist = state_attr("sensor.asusrouter_allowlist", "list") %}
{% set name = allowlist | selectattr('1', 'eq',
trigger.event.data.mac.upper()) | map(attribute='0') | list | first |
default(none) %}
{{ name is none }}
action:
- service: notify.persistent_notification
data_template:
message: >-
{{trigger.event.data.ip}} | {{trigger.event.data.name}} |
{{trigger.event.data.mac}} | {{trigger.event.data.connection_type}} | {%
if trigger.event.data.guest == True %} Guest: Yes {% else %} Guest: No
{% endif %}
title: A device has reconnected to WiFi
mode: queued
max: 100
Hey, @Quacked,
That’s strange, but here are a couple of things which I can explain from the AsusRouter point of view:
- When the user provides no name for a device and the device itself gives no name, the
name
has the same value asmac
- that is the feature of the library to avoid missing names and related issues. - Absence of the IP can be explained by the fact, the device did not really connect to the network - either did not provide the correct password or just did not finish auth process. This would explain why it only notified in AsusRouter but you did not actually see it in the connected devices list in the Web UI - that was hit and run only, not an actual connection.
Actually, if you live in some neighbourhood where your WiFi coverage extends your property, and your network is not hidden - that might happen - some devices like to scan available networks around in order to check whether they can be used before the user actually tries to connect.
I would say, that is the most convincing explanation. If the device would actually connect - it would obtain an IP address and would probably send its name - e.g. Apple sends at least iPhone/iPad and so as a generic name if not other set by the user.
But you might want to watch your network just in case.
Thank you. I assumed the event required an authenticated connection and not just an attempt of one. Is it possible to identify if it is actually able to connect so I can have a separate notification for that? I live in an apartment building and I guess there will be plenty of times where someone tries to login to my WiFi by mistake (I prefer not to hide SSID).
I saw a brief appearance of an unexpected MAC address recently. Discovered that it was for the wifi interface of a mesh node. Weird thing is that that node is connected to the main router by ethernet (wired) so I wouldn’t expect its wifi interface to try to connect to the main router.
@Quacked, actually it just notifies of any device, that the router has added to the list of connected. Why it does things in this way I don’t know. Actually, if you would be lucky, you would also see it in the Web UI - the source for data is the same as AsusRouter is using
You can update your automation to ignore devices without IP - that would avoid such cases as you had
Yes, AiMesh nodes are actually trying different connections from time to time. Especially if wired backhaul is 1 Gb/s and wireless can go faster
@Vaskivskyi thank you for all your work on the integration!
I’ve had it working for 2 days, and then after rebooting my Home Assistant, I’m now getting errors on this only:
Logger: homeassistant.config_entries
Source: custom_components/asusrouter/bridge.py:459
Integration: AsusRouter (documentation, issues)
First occurred: 7:18:53 PM (3 occurrences)
Last logged: 7:21:22 PM
Error setting up entry 192.168.1.1 for asusrouter
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 382, in async_setup
result = await component.async_setup_entry(hass, self)
File "/config/custom_components/asusrouter/__init__.py", line 26, in async_setup_entry
await router.setup()
File "/config/custom_components/asusrouter/router.py", line 748, in setup
await self._init_sensor_coordinators()
File "/config/custom_components/asusrouter/router.py", line 980, in _init_sensor_coordinators
available_sensors = await self.bridge.async_get_available_sensors()
File "/config/custom_components/asusrouter/bridge.py", line 241, in async_get_available_sensors
SENSORS: await self._get_sensors_ports(),
File "/config/custom_components/asusrouter/bridge.py", line 505, in _get_sensors_ports
return await self._get_sensors(
File "/config/custom_components/asusrouter/bridge.py", line 459, in _get_sensors
data = await method()
File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1223, in async_get_ports
return await self.async_get_data(
File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1120, in async_get_data
await self.async_monitor(_monitor)
File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 443, in async_monitor
result = process(raw, time=monitor.time)
File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 640, in _process_monitor_ethernet_ports
data = raw["portSpeed"]
KeyError: 'portSpeed'
Some assistant would be amazing.
Many thanks.
Hey, @hk21x,
It seems, that one of the API endpoints (the one reporting LAN/WAN ports status) is not responding. That happens with some devices. You can try rebooting your router and then reloading integration - it should work again
Of course, this is not a fix, but a shortcut. I will fix the code producing the error and it will be released in the next integration update (sometime this weekend)
I am sorry that you are experiencing this issue
Rebooted. You’re a superstar - thank you.
The latest features are amazing, the port forwarding service call is exactly what I have been looking for. I have tried it out and adding port forwarding rules works well, I even have a template value that will add the external port of my phone as it changes. One question though, I cant seem to get the remove service call to work. Are there specific values it requires, I tried using the exact same values in the “action: set” and just changed it to remove, I also tried just using the port forward name but the rule still remains. Any guidance would be appreciate.
service: asusrouter.port_forwarding
data:
action: set
ip: 192.168.1.XX
protocol: TCP
port: 8089
ip_external: "{{ states(\"sensor.XX_phone_public_ip_address\") }}"
port_external: "8089"
name: Auto SIP WS
service: asusrouter.port_forwarding
data:
action: remove
ip: 192.168.1.XX
protocol: TCP
port: 8089
ip_external: "{{ states(\"sensor.XX_phone_public_ip_address\") }}"
port_external: "8089"
name: Auto SIP WS
Hey, @vijaykbhatia,
In principle, it should work with just the following:
service: asusrouter.port_forwarding
data:
action: remove
ip: 192.168.1.XX
port_external: "8089"
protocol: TCP
→ this is the minimum required parameters for remove
Actually, if you have only a single rule for an IP address, you can use the remove_ip
action:
service: asusrouter.port_forwarding
data:
action: remove_ip
ip: 192.168.1.XX
→ this will remove all the rules for the selected IP.
P.S. The name value is not checked, since it is not actually required and is not a unique parameter of the port forwarding settings.
If it still does not work, please check the log for errors/warnings after calling the service. If needed, please open an issue on GitHub with the info about your device and the log
Thanks this worked a treat. I did find however there must be some rate limit as calling multiple changes through an automation would create problems. I just added a few second wait between service calls.
AsusRouter
Today is the first Birthday of the AsusRouter Python library. The first release was published on 12.02.2022. This was a long and quite productive journey and I hope that AsusRouter will continue growing further.
By the way, the AsusRouter library was downloaded more than 17K times in the last month! AsusRouter integration is currently installed in 754 HA instances reporting to Analytics.
Cheers!
0.20.0 Port Status
2023-02-12
→ GitHub change log ←
Deprecation warning
- Sensors
lan_speed
andwan_speed
are deprecated. They will be removed in version 0.22.0. Please, use the new sensorsport_status_lan
andport_status_wan
Features
- Added new Port status sensors (LAN -
port_status_lan
, USB -port_status_usb
, WAN -port_status_wan
), reporting more information on the physical ports connections. The feature is fully supported by FW version388.x
. With older versions, new sensors might reflect fewer data (mimicking deprecatedlan_speed
andwan_speed
sensors with the new format). More details on the new features
Bug fixes
- Fixed bug in the backend library causing errors when device API stops reporting some information (report #C471)
Documentation
- Updated supported devices
Dependencies
- Bumped
asusrouter
library to0.20.1
Other changes
- Improved code typing
- Sorted integration manifest to fulfil the latest HA requirements
Support AsusRouter
Monetary support:
- You can make a donation using the Buy Me a Coffee service
- Thinking of buying a new Asus router to use with AsusRouter integration? Check the compatibility list in our Docs. If you will use any of the Amazon Associate links, I might get a small (1-3%) bonus from Amazon (usage of the associate links does not change the price of the items for you)
Non-monetary support:
- Star AsusRouter repository
- Know a person with an Asus device using Home Assistant but not AsusRouter? Let them know, AsusRouter is cool and has lots of useful features
Our progress on the way to HA Core
We have already received 90 votes. Add your one. More votes we get, the more chance that HA developers will notice it and give a review to the PR in the HA Core repository, which is required to add AsusRouter into Core.
Congratulation(HBD) from Northern Europe, and huge thanks for your great work
EDIT: And cool to see the Lan-Ports, and USB-Port, thou as it’s states of a value in a list in attributes, im lost … i have no idea how to get there, ive’ tried with various attributes-cards … thou seems like one have to use a template-sensor, for showing those states … would be great if you have any good ideas/card tips for that
EDIT: Never mind, problem solved
Great integration !!
Got a problem using device_internet_access service after version 17.4.
Background:
- AX86U (fw 388.1) as main router aimesh with AC68P (fw 386.9) as node
- Configured AX86U as router, device_tracker, device control checked when set up integration
- Both devices showed in integration and device_tracker.my_laptop.
- my_laptop has been added to Parental Controls - Time Scheduling with no schedule, device_tracker.my_laptop enabled in integration.
service: asusrouter.device_internet_access
data:
entities:
- device_tracker.my_laptop
state: disable
In version 17.4, that worked.
Any version later than 17.4, I got this on screen:
Fail to call service asusrouter.device_internet_access. Unknown error.
and this in log:
This error originated from a custom integration.
Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/asusrouter/bridge.py:808
Integration: AsusRouter (documentation, issues)
First occurred: 11:33:25 AM (1 occurrences)
Last logged: 11:33:25 AM
websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'replace'
Traceback (most recent call last):
File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/script.py", line 451, in _async_step
await getattr(self, handler)()
File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/helpers/script.py", line 684, in _async_call_service_step
await service_task
File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/core.py", line 1787, in async_call
task.result()
File "/srv/homeassistant/lib/python3.10/site-packages/homeassistant/core.py", line 1824, in _execute_service
await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
File "/home/homeassistant/.homeassistant/custom_components/asusrouter/router.py", line 923, in async_service_device_internet_access
await self.bridge.async_parental_control(raw=service.data)
File "/home/homeassistant/.homeassistant/custom_components/asusrouter/bridge.py", line 808, in async_parental_control
return await self.api.async_set_parental_control_rules(
File "/srv/homeassistant/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1351, in async_set_parental_control_rules
return await self.async_apply_parental_control_rules(current_rules)
File "/srv/homeassistant/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 1297, in async_apply_parental_control_rules
request = compilers.parental_control(rules)
File "/srv/homeassistant/lib/python3.10/site-packages/asusrouter/util/compilers.py", line 144, in parental_control
timemaps += f"{data[rule].timemap.replace('<', '<')}>"
AttributeError: 'NoneType' object has no attribute 'replace'
If I downgrade back to 17.4, service works with no error.
Any help would be appreciated.
Sorry, I haven’t seen that you have updated your post with a question. I am only getting notifications on “new posts”. But I am glad, you found a solution
Sorry to hear that you are experiencing this issue. From the log, it seems like there is a problem in the backend library. Please allow me some time to localize and fix it.
I didn’t wanted you to bother bout this, on the 1st Birthday celebration … id figured you eventually would see it, but yes i found a perfect “solution” , am about to build a new overview/splash page of my network, where obvious The AsusRouter will have the main role
@Vaskivskyi Hi, and thank you for great integration!
Is there any way to determine the secondary WAN (USB modem) operation after failover?
I can try with IP, but I thought you might have some dedicated switch I was unable to find.