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

Custom mapping.yaml file does not work #51

Closed aperrin closed 1 year ago

aperrin commented 1 year ago

Hi there,

I wanted to change a little detail in the mapping.yaml, as my covers do not behave as in the default one (mine are at position 0 when close, 100 when open). To do so, I copied this mapping.yaml file : https://github.com/mak-gitdev/HA_enoceanmqtt/blob/master/enoceanmqtt/overlays/homeassistant/mapping.yaml And I only changed the following (line 394):

payload_open: >-
    {"CMD":"1","POS":"0","ANG":"127","REPO":"0","LOCK":"0","CHN":"0","send":"clear"}
 payload_close: >-
    {"CMD":"1","POS":"100","ANG":"127","REPO":"0","LOCK":"0","CHN":"0","send":"clear"}

to

payload_open: >-
  {"CMD":"1","POS":"100","ANG":"127","REPO":"0","LOCK":"0","CHN":"0","send":"clear"}
payload_close: >-
  {"CMD":"1","POS":"0","ANG":"127","REPO":"0","LOCK":"0","CHN":"0","send":"clear"}

I added the path to this new file in the config of the add-on :

device_file: /config/enocean/enoceanmqtt.conf
mapping_file: /config/enocean/mapping.yaml
eep_file: ""
[...]

and restarted. In the logs, I can see that everything seems to be correctly read. However, the devices are not synchronized anymore with HA : I cannot access them (see their state, change etc.). One thing I saw in the log file is an error Caught exception in on_connect: 'date' which does not appear when I don't specify a custom mapping file. But this happens after the 2023-02-25 14:33:50,125 INFO: Mapping file correctly read: /config/enocean/mapping.yaml. Any idea what could happen?

Here is my logs

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
s6-rc: info: service legacy-services successfully started
Preparing to start...
Retrieved devices file: /config/enocean/enoceanmqtt.conf
Starting EnOceanMQTT...
/usr/lib/python3.10/site-packages/beautifulsoup4-4.11.2-py3.10.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-02-25 14:33:49,686 INFO: Logging to file: /config/enocean/enoceanmqtt.log
2023-02-25 14:33:49,688 INFO: Loading config file /data/enoceanmqtt.conf
2023-02-25 14:33:49,696 DEBUG: Created sensor: {'name': 'homeassistant/inter-sup-salon', 'address': xxxxx, 'rorg': xxx, 'func': 2, 'type': 1, 'log_learn': 1, 'publish_rssi': 0}
2023-02-25 14:33:49,697 DEBUG: Created sensor: {'name': 'homeassistant/cover/salon', 'address': xxxxxx, 'rorg': xxx, 'func': 5, 'type': 0, 'log_learn': 1, 'command': 'CMD', 'persistent': 1}
2023-02-25 14:33:49,708 DEBUG: Global config: {'enocean_port': '/dev/ttyUSB0', 'log_packets': 'true', 'overlay': 'HA', 'db_file': '/data/enoceanmqtt_db.json', 'mapping_file': '/config/enocean/mapping.yaml', 'mqtt_discovery_prefix': 'homeassistant/', 'mqtt_host': 'core-mosquitto', 'mqtt_port': '1883', 'mqtt_client_id': 'homeassistant', 'mqtt_keepalive': '60', 'mqtt_prefix': 'homeassistant/', 'mqtt_user': 'addons', 'mqtt_pwd': '*****', 'mqtt_debug': 'true'}
2023-02-25 14:33:49,708 INFO: Selected overlay : Home Assistant
2023-02-25 14:33:50,125 INFO: Mapping file correctly read: /config/enocean/mapping.yaml
2023-02-25 14:33:50,177 INFO: Device database /data/enoceanmqtt_db.json correctly read/created
2023-02-25 14:33:50,178 INFO: Authenticating: addons
2023-02-25 14:33:50,179 DEBUG: Connecting to host core-mosquitto, 
2023-02-25 14:33:50,188 INFO: SerialCommunicator started
2023-02-25 14:33:50,188 INFO: Auto Teach-in is disabled
2023-02-25 14:33:50,189 WARNING: Replacing Packet.optional with default value.
2023-02-25 14:33:50,291 INFO: Sending packet
[...]
2023-02-25 14:33:50,302 INFO: Succesfully connected to MQTT broker.
2023-02-25 14:33:50,303 DEBUG: Sending SUBSCRIBE (d0, m1) [...]
2023-02-25 14:33:50,321 ERROR: Caught exception in on_connect: 'date'
Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 3039, in _packet_handle
2023-02-25 14:33:50,397 DEBUG: 0x02 ['0x0', '0xff', '0xd2', '0x7c', '0x80'] ['0xa'] OrderedDict()
2023-02-25 14:33:50,398 INFO: got response packet: OK
    return self._handle_connack()
  File "/usr/lib/python3.10/site-packages/paho_mqtt-1.6.1-py3.10.egg/paho/mqtt/client.py", line 3138, in _handle_connack
    on_connect(
  File "/app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/ha_communicator.py", line 107, in _on_connect
    self._mqtt_discovery_sensor(cur_sensor, cfgtopics)
  File "/app/enocean-mqtt/enoceanmqtt/overlays/homeassistant/ha_communicator.py", line 236, in _mqtt_discovery_sensor
    device_map += copy.deepcopy(self._ha_mapping['common']['date'])
KeyError: 'date'
2023-02-25 14:33:57,398 DEBUG: FF:E7:B3:81->FF:FF:FF:FF (-56 dBm):
2023-02-25 14:33:57,408 INFO: unknown sensor: FF:E7:B3:82
[...]

Thanks for your help !

mak-gitdev commented 1 year ago

Hi @aperrin,

Do not use the mapping file in the master branch but the one in the two others branches.

aperrin commented 1 year ago

Perfect, that solved the problem, thank you!