JoDehli / PyLoxone

Python Loxone binding
Apache License 2.0
183 stars 40 forks source link

[How to]: Control my garage door (secured with code) #283

Closed Nico0W closed 4 weeks ago

Nico0W commented 1 month ago

Describe the bug

Hello,

I'm not able to control my Hormann garage door with HA. The door works well with Loxone and I've got the possibility to control it with Pyloxone but the door don't move cause it needs the security code. When I use it in Loxone, I have to insert the code. Where have I to put this code to control the door ?

dd

Thanks for your help! It makes me crazy!

Firmware of your Miniserver

Gen. 1 Firmware 14.5.12.7

HomeAssistant install method

RPI 4 server

Version of HomeAssistant

2024.7.2

Version of Pyloxone

Last one.

Update pyloxone

Successfully.

Log

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

JoDehli commented 1 month ago

@Nico0W I think it is not possible to secure a cover with normal UI elements. You can try to open the door via a secure websocket call. If this works you can try to combine it with a custom UI element where you can input a code. There a view custom elements available.

Nico0W commented 1 month ago

I'm really struggling to make it works...

I used ChatGPT to help me and i've added this to my configuration.yalm:

input_text:
  door_code:
    name: Code pour la porte
    min: 4
    max: 4
    pattern: '[0-9]{4}'
    mode: password

input_button:
  validate_code:
    name: Valider le code

shell_command:
  open_door: 'python3 /config/loxone_ws_client.py {{ code }}'

automation: !include automations.yaml
script: !include scripts.yaml

This to automation.yalm

`- alias: "Valider le code pour ouvrir la porte"
  trigger:
    platform: state
    entity_id: input_button.validate_code
    to: 'pressed'
  action:
    - service: shell_command.open_door
      data:
        code: "{{ states('input_text.door_code') }}"
`

and created this page in my configuration folder:

`import asyncio
import websockets
import ssl
import json
import sys

LOXONE_HOST = '192.168.1.100'  # Remplacez par l'adresse IP de votre Loxone Miniserver
LOXONE_PORT = 8080  # Remplacez par le port de votre Loxone Miniserver
LOXONE_USER = 'your_loxone_username'
LOXONE_PASSWORD = 'your_loxone_password'
LOXONE_DOOR_UUID = 'loxone_door_uuid'  # Remplacez par l'UUID de votre porte Loxone
CORRECT_CODE = '1234'  # Remplacez par le code correct

async def open_door_if_code_correct(entered_code):
    if entered_code == CORRECT_CODE:
        uri = f'wss://{LOXONE_HOST}:{LOXONE_PORT}/ws/rfc6455'
        ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
        async with websockets.connect(uri, ssl=ssl_context) as websocket:
            command = f'jdev/sps/io/{LOXONE_DOOR_UUID}/pulse'
            await websocket.send(json.dumps({'method': command}))
            response = await websocket.recv()
            print(response)
    else:
        print("Incorrect code")

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print("Usage: python3 loxone_ws_client.py <entered_code>")
    else:
        entered_code = sys.argv[1]
        asyncio.run(open_door_if_code_correct(entered_code))`

And it doens't seems to want to work. What have I done wrong ?

That's like my Mechanical Ventilation. In the Loxone app, I can control the speed, not in HA. Only see sensors about temperature and speed and have a button to switch to automatic mode. I would like to manually change the speed, like the app: vmc Do you have any idea on how i can control it ?

JoDehli commented 1 month ago

@Nico0W do you still have this problem? ChatGpt is the wrong solution for this. ;-)

Nico0W commented 1 month ago

Yes, I still have the problem.

I did not solve it, nothing worked with ChatGPT. Without help, it's completely out of my knowledge :-(

JoDehli commented 1 month ago

@Nico0W

Here is a solution how I would do it:

  1. Update Pyloxone to the newest version (at least 0.6.11). I created a service called "event_secured_websocket_command"
  2. Create a Input Helper for the Code. Let's assume that you call it code.
  3. Create a Template Cover like this:

cover:

IMPORTANT:

  1. The cover.tor in this example must be replaced with the cover name which you want to control. For example cover.ferme.
  2. The uuid: xxxxx-xxxx-xxx-xxxxx must be replaced with the uuid of the cover you want to control.

Then put the Input and the template Cover to any dashboard an try it. If this works you can hide the original cover which pyloxone auto generated.

JoDehli commented 1 month ago

@Nico0W and please do not only use chatGPT and read more in the documentation. ChatGPT is not the solution for such a problem.