Python plugin: Presence detection from wireless router

Python and python framework
EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 20 June 2018 23:35

This is the one:

Code: Select all

2018-06-20 23:28:07.991 Error: (WiFi Presence) 'onStart' failed 'AttributeError':'module 'Domoticz' has no attribute 'Status''.
It should be solved after updating to the latest (beta) version of Domoticz. The Domoticz.Status method is relatively new. The plugin framework is still in beta and under development, so things change rapidly.

EDIT
Fun fact: the plugin crashed because it tried to tell you how successful it was in finding the command and interfaces to use for detection ... using the Domoticz.Status to write to the log. :?
Looks like the ssh part is working fine.
Last edited by EscApe on Wednesday 20 June 2018 23:40, edited 1 time in total.

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Wednesday 20 June 2018 23:40

Cheers, it's working!
Thanks for the help :)

EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 20 June 2018 23:42

:D That's great! and you're welcome.

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Wednesday 20 June 2018 23:45

EDIT
Fun fact: the plugin crashed because it tried to tell you how successful it was in finding the command and interfaces to use for detection ... using the Domoticz.Status to write to the log. :?
ROFL

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Thursday 21 June 2018 21:22

Does the script supposed to work with an access point?

EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Friday 22 June 2018 10:35

The plugin could theoretically work with accespoints. It depends on you accespoint though. If the accespoint supports ssh access you should configure the acces point as the 'router ip' for the plugin, so it can directly query the wireless chipset on the accespoint. If not, you can query the mac information the (real) router has in its bridge. That list should include all mac addresses in your local network. To do so add '#forcegeneric' behind the router ip address you configured for the plugin (see instructions and previous messages in this forum thread).

Querying the wireless chipset will give you the quickest and most reliable response to present/absent changes.
Querying the mac address list on the router bridge is also quick te respond to presence but can take a few minutes for absence (people leaving).

derjoern
Posts: 5
Joined: Sunday 13 August 2017 11:40
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by derjoern » Saturday 23 June 2018 15:11

Very good plugin. Works great on my D-Link with LEDE/OpenWrt 17.01 configured as access-point. Sadly I have also a Fritzbox which provides wlan to the front of my house while the D-Link is for the back and garden. Any plans for support of multiple routers?

To make it a bit difficult the Fritzbox does not support any of the present methods. I could put the presence on mqtt to read it from there. Smart home a is giant field of things that doesnt work together ...

EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Saturday 23 June 2018 22:08

Hi derjoern,

Thanks!
I only know the Fritzbox by name and nothing of its command line capabilities. If you can figure out a way to get a mac address list from it, then it can probably be incorporated into the plugin. I have no plans to interface with mqtt or anything other than the router itself. But there are (theoretical) options...

Lets say your D-Link is router A and the Fritzbox router B
You could make the plugin work on A and use another way to get a general Anyone-home kind of status from B to toggle the 'Override button' of A. That way you would at least have only one 'Anyone home' status to monitor for automation tasks.

This might also be the way to use multiple routers (have not tried is). Just add the plugin twice. Once for A and once for B. The anyone home of B could again control the override of A. In case of your Fritzbox we would first have to figure out a way to get the maclist from the router. Does the fritzbox offer ssh? If it is linux/busybox based i would expect it to at least support the brctl or arp method.

bkram
Posts: 1
Joined: Wednesday 27 June 2018 11:16
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Python plugin: Presence detection from wireless router

Post by bkram » Wednesday 27 June 2018 11:28

Hi,

Thanks for the plugin, I am using it with an Ziggo TP-Link Arcer C7 running Lede.

A request for the "Anyone" feature, I would like to blacklist some Wifi devices which are always online, so I can detect if there are any 'Guests' in the house.

Regards

bkram

Prutsium
Posts: 70
Joined: Monday 18 June 2018 11:31
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Germany / Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Prutsium » Wednesday 27 June 2018 13:18

derjoern wrote:
Saturday 23 June 2018 15:11
Very good plugin. Works great on my D-Link with LEDE/OpenWrt 17.01 configured as access-point. Sadly I have also a Fritzbox which provides wlan to the front of my house while the D-Link is for the back and garden. Any plans for support of multiple routers?

To make it a bit difficult the Fritzbox does not support any of the present methods. I could put the presence on mqtt to read it from there. Smart home a is giant field of things that doesnt work together ...
I assume 1 of the routers is the main router and the other one is connected to the LAN port of the 1st router right?
In that case you run the script on the first one and let the first one also handle all DHCP requests.
You put the plugin with #forcegeneric and it will read also the adresses used by LAN ports.

I have a simular setup with 2 routers where 1 is the Asus and the other a crappy Dlink and i see any client from any router.

EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 27 June 2018 13:27

Hi bkram,

Maybe you can already achieve what you want by adding the plugin twice? Once for devices that are always connected and one for devices that you want to monitor for presence. See previous post (just above yours) for an explanation on how this could work.

I have never tried adding the plugin twice, but it should work. You will of course have twice as many queries on the router, so i would set the poll interval a bit higher.

Could you let me (us) know if adding it twice works and serves your needs?

Monitoring devices that are always connected is not the purpose of this plugin.

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Wednesday 27 June 2018 15:53

I have an AP after my main router.
When I add '# forcegeneric' behind my main router adress I get this:

Code: Select all

2018-06-27 15:51:12.976 Error: (WiFi Presence) No usable commandline to check presence. Trying again to detect router capabilities.
2018-06-27 15:51:12.976 Error: (WiFi Presence) If you keep getting this message: check your (authentication) settings and router status.
2018-06-27 15:51:12.976 Error: (WiFi Presence) Make sure your router supports ssh and the commands used by this plugin. If this message persists disable the plugin (for now), or the plugin might flood the Domoticz eventsystem
2018-06-27 15:51:13.052 (WiFi Presence) Returncode ssh command: 255
2018-06-27 15:51:13.052 (WiFi Presence) Output from router: b''
2018-06-27 15:51:13.053 Error: (WiFi Presence) Router command failed with returncode: 255
2018-06-27 15:51:13.053 Error: (WiFi Presence) Raw data from router: b''
2018-06-27 15:51:13.053 Error: (WiFi Presence) Could not determine router capabilities


EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 27 June 2018 16:36

There should not be a space in #forcegeneric (although i think that would be handled by the plugin.. not sure)
It looks like the entire ssh connection subprocess is failing. Can you enable debug mode en share the log from where the plugin starts up?

Did the plugin work without errors before you added #forcegeneric?

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Wednesday 27 June 2018 18:55

Fixed the 'space' after #
The plugin worked without errors before adding '#forcegeneric'

Code: Select all

2018-06-27 18:09:35.790 Error: (WiFi Presence) Raw data from router: b''
2018-06-27 18:09:35.790 Error: (WiFi Presence) Could not determine router capabilities
2018-06-27 18:09:45.208 (WiFi Presence) Pushing 'onHeartbeatCallback' on to queue
2018-06-27 18:09:45.256 (WiFi Presence) Processing 'onHeartbeatCallback' message
2018-06-27 18:09:45.256 (WiFi Presence) Calling message handler 'onHeartbeat'.
2018-06-27 18:09:45.257 (WiFi Presence) devid2domid: {'phone1': 2, 'phone2': 3}
2018-06-27 18:09:45.257 (WiFi Presence) Checking router capabilities and wireless interfaces
2018-06-27 18:09:45.257 (WiFi Presence) Using password instead of ssh public key authentication (less secure!)
2018-06-27 18:09:45.257 (WiFi Presence) Fetching data from router using ssh
2018-06-27 18:09:45.257 (WiFi Presence) command: ['sshpass', '-p', '<PASS>', 'ssh', '-o', 'StrictHostKeyChecking=no', '-o', 'ConnectTimeout=2', 'admin@192.168.3.1#forcegeneric', '#!/bin/sh\n\t\t\t\t\texport PATH=/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:$PATH\n\t\t\t\t\ttest=$(which wl > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wl@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wl -i $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which iwinfo > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "iwinfo@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(iwinfo $iface assoclist > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\ttest=$(which wlanconfig > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "wlanconfig@"\n\t\t\t\t\t\t\tfor iface in $(ifconfig | cut -d \' \' -f1| tr \':\' \'\n\' | grep \'^eth\\|^wlan\\|^ath\')\n\t\t\t\t\t\t\tdo\n\t\t\t\t\t\t\t\t\ttest=$(wlanconfig $iface list > /dev/null 2>&1)\n\t\t\t\t\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\t\t\t\t\tprintf "$iface "\n\t\t\t\t\t\t\t\t\tfi\n\t\t\t\t\t\t\tdone\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\ttest=$(which arp > /dev/null 2>&1)\n\t\t\t\t\tif [ $? == 0 ]; then\n\t\t\t\t\t\t\tprintf "arp"\n\t\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tif [ -f /proc/net/arp ]; then\n\t\t\t\t\t\tprintf "procarp"\n\t\t\t\t\t\texit\n\t\t\t\t\tfi\n\t\t\t\t\tprintf none']
2018-06-27 18:09:45.335 (WiFi Presence) Returncode ssh command: 255
2018-06-27 18:09:45.335 (WiFi Presence) Output from router: b''
2018-06-27 18:09:45.257 Error: (WiFi Presence) No usable commandline to check presence. Trying again to detect router capabilities.
2018-06-27 18:09:45.257 Error: (WiFi Presence) If you keep getting this message: check your (authentication) settings and router status.
2018-06-27 18:09:45.257 Error: (WiFi Presence) Make sure your router supports ssh and the commands used by this plugin. If this message persists disable the plugin (for now), or the plugin might flood the Domoticz eventsystem
2018-06-27 18:09:45.335 Error: (WiFi Presence) Router command failed with returncode: 255
2018-06-27 18:09:45.335 Error: (WiFi Presence) Raw data from router: b''
2018-06-27 18:09:45.336 Error: (WiFi Presence) Could not determine router capabilities
2018-06-27 18:09:55.209 (WiFi Presence) Pushing 'onHeartbeatCallback' on to queue
2018-06-27 18:09:55.252 (WiFi Presence) Processing 'onHeartbeatCallback' message
2018-06-27 18:09:55.253 (WiFi Presence) Calling message handler 'onHeartbeat'.


EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 27 June 2018 19:49

Please update to the latest version. The #forcegeneric option is new and older version of the plugin will treat it as part of the router address (there's no router called 192.168.3.1#forcegeneric, so the plugin fails).

derjoern
Posts: 5
Joined: Sunday 13 August 2017 11:40
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by derjoern » Wednesday 27 June 2018 19:52

Prutsium wrote:
Wednesday 27 June 2018 13:18
I assume 1 of the routers is the main router and the other one is connected to the LAN port of the 1st router right?
In that case you run the script on the first one and let the first one also handle all DHCP requests.
You put the plugin with #forcegeneric and it will read also the adresses used by LAN ports.
I have such setup sadly my first router has no ssh. I could throw the stock firmware away, but that is no route I'm willing to go.

Regards Joern

derjoern
Posts: 5
Joined: Sunday 13 August 2017 11:40
Target OS: Linux
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by derjoern » Wednesday 27 June 2018 19:58

Thank you for your feedback.
EscApe wrote:
Saturday 23 June 2018 22:08
Lets say your D-Link is router A and the Fritzbox router B
You could make the plugin work on A and use another way to get a general Anyone-home kind of status from B to toggle the 'Override button' of A. That way you would at least have only one 'Anyone home' status to monitor for automation tasks.
My plan is to use the Domoticz JSON-Api to trigger the switches from node-red. I don't if this will cause havok, because your plugin will turn it off and node-red on. I will see.

EscApe
Posts: 223
Joined: Thursday 02 April 2015 8:46
Target OS: Raspberry Pi
Domoticz version: v3+beta
Location: The Netherlands
Contact:

Re: Python plugin: Presence detection from wireless router

Post by EscApe » Wednesday 27 June 2018 20:09

Hi derjoern,

Ik you set the override button mode to 'indefinitely' you can have full control over that button from another script or through the domoticz api. That is one of the use cases for the override.
Just don't try to control the Anyone-home or other devices directly.

drwurn
Posts: 42
Joined: Sunday 10 June 2018 16:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Presence detection from wireless router

Post by drwurn » Thursday 28 June 2018 21:38

EscApe wrote:
Wednesday 27 June 2018 19:49
Please update to the latest version. The #forcegeneric option is new and older version of the plugin will treat it as part of the router address (there's no router called 192.168.3.1#forcegeneric, so the plugin fails).
Just updated the plugin and it works good. Thanks!

User avatar
Innovator
Posts: 15
Joined: Tuesday 20 February 2018 13:33
Target OS: NAS (Synology & others)
Domoticz version: 8924
Location: Amsterdam
Contact:

Re: Python plugin: Presence detection from wireless router

Post by Innovator » Friday 29 June 2018 20:36

Today again time. Was bothering me why it did not work.
My router AC828 unfortunately does not support WL etc. commands. only ARP.
What I at least format from the debug log is that not the arp but the wl command is invoked.
I have manually changed the method to "arp" and it works again.

So I think that something is wrong in calling when checking the environment in python.
But unfortunately I am not a python programmer, but I wanted to let you know @escape.
Synology DS918+ /DS412+
ASUS BRT-AC828, RT-AC86U, RT-AC68U

Post Reply

Who is online

Users browsing this forum: jakkes72 and 2 guests