mak-gitdev / HA_enoceanmqtt

Home Assistant wrapper for enocean-mqtt (https://github.com/embyt/enocean-mqtt)
GNU General Public License v3.0
54 stars 14 forks source link

MQTT discovery not working? #61

Closed tbarbette closed 1 year ago

tbarbette commented 1 year ago

Hi all! I'm trying this great "overlay" to finally be able to activate some lights through enocean.

However no MQTT devices appear. I'm using a local mosquitto without password.

Here's my log (using docker-compose):

sudo docker logs ha_enoceanmqtt_dev                                                                                                          < ~homeassistant/.homeassistant (:|✔)[15:28:13]
/usr/local/lib/python3.11/site-packages/beautifulsoup4-4.11.2-py3.11.egg/bs4/builder/__init__.py:545: XMLParsedAsHTMLWarning: It looks like you're parsing an XML document using an HTML parser. If this really is an HTML document (maybe it's XHTML?), you can ignore or filter this warning. If it's XML, you should know that using an XML parser will be more reliable. To parse this document as XML, make sure you have the lxml package installed, and pass the keyword argument `features="xml"` into the BeautifulSoup constructor.
  warnings.warn(
2023-03-31 13:27:58,369 INFO: Logging to file: /app/enocean-mqtt/enoceanmqtt/../enoceanmqtt.log
2023-03-31 13:27:58,370 INFO: Loading config file /config/enoceanmqtt.conf
2023-03-31 13:27:58,372 INFO: Loading config file /config/enoceanmqtt.conf
2023-03-31 13:27:58,374 INFO: Selected overlay : Home Assistant
2023-03-31 13:27:59,354 INFO: Mapping file correctly read: /app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/mapping.yaml
2023-03-31 13:27:59,355 INFO: Device database /app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/device_db.json correctly read/created

Here's my config file:

## the general section defines parameter for the mqtt broker and the enocean interface
[CONFIG]
enocean_port    = /dev/enocean
log_packets     = 1
overlay         = HA

## the discovery prefix is used by MQTT discovery in Home Assistant
mqtt_discovery_prefix = homeassistant/

mqtt_host       = localhost
mqtt_port       = 1883
mqtt_client_id  = enocean_gateway   # ensure that this is unique if you use multiple clients

## setting mqtt_keepalive = 0 sets the timeout to infinitive but does not work reliably
## due to an upstream issue https://github.com/eclipse/paho.mqtt.python/issues/473
mqtt_keepalive  = 60

## the prefix is used for the mqtt value names; this is extended by the sensor name
mqtt_prefix     = enoceanmqtt/

# Set mqtt_user and mqtt_pwd (don't use quotes).
#mqtt_user       =
#mqtt_pwd        =

## enable SSL on MQTT connection
## Ensure that mqtt_host matches one of the hostnames contained in the broker's
## certificate, otherwise the client will refuse to connect.
##
## mqtt_ssl_ca_certs: CA certificates to be treated as trusted. Required if
##     the MQTT broker is configured with a self-signed certificate.
## mqtt_ssl_certfile, mqtt_ssl_keyfile: Client certificate and private key.
##     Only required if the broker requires clients to present a certificate.
## mqtt_ssl_insecure: Disable verification of the broker's certificate.
##     WARNING: do NOT use on production systems as this is insecure!
##
# mqtt_ssl          = true
# mqtt_ssl_ca_certs = /path/CA_files_merged.pem
# mqtt_ssl_certfile = /path/client_cert.pem
# mqtt_ssl_keyfile  = /path/client_key.pem
# mqtt_ssl_insecure = true

## Enable/Disable MQTT debugging. Requires --debug on the command line.
mqtt_debug      = false

## all other sections define the sensors to monitor

[virtualButton1]
address = 0xFFFFFFFF
rorg    = 0xF6
func    = 0x02
type    = 0x01
sender  = 0xFFDA5580
virtual = 1

I've got no devices inside HA. Probably a noob problem :) image

Any idea what is going wrong? :) Thanks!

mak-gitdev commented 1 year ago

Hi @tbarbette,

Could you please run enoceanmqtt with --debug ? Also in enoceanmqtt.conf, set mqtt_debug to true.

Then please report the full log here.

tbarbette commented 1 year ago

Thanks for your reply. Here's the output:

sudo docker run --volume /home/homeassistant/ha_enoceanmqtt/config:/config --device /dev/serial/by-id/usb-EnOcean_GmbH_EnOcean_USB_300_DC_FT3YJB58-if00-port0:/dev/enocean makgitdev/ha_enoceanmqtt_dev-armhf /config/enoceanmqtt.conf --debug
/usr/local/lib/python3.11/site-packages/beautifulsoup4-4.11.2-py3.11.egg/bs4/builder/__init__.py:545: XMLParsedAsHTMLWarning: It looks like you're parsing an XML document using an HTML parser. If this really is an HTML document (maybe it's XHTML?), you can ignore or filter this warning. If it's XML, you should know that using an XML parser will be more reliable. To parse this document as XML, make sure you have the lxml package installed, and pass the keyword argument `features="xml"` into the BeautifulSoup constructor.
  warnings.warn(
2023-04-01 13:49:11,358 INFO: Logging to file: /app/enocean-mqtt/enoceanmqtt/../enoceanmqtt.log
2023-04-01 13:49:11,360 INFO: Loading config file /config/enoceanmqtt.conf
2023-04-01 13:49:11,362 DEBUG: Created sensor: {'name': 'enoceanmqtt/virtualButton1', 'address': 4294967295, 'rorg': 246, 'func': 2, 'type': 1, 'sender': 4292498816, 'virtual': 1}
2023-04-01 13:49:11,364 INFO: Loading config file /config/enoceanmqtt.conf
2023-04-01 13:49:11,366 DEBUG: Created sensor: {'name': 'enoceanmqtt/virtualButton1', 'address': 4294967295, 'rorg': 246, 'func': 2, 'type': 1, 'sender': 4292498816, 'virtual': 1}
2023-04-01 13:49:11,367 DEBUG: Global config: {'enocean_port': '/dev/enocean', 'log_packets': '1', 'overlay': 'HA', 'mqtt_discovery_prefix': 'homeassistant/', 'mqtt_host': '127.0.0.1', 'mqtt_port': '1883', 'mqtt_client_id': 'enocean_gateway', 'mqtt_keepalive': '60', 'mqtt_prefix': 'enoceanmqtt/', 'mqtt_debug': 'true'}
2023-04-01 13:49:11,367 INFO: Selected overlay : Home Assistant
2023-04-01 13:49:12,324 INFO: Mapping file correctly read: /app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/mapping.yaml
2023-04-01 13:49:12,326 INFO: Device database /app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/device_db.json correctly read/created
2023-04-01 13:49:12,327 DEBUG: Connecting to host 127.0.0.1, port 1883, keepalive 60
2023-04-01 13:49:12,337 DEBUG: Connection failed, retrying
2023-04-01 13:49:12,340 INFO: SerialCommunicator started
2023-04-01 13:49:12,341 INFO: Auto Teach-in is disabled
2023-04-01 13:49:12,341 WARNING: Replacing Packet.optional with default value.
2023-04-01 13:49:12,441 INFO: Sending packet
2023-04-01 13:49:12,442 DEBUG: 0x05 ['0x8'] [] OrderedDict()
2023-04-01 13:49:12,543 DEBUG: 0x02 ['0x0', '0xff', '0xed', '0xa9', '0x0'] ['0xa'] OrderedDict()
2023-04-01 13:49:12,545 INFO: got response packet: OK
2023-04-01 13:49:15,338 DEBUG: Connection failed, retrying
2023-04-01 13:49:19,339 DEBUG: Connection failed, retrying
2023-04-01 13:49:27,340 DEBUG: Connection failed, retrying
2023-04-01 13:49:43,341 DEBUG: Connection failed, retrying
2023-04-01 13:50:15,342 DEBUG: Connection failed, retrying

Connection failed relates to mqtt, right? mosquitto_pub -h 127.0.0.1 -p 1883 -t homeassistant/discovery -m "hello" works for instance.

tbarbette commented 1 year ago

Ok, it's because I'm using docker, and therefore 127.0.0.1 from docker does not work ! I ended up using my local IP address.

May I suggest "Connection failed" should be a WARNING and not a DEBUG?

mak-gitdev commented 1 year ago

Hi @tbarbette,

May I suggest "Connection failed" should be a WARNING and not a DEBUG?

This is done at paho-mqtt level so we don't have control over that. It has been activated because of mqtt_debug being set to true in your enoceanmqtt.conf file.