JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
161 stars 39 forks source link

[Request]: Authentication NFC Code Touch #253

Open pissten opened 1 month ago

pissten commented 1 month ago

Describe the bug

Would be great to have support for the object type: Authentication NFC Code Touch

Firmware of your Miniserver

Newest

HomeAssistant install method

Docker

Version of HomeAssistant

Latest

Version of Pyloxone

Latest

Update pyloxone

not relevant

Log

Settings for the log can be found on the main page under the section Log Configuration

gigatexel commented 1 month ago

Hi @pissten. I'm keem to help, but integrating the NFC would require creating a new "device" in the custom integration. I'm not skilled enough in python/HA to implement this from scratch.

From now, maybe you could use the VTI addition to send/get info from the NFC block?

gigatexel commented 1 month ago

@pissten Are you able to test when I have some more progression?

image
pissten commented 1 month ago

Wow 😲🤩 absolutely mate 🙏🤌

pissten commented 1 month ago

Do you know if the code touch api, allows for retrieving state change upon successfull access code being entered? A useful usecase would be to activate/deactivate alarmo from the code touch panel 🤞🤩

gigatexel commented 1 month ago

Do you know if the code touch api, allows for retrieving state change upon successfull access code being entered? A useful usecase would be to activate/deactivate alarmo from the code touch panel 🤞🤩

I'm not that far yet. But you could use the VTI-integration for that.

gigatexel commented 1 month ago

Do you know if the code touch api, allows for retrieving state change upon successfull access code being entered? A useful usecase would be to activate/deactivate alarmo from the code touch panel 🤞🤩

Can you replace the const.py file with the one from my repository and add the button.py file from the same location?

https://github.com/gigatexel/PyLoxone/tree/add_nfc/custom_components/loxone

Let me know if this works.

Warning

You need to disable the Visualisation Password on the NFC Code Touch block in Loxone Config. This breaks part of Loxone's NFC Code Touch's security.

@JoDehli I tried to use the SECUREDSENDDOMAIN parameter as a replacement for SENDDOMAIN but it returns an error 500. Moreover, this causes my HA to crash after a few tries and requires a full reboot

pissten commented 1 month ago

Hi @gigatexel Thanks for your great effort on this! I have replaced the files you mentioned, and can now see the device and one entity (Q1). But on the other hand, I have some issues with the loxone integration in general. It has difficaulties on generating connection upon startup. Very often the loxone will fail to load, and when manually realoading the integration, it loads but all entities shows as unavailable :/

image

logs: Before replacing you files: 2024-04-02 22:01:03.614 WARNING (MainThread) [py.warnings] /config/custom_components/loxone/const.py:103: SyntaxWarning: invalid escape sequence '\d' 2024-04-02 22:02:36.637 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry PyLoxone for loxone File "/config/custom_components/loxone/__init__.py", line 175, in async_setup_entry File "/config/custom_components/loxone/miniserver.py", line 133, in async_setup File "/config/custom_components/loxone/api.py", line 105, in getJson After replacing your files: 2024-04-02 22:05:30.737 INFO (MainThread) [custom_components.loxone.button] id: q1 2024-04-02 22:05:30.841 DEBUG (MainThread) [custom_components.loxone.api] try to read token 2024-04-02 22:05:30.841 DEBUG (MainThread) [custom_components.loxone.api] try to get_token_from_file 2024-04-02 22:05:30.841 DEBUG (MainThread) [custom_components.loxone.api] try to get public key: http://10.0.0.41/jdev/sys/getPublicKey 2024-04-02 22:05:30.917 DEBUG (MainThread) [custom_components.loxone.api] get_public_key successfully... 2024-04-02 22:05:31.408 DEBUG (MainThread) [custom_components.loxone.api] init_rsa_cipher successfully... 2024-04-02 22:05:31.410 DEBUG (MainThread) [custom_components.loxone.api] generate_session_key successfully... 2024-04-02 22:05:44.073 DEBUG (MainThread) [custom_components.loxone.api] parse_loxone_message successfully... 2024-04-02 22:05:44.073 DEBUG (MainThread) [custom_components.loxone.api] acquire_tokend 2024-04-02 22:05:44.074 DEBUG (MainThread) [custom_components.loxone.api] get_new_aes_chiper successfully... 2024-04-02 22:05:44.305 DEBUG (MainThread) [custom_components.loxone.api] parse_loxone_message successfully... 2024-04-02 22:05:44.305 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry PyLoxone for loxone File "/config/custom_components/loxone/__init__.py", line 351, in async_setup_entry File "/config/custom_components/loxone/miniserver.py", line 119, in start_ws File "/config/custom_components/loxone/api.py", line 435, in async_init File "/config/custom_components/loxone/api.py", line 694, in acquire_token File "/config/custom_components/loxone/api.py", line 1013, in read_user_salt_responce

pissten commented 1 month ago

Addditional information:

Running Home Assistant 2024.3.1, in docker. System OS: Ubuntu 22.04.3 LTS

JoDehli commented 1 month ago

@pissten reloading does not work and is not implemented. I had a lot of problems In the past and every time it was the network. So please first check you connection quality. Some users had there miniserver in a different network. When it is it not every time it is not caused by the integration in the first place.

Have you tried openhab as an alternative solution?

gigatexel commented 1 month ago

Hi @gigatexel Thanks for your great effort on this! I have replaced the files you mentioned, and can now see the device and one entity (Q1). But on the other hand, I have some issues with the loxone integration in general. It has difficaulties on generating connection upon startup. Very often the loxone will fail to load, and when manually realoading the integration, it loads but all entities shows as unavailable :/

How many Outputs do you have configured? If you have only Q1, only Q1 appears in HA. If you have, for example used Q1, Q2, Q3, all three will appear in HA.

Regarding the connection errors, a HA restart usually fixes these for me.

pissten commented 1 month ago

@pissten reloading does not work and is not implemented. I had a lot of problems In the past and every time it was the network. So please first check you connection quality. Some users had there miniserver in a different network. When it is it not every time it is not caused by the integration in the first place.

Have you tried openhab as an alternative solution?

Hi @JoDehli,

Yes, i used openhab for several years until i decided to move to HA. I also back then used the loxone binding, and had a very stable connection. Regarding the network issues i can't say that I suspect a network related problem. I have a really good cabling topology and running unifi equipment. All my network devices is on the same VLAN and subnet. But It may be some issues related to the Docker environment though :/ I'm also running home assistant network mode as host, and in privileged mode.

I haven't been able to find a specific pattern on when It is able to connect, and when it fails. But It was working a long time on version 0.6.1, working stable inbetween and on reboots, but issues when upgrading to 0.6.2 and 0.6.3.. now after downgrading to 0.6.1, it doesn't work so good anymore, perhaps because of my HA version beeing to new. But, I now have the integration up and running, by downgrading to 0.6.1 and copying the files metioned from @gigatexel repo.

pissten commented 1 month ago

@gigatexel ,

I have finally got some time to test a little bit on my installation. And so far, I can't seem to get the Q1 push button to actually trigger a action on the loxone side. I have tried to send a different combinations of commands using the loxone.event_websocket_command service, and this is what has worked for me so far:

service: loxone.event_websocket_command data: uuid: myuuid/output/1

service: loxone.event_websocket_command data: uuid: myuuid/output value: 1

Log from when i press the Q1 button from within the integration device ( as pictured from screendump above ): 2024-04-03 15:51:41.232 DEBUG (MainThread) [custom_components.loxone.api] send command: jdev/sps/io/17395597-03d6-2439-ffff60d05923bf6e/output/l 2024-04-03 15:51:41.234 DEBUG (MainThread) [custom_components.loxone.api] message [type:0]):{"LL": { "control": "dev/sps/io/17395597-03d6-2439-ffff60d05923bf6e/output/l", "value": "423", "Code": "423"}} I don't know why the value: "423" is present though?

Logs from sending through loxone.event_websocket_command: 2024-04-03 15:52:15.381 DEBUG (MainThread) [custom_components.loxone.api] send command: jdev/sps/io/17395597-03d6-2439-ffff60d05923bf6e/output/1/423 2024-04-03 15:52:15.387 DEBUG (MainThread) [custom_components.loxone.api] message [type:0]):{"LL": { "control": "dev/sps/io/17395597-03d6-2439-ffff60d05923bf6e/output/1", "value": "output/1", "Code": "200"}}

gigatexel commented 1 month ago

https://www.loxone.com/wp-content/uploads/datasheets/CommunicatingWithMiniserver.pdf page 33

There is something wrong with the user you are using for the integration

pissten commented 1 month ago

Hi @gigatexel Thanks for your great effort on this! I have replaced the files you mentioned, and can now see the device and one entity (Q1). But on the other hand, I have some issues with the loxone integration in general. It has difficaulties on generating connection upon startup. Very often the loxone will fail to load, and when manually realoading the integration, it loads but all entities shows as unavailable :/

How many Outputs do you have configured? If you have only Q1, only Q1 appears in HA. If you have, for example used Q1, Q2, Q3, all three will appear in HA.

Regarding the connection errors, a HA restart usually fixes these for me.

I only have Q1 configured. But what data is available from the NFC code touch api? Are all the inputs and outputs on the system block in loxone config, available over the api connector? Would be interessted in the As - Authentication Successfull [Digital], as this could potensially be used as a arm/disarming function for alarmo

pissten commented 1 month ago

https://www.loxone.com/wp-content/uploads/datasheets/CommunicatingWithMiniserver.pdf page 33

There is something wrong with the user you are using for the integration

You are absolutely right! :) I added another user to my config, and reauthenticated the loxone integration, and now the button is working as expected! Thank you very much for integrating this! Would probably need some more assistanse on the integration not loading properly though :S

gigatexel commented 1 month ago

https://www.loxone.com/wp-content/uploads/datasheets/CommunicatingWithMiniserver.pdf page 33 There is something wrong with the user you are using for the integration

You are absolutely right! :) I added another user to my config, and reauthenticated the loxone integration, and now the button is working as expected! Thank you very much for integrating this! Would probably need some more assistanse on the integration not loading properly though :S

Hi!

https://www.loxone.com/enen/kb/api/ -> Structure File -> Page 94 This shows all that is implemented on the API, as you can see, no As.

What you could to is add a Virtual Status to the NFC block. This VO will then appear in the integration. But beware As is a "general" output. So any authentication will disable the alarm - regardless of what output you trigger.

gigatexel commented 1 month ago

An example:

image