zdar / elan2mqtt

MQTT client (gateway) for eLan
MIT License
11 stars 4 forks source link

Can't connect to elan #2

Closed barnagoz closed 2 years ago

barnagoz commented 2 years ago

Hi!

I might be a little late for this repo, I don't know if it is active, but when I try to use the add-on, it drops this error:

[2021-10-18 16:37:44,543] {socket_listener.py:296} ERROR - SOCKET LISTENER: Something went wrong. But don't worry we will start over again.
Traceback (most recent call last):
  File "/elan2mqtt-1.7.0/socket_listener.py", line 294, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/elan2mqtt-1.7.0/socket_listener.py", line 143, in main
    mqtt_cli.connect(mqtt_broker, 1883, 120)
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)

I use a raspberry pi 3b+ with the official Home assistant software installed directly, so I don't use Docker or anything like that.

zdar commented 2 years ago

Hi, could you send me a longer part of the log? Including beginning when first connection is done. From the part you have posted I can't determine the problem. I just see that connection to you elan gateway fails for some reason.

Some quick checks:

Docker - original HA software uses docker internally

barnagoz commented 2 years ago

Thanks for the fast reply! I'm actually really new to Hass.io, but I have copied it...

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Run.sh starting
Installing requirements
Collecting argparse
  Downloading argparse-1.4.0-py2.py3-none-any.whl (23 kB)
Collecting paho-mqtt
  Downloading paho-mqtt-1.5.1.tar.gz (101 kB)
Collecting multidict==4.5.2
  Downloading multidict-4.5.2.tar.gz (105 kB)
Collecting attrs>=17.3.0
  Downloading attrs-21.2.0-py2.py3-none-any.whl (53 kB)
Collecting yarl==1.2.6
  Downloading yarl-1.2.6.tar.gz (159 kB)
Collecting async_timeout<4.0,>=3.0
  Downloading async_timeout-3.0.1-py3-none-any.whl (8.2 kB)
Requirement already satisfied: idna>=2.0 in /usr/lib/python3.9/site-packages (from yarl==1.2.6->-r requirements.txt (line 6)) (3.2)
Using legacy 'setup.py install' for multidict, since package 'wheel' is not installed.
Using legacy 'setup.py install' for yarl, since package 'wheel' is not installed.
Using legacy 'setup.py install' for paho-mqtt, since package 'wheel' is not installed.
Installing collected packages: multidict, yarl, paho-mqtt, attrs, async-timeout, argparse
    Running setup.py install for multidict: started
    Running setup.py install for multidict: finished with status 'done'
    Running setup.py install for yarl: started
    Running setup.py install for yarl: finished with status 'done'
    Running setup.py install for paho-mqtt: started
    Running setup.py install for paho-mqtt: finished with status 'done'
Successfully installed argparse-1.4.0 async-timeout-3.0.1 attrs-21.2.0 multidict-4.5.2 paho-mqtt-1.5.1 yarl-1.2.6
Starting gateway
http://192.168.1.3 mqtt://admin:[mypassword]@192.168.1.3
Loglevel: notice
Autodiscovery disabled: false
[2021-10-19 06:52:11,691] {socket_listener.py:296} ERROR - SOCKET LISTENER: Something went wrong. But don't worry we will start over again.
Traceback (most recent call last):
  File "/elan2mqtt-1.7.0/socket_listener.py", line 294, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/elan2mqtt-1.7.0/socket_listener.py", line 143, in main
    mqtt_cli.connect(mqtt_broker, 1883, 120)
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
[2021-10-19 06:52:11,708] {socket_listener.py:299} ERROR - But at first take some break. Sleeping for 5 s
[2021-10-19 06:52:11,692] {main_worker.py:1060} ERROR - MAIN WORKER: Something went wrong. But don't worry we will start over again.
Traceback (most recent call last):
  File "/elan2mqtt-1.7.0/main_worker.py", line 1058, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/elan2mqtt-1.7.0/main_worker.py", line 855, in main
    mqtt_cli.connect(mqtt_broker, 1883, 120)
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
[2021-10-19 06:52:11,710] {main_worker.py:1063} ERROR - But at first take some break. Sleeping for 10 s

[mypassword] is changed to my actual password, I just didn't felt the need to post it to the internet.

And yes the URL, name and the password is properly set up. I can connect to it with browser. No, it does not connect.

I hope it is enough.

zdar commented 2 years ago

Ok. The problem is not with eLan but with connection to your MQTT server. It is refused.

"ConnectionRefusedError: [Errno 111] Connection refused"

Check config of MQTT (IP, username, password, opened ports on firewall if used). Try to use MQTT lens or other tool to test connection to your MQTT server first.

barnagoz commented 2 years ago

I have changed the mqtt brokers url... But it still doesn't work.

Log:

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Run.sh starting
Installing requirements
Collecting argparse
  Downloading argparse-1.4.0-py2.py3-none-any.whl (23 kB)
Collecting paho-mqtt
  Downloading paho-mqtt-1.5.1.tar.gz (101 kB)
Collecting multidict==4.5.2
  Downloading multidict-4.5.2.tar.gz (105 kB)
Collecting attrs>=17.3.0
  Downloading attrs-21.2.0-py2.py3-none-any.whl (53 kB)
Collecting yarl==1.2.6
  Downloading yarl-1.2.6.tar.gz (159 kB)
Collecting async_timeout<4.0,>=3.0
  Downloading async_timeout-3.0.1-py3-none-any.whl (8.2 kB)
Requirement already satisfied: idna>=2.0 in /usr/lib/python3.9/site-packages (from yarl==1.2.6->-r requirements.txt (line 6)) (3.2)
Using legacy 'setup.py install' for multidict, since package 'wheel' is not installed.
Using legacy 'setup.py install' for yarl, since package 'wheel' is not installed.
Using legacy 'setup.py install' for paho-mqtt, since package 'wheel' is not installed.
Installing collected packages: multidict, yarl, paho-mqtt, attrs, async-timeout, argparse
    Running setup.py install for multidict: started
    Running setup.py install for multidict: finished with status 'done'
    Running setup.py install for yarl: started
    Running setup.py install for yarl: finished with status 'done'
    Running setup.py install for paho-mqtt: started
    Running setup.py install for paho-mqtt: finished with status 'done'
Successfully installed argparse-1.4.0 async-timeout-3.0.1 attrs-21.2.0 multidict-4.5.2 paho-mqtt-1.5.1 yarl-1.2.6
Starting gateway
http://192.168.1.3 mqtt://mqtt:feketefeherkek99@192.168.1.60:1883
Loglevel: notice
Autodiscovery disabled: false
[2021-10-19 14:18:06,144] {socket_listener.py:296} ERROR - SOCKET LISTENER: Something went wrong. But don't worry we will start over again.
Traceback (most recent call last):
  File "/elan2mqtt-1.7.0/socket_listener.py", line 294, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/elan2mqtt-1.7.0/socket_listener.py", line 143, in main
    mqtt_cli.connect(mqtt_broker, 1883, 120)
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve
[2021-10-19 14:18:06,166] {socket_listener.py:299} ERROR - But at first take some break. Sleeping for 5 s
[2021-10-19 14:18:06,148] {main_worker.py:1060} ERROR - MAIN WORKER: Something went wrong. But don't worry we will start over again.
Traceback (most recent call last):
  File "/elan2mqtt-1.7.0/main_worker.py", line 1058, in <module>
    asyncio.get_event_loop().run_until_complete(main())
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/elan2mqtt-1.7.0/main_worker.py", line 855, in main
    mqtt_cli.connect(mqtt_broker, 1883, 120)
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 941, in connect
    return self.reconnect()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 1075, in reconnect
    sock = self._create_socket_connection()
  File "/usr/lib/python3.9/site-packages/paho/mqtt/client.py", line 3546, in _create_socket_connection
    return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
  File "/usr/lib/python3.9/socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name does not resolve
[2021-10-19 14:18:06,177] {main_worker.py:1063} ERROR - But at first take some break. Sleeping for 10 s

When I get home, I will try to use mqtt lens.

zdar commented 2 years ago

It is still problem of MQTT broker address. Supplied name can not be resolved. "socket.gaierror: [Errno -2] Name does not resolve"

barnagoz commented 2 years ago

Yes!!!! It is connected...

But:

Starting gateway
http://192.168.1.3 mqtt://[my uname and pass]@192.168.1.60
Loglevel: notice
Autodiscovery disabled: false
[2021-10-19 15:28:30,823] {socket_listener.py:180} ERROR - There is no MAC for device {'url': 'http://192.168.1.3/api/devices/53581', 'info': {'id': '53581', 'device info': {'label': 'Emelet fűtése', 'product type': 'HeatCoolArea', 'type': 'temperature regulation area'}, 'actions info': {'mode': {'type': 'int', 'min': 1, 'max': 4, 'step': 1}, 'correction': {'type': 'number', 'min': -5, 'max': 5, 'step': 0.5}, 'device action': {'type': 'object'}, 'controll': {'type': 'int', 'min': 1, 'max': 4, 'step': 1}, 'power': {'type': 'int', 'min': 0, 'max': 2, 'step': 1}}, 'primary actions': [], 'secondary actions': ['power', 'correction', 'mode'], 'settings': {}, 'schedule': '55026', 'schedule2': '55026', 'temperature sensor': {'61780': 'temperature'}, 'heating devices': [{'id': '09456', 'central source': False}], 'cooling devices': []}}
[2021-10-19 15:28:30,876] {main_worker.py:894} ERROR - There is no MAC for device {'url': 'http://192.168.1.3/api/devices/53581', 'info': {'id': '53581', 'device info': {'label': 'Emelet fűtése', 'product type': 'HeatCoolArea', 'type': 'temperature regulation area'}, 'actions info': {'mode': {'type': 'int', 'min': 1, 'max': 4, 'step': 1}, 'correction': {'type': 'number', 'min': -5, 'max': 5, 'step': 0.5}, 'device action': {'type': 'object'}, 'controll': {'type': 'int', 'min': 1, 'max': 4, 'step': 1}, 'power': {'type': 'int', 'min': 0, 'max': 2, 'step': 1}}, 'primary actions': [], 'secondary actions': ['power', 'correction', 'mode'], 'settings': {}, 'schedule': '55026', 'schedule2': '55026', 'temperature sensor': {'61780': 'temperature'}, 'heating devices': [{'id': '09456', 'central source': False}], 'cooling devices': []}}

And it goes along... Our whole house is full of these sensors, thermostats, etc...

zdar commented 2 years ago

Let me guess. Those are "virtual" devices defined in eLan to setup heating zones. They use temperature sensors and valves to regulate the temperature in room itself.

I do not have those in my config therefore they are not directly supported by now. However the ERROR is pretty harmless and most of things should work. You should see you temperature sensors and probably heaters present.

To get it supporte I'll need some (=a lot of) info from you. I will need:

However as a first step - could you enable debug in elan2mqtt config and send me a log via PM (full log). Just do not forget to delete passwords etc :-)

Note: You should be able tomanually setup MQTT controls even without "support" for zones in elan2mqtt. Support just means that autodiscovery works

barnagoz commented 2 years ago

Thanks! Can you tell me, how should I add the devices manually to hass.io? I'm a little bit new to this software... I just don't want to bother you with these kinds of things. If you could write a simple How-To I would be grateful.

zdar commented 2 years ago

There is not an easy HowTo unfortunatelly.

You have to look at how the webinterface and API of elan works for your device. What messages are exchange and to reverse engineer their format. Simply open elan in web browser and use developer console to look at the traffic.

Then you have to go trough HA documentation for MQTT devices (https://www.home-assistant.io/integrations/climate.mqtt/) There you have to define correct templates for status and command payloads (json files).

Very simply put - Elan2mqtt does not do any processing. It only forwards payload between elan and HA.

This is quite tedious problem. If you send me full debug log I can at least update elan2mqtt so that autodiscovery works better. You can use it as starting point.

barnagoz commented 2 years ago

Then, thank you for all your help! It is now working fine! 😊😊