jheling / freeathome

Free@Home component for Home Assistant
112 stars 41 forks source link

free@home Binary Sensor units are not recongized in HA #37

Closed SuperMaximus1984 closed 2 years ago

SuperMaximus1984 commented 4 years ago

Hi jheling! Thanks for your efforts on creation of F@H module for HA. I have FW 2.4.0 and almost all Actuators/Sensors discovered (modified pfreeathome.py with IDs of my devices that have been discovered by Openhab), however I am missing several important modules. Here are Binary sensor modules with 4 input channels each: ABB265232951 (KTQ) ABB240232951 (PEH) and partial problems with 8/8 Actuator / Binary input unit (ABB26B703051 (ZWX)): Here Actuator outputs are discovered, though Input channels are not discovered. 8/8 Actuator/Binary Input unit code is "B008", I tried inputting it as Sensor/Acutator in configuration file, also attempted adding it as Binary Sensor unit, but no result. I have some devices discovered in HA that seem to be correct, but they are always in OFF state. Besides, all important Binary sensors are connected to ABB265232951 (KTQ) ABB240232951 (PEH) that are not discovered at all.

I was unable to run "get-master-message.py", was getting error

D:>python get-master-message.py Traceback (most recent call last): File "get-master-message.py", line 26, in from fah.messagereader import MessageReader ModuleNotFoundError: No module named 'fah'

Please help to sort things out and get Binary sensor modules working. Thank you a lot!

SuperMaximus1984 commented 4 years ago

UPD: 8/8 Actuator / Binary unit is discovered, but because it was input as Sensor/Actuator in .PY config file and I found out INPUTs were also discovered, but as Switches. Surely they don't work as Binary Switches and it's frustrating. How can I divide one device into 2: Acutator & Binary Sensor? image

jheling commented 4 years ago

If you want to run the get-master-message.py you have to place the full freeathome directory somewhere on your computer and then run get-master-message.py within that directory. I use idle (python 3.7) on windows 10 for running get-master-message.py

I know the binary sensors are not working. I have allready made some modifications. I'll try to upload them this week.

Did you add new device_id's to your pfreeathome.py? Can you share them? Other users could also benefit from them.

SuperMaximus1984 commented 4 years ago

Sorry, but I did not manage to get "get-master-message.py" working even if I execute it from freeathome directory with original file structure. Firstly there was absent lib, I installed it, then one more error again.

D:\freeathome>python get-master-message.py

Traceback (most recent call last): File "get-master-message.py", line 27, in from fah.saslhandler import SaslHandler File "D:\freeathome\fah\saslhandler.py", line 7, in from .crypto import Crypto, loginSaslPayload, buildSaslResponse File "D:\freeathome\fah\crypto.py", line 3, in import libnacl ModuleNotFoundError: No module named 'libnacl'

D:\freeathome>pip install libnacl Collecting libnacl Downloading libnacl-1.7.1-py2.py3-none-any.whl (20 kB) Installing collected packages: libnacl Successfully installed libnacl-1.7.1

D:\freeathome>python get-master-message.py Traceback (most recent call last): File "get-master-message.py", line 27, in from fah.saslhandler import SaslHandler File "D:\freeathome\fah\saslhandler.py", line 7, in from .crypto import Crypto, loginSaslPayload, buildSaslResponse File "D:\freeathome\fah\crypto.py", line 3, in import libnacl File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\libnacl__init.py", line 85, in nacl = _get_nacl() File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\libnacl\init__.py", line 34, in _get_nacl raise OSError(msg) OSError: Could not locate nacl lib, searched for libsodium

D:\freeathome>

Yes, I added those device codes that were discovered by Openhab, I modified your code with my device codes and here it is:

                 # Switch actuators

if (device_id == 'B002' or device_id == '100E' or device_id == 'B008' or device_id == '900D' or device_id == '9011' or device_id == '4000' or device_id == '4001' or device_id == '100C' or device_id == '1010'): self.add_light_device(neighbor, serialnumber, roomnames)

            # Dimming actuators
            # Hue Aktor (LED Strip), Sensor/dimaktor 1/1-voudig
            if (device_id == '101C' or device_id == '1021' or
                    device_id == '1014' or device_id == '901c' or
                    device_id == '9018' or device_id == '9019' or
                    device_id == '10C0' or device_id == '1017' or
                    device_id == '1019'):
                self.add_dimmer_device(neighbor, serialnumber, roomnames)

            # Scene or Timer
            if device_id == '4800' or device_id == '4A00':
                self.add_scene(neighbor, serialnumber, roomnames)

            # blind/cover device
            if device_id == 'B001' or device_id == '1013' or device_id == '1015' or \
                    device_id == '9014' or device_id == '9015':
                self.add_cover_device(neighbor, serialnumber, roomnames)

            # Sensor units 1/2 way
            if device_id == '1002' or device_id == '1000' or device_id == '100C' or \
                device_id == '1019' or device_id == '1017' :
                self.add_sensor_unit(neighbor, serialnumber, roomnames, device_id)

            # binary sensor
            if device_id == 'B007':
                self.add_binary_sensor(neighbor, serialnumber, roomnames)

            # movement detector
            if device_id == '100A' or device_id == '9008' or device_id == '900B':
                self.add_movement_detector(neighbor, serialnumber, roomnames)

            # thermostat
            if device_id == '9005' or device_id == '2041':
                self.add_thermostat(neighbor, serialnumber, roomnames)

For your convenience I add up codes below. Binary sensor units were not recognized even by Openhab f@h module, so I just manually assigned "B007", though it's not discoverable. So still I hope I could run get-master-message.py and find out exact codes/IDs.

Binary input B007 Blind actuator sensor 1/1 9001 9014 Heating actuator 6gang B003 Movement detector 9009 900B Room temperature Controller 9005 Room temperature Controller Wireless 2041 Sensor unit 1gang 9001 Sensor unit 2gang 9003 Sensor/dimming actuator 9018 Sensor/switch actuator B008 Switch actuator sensor 1/1 900D Switch actuator sensor 2/2 9011 SysAP 1012 SysAP communication interface 2012

SuperMaximus1984 commented 4 years ago

After I installed libsodium, I got the following while running get-master-message.py

D:\freeathome>python get-master-message.py INFO 2.4.0 10000 OuCskclpfkoPmW7fdpXf9tdBCUnoy4LjquEXy1M24pQ= INFO version: 2.4.0 From cffi callback <function _sock_state_cb at 0x000002779F2B1C10>: Traceback (most recent call last): File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\pycares__init.py", line 91, in _sock_state_cb sock_state_cb(socket_fd, readable, writable) File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\site-packages\aiodns\init__.py", line 104, in _sock_state_cb self.loop.add_reader(fd, self._handle_event, fd, READ) File "C:\Users\Max\AppData\Local\Programs\Python\Python38\lib\asyncio\events.py", line 501, in add_reader raise NotImplementedError NotImplementedError

jheling commented 4 years ago

There is also a libsodium.dll which should be installed in the Windows\SysWOW64 or Windows\System32. This dll does all the crypto computations. The name of this dll should be libsodium.dll.

SuperMaximus1984 commented 4 years ago

Yes, I copied this DLL to both directories and keep on getting this error in my previous message...

jheling commented 4 years ago

This error is new to me. Maybe install packaging with pip?

SuperMaximus1984 commented 4 years ago

Yes, I did "pip install packaging" in the beginning. You see it displays SysAP 2.4.0, but then fall back into some error when addresses to events.py.

Do I really need to run get-master-message.py in my case if you plan to implement Binary sensors in the nearest release? Thank you!

jheling commented 4 years ago

No, it is not necessery. The error seems to be releated to python 3.8. In version 3.8 asyncio uses a new event loop. https://stackoverflow.com/questions/58422817/jupyter-notebook-with-python-3-8-notimplementederror. Reverting to 3.7 or patching a file in asyncio seems to be the solution.

SuperMaximus1984 commented 4 years ago

Thanks! It worked! As it was supposed my 4-channel Binary Input modules are having code "B007" and occasionally they were added to Objects list when I put "B007" in Switch/Actuator section, though they were not operational. Now B007 code is in right place (Binary Sensor), so I guess devices can be normally detected as soon as you release the update, right?

jheling commented 4 years ago

I have just updated the repository. The B007 device is added to the list of binary devices.

SuperMaximus1984 commented 4 years ago

Thank you! What files should I replace in my current version?

jheling commented 4 years ago

binary_sensor.py and pfreeathome.py.

SuperMaximus1984 commented 4 years ago

Thank you so much & big respect to you! It DOES work! Binary Sensor units are discoverable and operable.

Do you have an idea how I can make my B008 (which is a combined unit 8/8 Actuator/Binary sensor) discoverable not only as Actuator, but also as Binary module so that I could program HA actions based on inputs either? Is it OK to add B008 to both sections of pfreeathome.py (Sensors and at the same time to Binary inputs)?

SuperMaximus1984 commented 4 years ago

@jheling Dear Author, please clarify how to make B008 Sensor/ Schaltaktor 8/8fach, REG recognized by HA either like Actuator (now working like this) and Binary Input? Unfortunately, when I input Binary Input 'B008' alongside with 'B008' as Sensor/Actuator, compenent stops working. Now as Actuator inputs are recognized like Switches, and surely are not operable. Thank you in advance!

image

jheling commented 4 years ago

In the current solution a device / channel combination cannot function as a binary input and as a actuator. The software has evolved in a certain way and it is now not possible to combine both. I the future it could be possible, but it would take more changes in the software.

SuperMaximus1984 commented 4 years ago

@jheling Would you please advise when will it be possible to combine binary input + actuator device and see all inputs/outputs in HA? Pretty much needed feature... Thanks a lot!

Cavekeeper commented 3 years ago

@jheling I have a problem due to 4x binary input sensor. The binary sensor are recognized by HA, but not reacting. The signal is always "high" although the input is configured as a normally open contact. A motion detector is connected to this. However, HA is not doing. The input always remains on "high". In BJ FAH V2.5.5 the motion detector is working well and reacts to a simple action rule. But now I want also to have this motion detector via binary input inside of HA.

Bildschirmfoto 2020-10-23 um 15 09 01

Now I've also tried other normal switches. These are displayed in HA as "low" and then also react when the switch is pressed.

Bildschirmfoto 2020-10-23 um 15 25 38

Generally the binary switches seem to work. Only the 4-way binary input does not work in HA. Where could be the problem?

RPI 3B+ | HassOS 4.15 | HA 0.116.4 | FAH V2.5.5 | last version of FAH component

jheling commented 3 years ago

Can you try to run get-master-message.py ? The messages above tell you how to do that. With the mastermessage.xml I can see the configuration of the binary sensors. Maybe something has changed in the 2.5.5 sysap and is the software looking at the wrong output datapoint.

Cavekeeper commented 3 years ago

Yes, here is the message:

Thomass-MBP:freeathome tlintzhoeft$ python3 get-master-message.py Traceback (most recent call last): File "/Users/tlintzhoeft/Downloads/freeathome/get-master-message.py", line 10, in <module> import slixmpp ModuleNotFoundError: No module named 'slixmpp'

jheling commented 3 years ago

This get-master-message.py generates a mastermessage.xml and that is where I'm interested in. This is a python error. You have to install the slixmpp library and probably the libnacl library: pip install slixmpp pip install libnacl

Cavekeeper commented 3 years ago

I also noticed the following. If I reconfigure the binary channel in BJ FAH, it is marked as OFF in HA. Then when the first trigger comes, the channel in HA goes ON and stays ON. It does not go OFF when the trigger is no longer present. That means in principle the trigger arrives in HA. It's ON. It just doesn't go back to OFF when the trigger drops.

jheling commented 3 years ago

Maybe there is something wrong in the message comming from FAH.
Could you turn the logging of HA to info? logger: default: info Then restart HA and activate one of the movement detectors connnected to your binary sensor. The initial value and actions should now appear in the HA logging.

Cavekeeper commented 3 years ago

I think I got a little closer to the problem. If I configure the digital input in FAH as a switch, then the channel in HA goes ON and OFF with every trigger. If I configure the digital input in FAH as a motion detector, then the channel in HA goes ON with the first trigger and remains there. This is what it says in the LOG. When configured as a switch, the channel changes from 0 to 1 and vice versa with each trigger. When configured as a BWM, the channel remains at 1 with the first trigger. I now believe that there must be a problem in the freeathome custom components after all.

miezie commented 3 years ago

Maybe wait for this one from @Tho85 and then be happy :)

jheling commented 3 years ago

Can you share the logging of the testcases? Maybe there is something wrong with the messages coming from the sysap

Cavekeeper commented 3 years ago

Ok, this is the log by using the motion detector:

2020-10-24 13:17:47 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x6e61b500> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:17:47 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1 2020-10-24 13:17:49 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x690e71e0> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:17:49 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1 2020-10-24 13:17:53 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x665f62f8> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:17:53 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1 2020-10-24 13:17:54 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x690e7230> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:17:54 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1 2020-10-24 13:17:58 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x66691780> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:17:58 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1 2020-10-24 13:18:00 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x6daef8c0> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:18:00 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 1

And this is log after removing the motion detector:

2020-10-24 13:21:11 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary info channel <Element 'channel' at 0x66ddbc08> device ABB2F2B11551/ch0002 in/output odp000D 2020-10-24 13:21:11 INFO (MainThread) [custom_components.freeathome.pfreeathome] binary device ABB2F2B11551/ch0002 output odp000D is 0

jheling commented 3 years ago

The custom_domponent is following the messages from the sysap. If the movement detector mode is active is only receiving on messages and is acting after that. I see that the movement sensor also has a parameter: Nopen and Nclose. Maybe you should change this parameter. Or is the binary channel connected to a switch? Then you have the parameter "Switch-off delay" which can get in your way.

Cavekeeper commented 3 years ago

That's right, the motion detector and the digital input are configured as normally open contacts. On the BJ side, this button also works perfectly. You are right, the signal also arrives in HA. It just doesn't drop out again when the motion detector no longer registers any movement. This means that the binary input in HA must receive an automatic reset and go to 0. The only problem is that there is no service in HA to change the status of a binary input.

Tho85 commented 3 years ago

During my work in #73 I just tested a binary sensor 2-gang configured as a motion detector. I can confirm that the sensor detects the "on" signal, but then remains there. According to my debug logs, this is actually a limitation of free@home. The system never sends an "off" signal for movement detectors. BTW, I observe the same behaviour when I configure the input as "timed start/stop", i.e. staircase light sensor.

Another hint this is an issue with free@home is in the free@home UI itself. When you first configure a binary sensor as a movement detector, drop it onto the floor plan, connect it to a light and trigger a movement, then you should see the detector blinking shortly on the floor plan (this works for all binary sensors). But it does so only once, immediately after initial configuration. It then never lights up again when movement stops, or when movement is triggered a second time. Just the same as observed with Home Assistant.

TL;DR: It's most likely a free@home issue.

miezie commented 3 years ago

Is it an issue? You can just observe the lux value of the detector... it toggles based on movement and that value. You can still check if the specific light (or whatever) is on.

Actually depending on on/off state of a binary switch might also be weird because it simulates a switch. But it could also be just one button with a state toggle every time when you press it.

Tho85 commented 3 years ago

@miezie This works for dedicated in-wall movement detectors, because they have a brightness sensor included. The issue is with generic binary sensors like this one, where you essentially connect an external movement detector to a generic input and configure it as a movement detector in F@H. They do not offer a brightness sensor.

Actually depending on on/off state of a binary switch might also be weird because it simulates a switch. But it could also be just one button with a state toggle every time when you press it.

Yes, relying on the internal state of the binary sensor is flawed, even if you configure it as a toggle. The state will eventually mismatch if you change the state of the attached light in HA. I think the best solution if you want to trigger something in HA from a F@H binary sensor is to expose the HA entity via emulated_hue, e.g. as a light bulb. This way the state tracking in F@H is always correct.

Cavekeeper commented 3 years ago

@Tho85 Could you please more explain

I think the best solution if you want to trigger something in HA from a F@H binary sensor is to expose the HA entity via emulated_hue, e.g. as a light bulb.

Tho85 commented 3 years ago

Take a look at the emulated_hue component for Home Assistant. If you install it, Home Assistant simulates a Philips Hue bridge that exposes selected lights in Home Assistant as Philips Hue light bulbs.

The free@home SysAP should discover that bridge and connect to it. You should then see a list of all exposed lights under your devices list. You can then drop these virtual Philips Hue bulbs onto your floor plan and connect them like any other free@home light bulb.

IIRC this does not only work for lights in Home Assistant, but for scenes, scripts, automations, etc. as well. So you can trigger almost any entity in Home Assistant through your free@home switches, motion detectors etc.

SuperMaximus1984 commented 3 years ago

Dears, Is there any update on reading Binary Sensor status from 8/8 Sensor/Actuator unit? https://www.busch-jaeger.de/en/online-catalogue/product-overview?tx_nlbjproducts_catalog%5Baction%5D=show&tx_nlbjproducts_catalog%5BcatBjeProdukt%5D=15137&tx_nlbjproducts_catalog%5Bcontroller%5D=CatStdArtikel&cHash=b958c2a9b1a888a552d7532a4bd59e0a

As it declares itself as one unit, and in @jheling 's component it can be selected either as Sensor OR Actuator, it can't be recognized by HA as a multi-functional device that contains both. I was able to set & control it as Actuator, but Binary Sensors - unfortunately - no... Any help on how to realize it is appreciated.

Tho85 commented 3 years ago

@SuperMaximus1984 Support for this device should be improved in #73, you should be able to use the 8 sensor and 8 actuator channels separately. Feel free to try the code there and give feedback.

SuperMaximus1984 commented 3 years ago

@Tho85 Thanks! I just don't quite get what files from @jheling 's original one's I need to replace with yours in order to use reworked code. Could you please point out?

jheling commented 3 years ago

I have just merged @Tho85 pull request. You can just download whole zip and install it on your system. Almost all the files have been touched.