ANEL Net-PwrCtrl Binding for OH3

I have re-written the binding for ANEL Net-PwrCtrl devices (doc of old binding version).
It has already been requested here.

This is an early version which already works fine with my two test devices (HUT2 and HOME).
Please feel free to test it and give feedback: download it here.
It should be sufficient to drop the the jar-file into your addons-folder (maybe OH must be restarted).

All channels of the old version of the binding should be supported, but you have to re-configure them all.
If you have multiple devices, please make sure that each device has its own exclusive UDP ports assigned (preferrably >1024, e.g. 7701 / 7501, 7702 / 7502, etc).

If something does not work as expected, keep an eye on the log and maybe set the log level to DEBUG, e.g. in the console:
openhab> log:set DEBUG org.openhab.binding.anel

If you want to report or discuss an issue, please add related log entries to your post (maybe also your device and firmware version).
There are still some TODOs left:

  • Auto discovery :heavy_check_mark:
  • Documentation :heavy_check_mark:
  • Dimmers (no explicit support needed)

PR: [anel] Initial contribution of the Anel NET-PwrCtrl binding for OH3 by paphko · Pull Request #10952 · openhab/openhab-addons · GitHub

1 Like

Hi Patrick

I have downloaded and installed this new version and it works, thanks!

There are a lot of these warnings when I reboot openHAB. Most probably, while the binding is inizializing:

2021-06-09 10:35:59.455 [WARN ] [nding.anel.internal.AnelUdpConnector] - Unexpected error while listening on port 7701
java.net.SocketException: Socket closed
at java.net.PlainDatagramSocketImpl.receive0(Native Method) ~[?:?]
at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181) ~[?:?]
at java.net.DatagramSocket.receive(DatagramSocket.java:814) ~[?:?]
at org.openhab.binding.anel.internal.AnelUdpConnector.run(AnelUdpConnector.java:120) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]

Anel Power Hut FW7.1

BR
Michael

Strange… I’ve never seen this exception on thing initialization.
This exception should only happen when the thing is deactivated. And during thing shutdown, this warning should not be logged.

How many such warnings are logged during a single initialization phase?
Is the thing initialized once or does it go online and offline multiple times?
(a connection check to the device is currently performed once a minute)

Hi Patrick,

1000 thanks!!

I was able to add 3 HUT’s without any issues, except that I had to restart openhab each time before the new HUT would become online.

From 4th up to 8th HUT I tried to add, there are always max 3-4 HUT’s online. (and the rest gives ERROR:COM)
Even those that were OK before. (HUT 1-3)

17:18:36.082 [INFO ] [inding.anel.internal.AnelUdpConnector] - Anel NET-PwrCtrl listener started for: ‘192.168.5.246:7677’
17:18:36.098 [INFO ] [inding.anel.internal.AnelUdpConnector] - Anel NET-PwrCtrl listener started for: ‘192.168.5.245:7577’
17:18:38.149 [INFO ] [re.automation.internal.RuleEngineImpl] - Rule engine started.
17:18:42.089 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel6’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.246,user=admin,password=XXXX,udpSendPort=7675,udpReceiverPort=7677]
17:18:42.089 [INFO ] [inding.anel.internal.AnelUdpConnector] - Anel NET-PwrCtrl listener started for: ‘192.168.5.248:7877’
17:18:42.106 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel5’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.245,user=admin,password=XXXX,udpSendPort=7575,udpReceiverPort=7577]
17:18:42.122 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel8’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.248,user=admin,password=XXXX,udpSendPort=7875,udpReceiverPort=7877]
17:18:48.127 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel2’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.242,user=admin,password=XXXX,udpSendPort=7275,udpReceiverPort=7277]
17:18:48.143 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel6’ changed from OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.246,user=admin,password=XXXX,udpSendPort=7675,udpReceiverPort=7677] to ONLINE
17:18:48.156 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel7’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=net-control,user=admin,password=XXXX,udpSendPort=7775,udpReceiverPort=7777]
17:18:48.161 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel5’ changed from OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.245,user=admin,password=XXXX,udpSendPort=7575,udpReceiverPort=7577] to ONLINE
17:18:54.150 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel1’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.241,user=admin,password=XXXX,udpSendPort=7175,udpReceiverPort=7177]
17:18:54.167 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel4’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.244,user=admin,password=XXXX,udpSendPort=7475,udpReceiverPort=7477]
17:18:54.178 [INFO ] [inding.anel.internal.AnelUdpConnector] - Anel NET-PwrCtrl listener started for: ‘net-control:7777’
17:18:54.181 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel8’ changed from OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.248,user=admin,password=XXXX,udpSendPort=7875,udpReceiverPort=7877] to ONLINE
17:19:00.154 [INFO ] [inding.anel.internal.AnelUdpConnector] - Anel NET-PwrCtrl listener started for: ‘192.168.5.242:7277’
17:19:00.154 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel3’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=192.168.5.243,user=admin,password=XXXX,udpSendPort=7375,udpReceiverPort=7377]

For those offline I see:
17:30:54.360 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Sending message ‘wer da?’ to 192.168.5.241:7175
17:30:54.364 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Sending successful.
But no response …

When I disable the 3 HUT’s that are OK, 3 other HUT’s will become OK

eg HUT 1 now is OK:
17:35:34.332 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Sending message ‘wer da?’ to 192.168.5.241:7175
17:35:34.336 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Sending successful.

And the response is there:

17:35:34.338 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Received data: NET-PwrCtrl:NET-CONTROL 01 :192.168.5.241:255.255.255.0:192.168.5.1:0.4.163.18.5.33:Nr.1,1:Nr.2,1:Nr.3,1:Nr.4,1:Nr.5,1:Nr.6,0:Nr.7,0:Nr.8,0:0:80:IO-1,1,1:IO-2,1,1:IO-3,1,1:IO-4,1,1:IO-5,1,1:IO-6,1,1:IO-7,1,1:IO-8,1,1:25.5�C:NET-PWRCTRL_06.5:h:n:xor:

And the same again when I disable again those OK/Online … the last HUTs will become OK.

So all individual configs are ok. But looks like there’s an issue when there are more than 3 HUT’s enabled?

8x NET-PwrCtrl HUT Ver.: 6.5
Openhab 3.0.2

BR,
Peter

I have now deleted the thing and started from scratch, but still the same. I get hundreds (thousands?) of these warning when I start or restart openHAB:

2021-06-10 18:54:33.828 [WARN ] [nding.anel.internal.AnelUdpConnector] - Unexpected error while listening on port 7701
java.net.SocketException: Socket closed
at java.net.PlainDatagramSocketImpl.receive0(Native Method) ~[?:?]
at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181) ~[?:?]
at java.net.DatagramSocket.receive(DatagramSocket.java:814) ~[?:?]
at org.openhab.binding.anel.internal.AnelUdpConnector.run(AnelUdpConnector.java:120) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
2021-06-10 18:54:33.830 [WARN ] [nding.anel.internal.AnelUdpConnector] - Unexpected error while listening on port 7701
java.net.SocketException: Socket closed
at java.net.PlainDatagramSocketImpl.receive0(Native Method) ~[?:?]
at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181) ~[?:?]
at java.net.DatagramSocket.receive(DatagramSocket.java:814) ~[?:?]
at org.openhab.binding.anel.internal.AnelUdpConnector.run(AnelUdpConnector.java:120) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
2021-06-10 18:54:33.831 [WARN ] [nding.anel.internal.AnelUdpConnector] - Unexpected error while listening on port 7701
java.net.SocketException: Socket closed
at java.net.PlainDatagramSocketImpl.receive0(Native Method) ~[?:?]
at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181) ~[?:?]
at java.net.DatagramSocket.receive(DatagramSocket.java:814) ~[?:?]
at org.openhab.binding.anel.internal.AnelUdpConnector.run(AnelUdpConnector.java:120) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
2021-06-10 18:54:33.832 [WARN ] [nding.anel.internal.AnelUdpConnector] - Unexpected error while listening on port 7701
java.net.SocketException: Socket closed
at java.net.PlainDatagramSocketImpl.receive0(Native Method) ~[?:?]
at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:181) ~[?:?]
at java.net.DatagramSocket.receive(DatagramSocket.java:814) ~[?:?]
at org.openhab.binding.anel.internal.AnelUdpConnector.run(AnelUdpConnector.java:120) [bundleFile:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]

Nearly every millisecond :open_mouth:

BTW: openHAB 3.1.0 M5!

Update: It seems that it has nothing to do with “Inizializing”. The Warnings are somehow before that.

Indeed. I can observe a similar behavior. Although I managed to get 4 devices online, communication is not really stable:

For each thing, a listening thread is started on the specifed port (the old bindings does it as well), but after the 4th thing is online, some (if not all) listening threads are blocked. After disabling one of the things, the messages are processed again. This is really weired. It seems as if OH3 only allows a limited number of concurrent threads? I cannot image that this is the case…

The good thing: I can reproduce the issue and try to find a solution.
The bad thing: I won’t have time for the next couple of days to look into it :wink:

This can only happen if the binding fails to listen to the specified port.
The binding tries it over and over again without any delay because it assumes exclusive access to the port.
The only two reasons I could think of is that either (1) the port is already occupied by someone else.
Do you have multiple things configured for the same port which might interfer with each other?
Is another application communicating with the device?
Could you try to use a different port?
Or (2) that your system does not allow OH to listen on the port, maybe some kind of security issue.

I will add a check that multiple subsequent listening failures will log a complete stacktrace (which will hopefully contain the cause of the problem), and that the thing will stop its initialization - without a listening thread, communication is not really possible :wink:

And you say that the device come online anyway and then it works as expected?

Mmmhhh, the PowerHut is the only device I have in my network and openHAB is the only application that connects to it.

I have started again from scratch and with standard and different ports but without success. As soon as openHAB is up and running everything is working as expected. Thing is online and I can control the outputs.

What I have seen → All these warnings are generated even before the events.log is generated by openHAB. So it must be at the very beginning of the startup process of openHAB. As soon as events.log is there, the warnings also disappear.

Maybe these events are left-overs of the previous run and the ‘socket closed’ logs were created and logged during shutdown? I updated the logging code, so you may re-download the addon, shutdown OH3, clear log-file, and try again :slight_smile:

I managed to get 9 devices online :partying_face:

The solution was simple: don’t use the ExecutorService of the binding handler to spawn long-running listener threads. Instead, follow Kais advice and create a dedicated listener thread.

@pfisser please download again and try the new jar-file.

Hi Patrick,

Looks ok now :slight_smile:

After restart sometimes one (randomly) remains offline but after a min it will become online

11:47:45.359 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel7’ changed from UNKNOWN to OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=net-control,user=admin,password=XXXX,udpSendPort=7775,udpReceiverPort=7777]

11:48:34.220 [INFO ] [hab.event.ThingStatusInfoChangedEvent] - Thing ‘anel:advanced-firmware:anel7’ changed from OFFLINE (COMMUNICATION_ERROR): Device does not respond (check IP, ports, and network connection): AnelConfiguration[hostname=net-control,user=admin,password=XXXX,udpSendPort=7775,udpReceiverPort=7777] to ONLINE

Thanks!!

1 Like

Great!

Communication with Anel devices happens via UDP, which is a connection-less protocol. There is no need (and no way) to acknowledge that a message has been received. So maybe one of the status messages gets lost in the network traffic?!

As you have observed correctly, the devices come back online if they respond to the heartbeat status (once a minute).

Working now, thanks!

I have stopped openHAB service before and deleted the log files, therefore no left-overs from previous shutdown :wink:

With new version and “sudo openhab-cli clean-cache” no warnings anymore!

1 Like

When adding a new Relay item the status will remain NULL
Even after updates are received
13:53:45.669 [DEBUG] [inding.anel.internal.AnelUdpConnector] - Received data on port 7177: NET-PwrCtrl:NET-CONTROL 01 :192.168.5.241:255.255.255.0:192.168.5.1:0.4.163.18.5.33:Nr.1,1:Nr.2,1:Nr.3,1:Nr.4,1:Nr.5,1:Nr.6,0:Nr.7,0:Nr.8,0:0:80:IO-1,1,1:IO-2,1,1:IO-3,1,1:IO-4,1,1:IO-5,1,1:IO-6,1,1:IO-7,1,1:IO-8,1,1:25.4�C:NET-PWRCTRL_06.5:h:n:xor:

When using the switch status will become ON/OFF
Not sure if this is really an issue(?)

Humidity and Brightness sensor are working fine. (only feedback)
14:00:34.629 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Anel04_SensorHumidity’ changed from 31.2 to 31.5
14:00:34.633 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘Anel04_SensorBrightness’ changed from 0 to 7

Whats the right item configuration please?
Switch f1 { anel=“anel:advanced-firmware:anel1:r5#state”, autoupdate=“false” }
Switch f1 { anel=“anel:advanced-firmware:anel1:r5”, autoupdate=“false” }
Switch f1 { channel=“anel:advanced-firmware:anel1:r5#state”, autoupdate=“false” }
Switch f1 { anel=“anel:advanced-firmware:anel1:F1”, autoupdate=“false” }

The configuration should be:

Switch f1 { channel="anel:advanced-firmware:anel1:r5#state" }

I’m also new to OH3, I just learned about profiles. If I understand it correctly, the autoupdate="false" setting is now handled with profile “follow”. I think “default” should be fine, but at as I said: I’m still looking for the best way to store the device state internally inside the binding.

As soon as a command for a switching a relay / IO port is received by the Anel binding, the command is forwarded to the device. Whether or not the command succeeds depends on multiple things:

  • The relay must not be locked / IO port must be configured to ‘output’
  • The UDP message to the device must not get lost (UDP is a connection-less protocol)
  • The UDP status message from the deivce to OH must not get lost

(Only) after the status message is received by the Anel binding, it can reliably update the state.

The new version (uploaded today) remembers that a switch command has been sent to the device and when receiving the next status update, it updates the state, no matter whether the state actually changed or not. (In previous versions, the state update was only sent if the relay / IO state did change.)

Moreover, the device discovery service is implemented, so it should now discover your devices if they are within the following port ranges: 75/77, 750/770, 7500/7700, 7750/7770
If a device is found for a specific port, the subsequent port is also scanned, e.g. 7500/7700 → 7501/7701 → 7502/7702 → etc.

FYI, pull request submitted: [anel] Initial contribution of the Anel NET-PwrCtrl binding for OH3 by paphko · Pull Request #10952 · openhab/openhab-addons · GitHub

Here is the prelimiinary documentation of the binding: openhab2/bundles/org.openhab.binding.anel at anel · paphko/openhab2 · GitHub

I also updated the jar file. I mainly fixed device discovery, logging, and increased the version to 3.2.0 (the currently developed version).

1 Like

Works perfect for me with a Anel NET-PwrCtrl HOME.
Thanks a lot!

1 Like

FYI, the PR has been approved and the binding will be part of the openhab 3.2 release.

The only functional change compared to the pre-release is that on a network error during initialization, the binding retries 2 times to establish a connection to the device.

1 Like