tydom2MQTT addon :D - Delta Dore Tydom to MQTT Broker

Hi

It’s Windows contact detector

here is what i was able to retrieve before

“endpoints”: [
{
“error”: 15,
“id”: 1589883539,
“metadata”: [
{
“max”: 254,
“min”: 0,
“name”: “config”,
“permission”: “r”,
“step”: 1,
“type”: “numeric”,
“unit”: “NA”
},
{
“name”: “battDefect”,
“permission”: “r”,
“type”: “boolean”,
“unit”: “boolean”
},
{
“enum_values”: [
“SHORT”,
“LONG”,
“NONE”
],
“name”: “supervisionMode”,
“permission”: “r”,
“type”: “string”
},
{
“name”: “intrusionDetect”,
“permission”: “r”,
“type”: “boolean”,
“unit”: “boolean”
},
{
“enum_values”: [
“LOCKED”,
“UNLOCKED”
],
“name”: “openState”,
“permission”: “r”,
“type”: “string”

Hi there,

I’m a very new user of Home assistant.
Got same issue with build 0.116.2
I installed mosquitto broker. Log is saying “Saving in-memory database to /data/mosquitto.db.”
And here is Tydom2MQTT logs :

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
msg_data error in parsing !
1590338190
Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...

I have a tydom 2.0 with Tyxal+ alarm but nothing is appearing on devices.

Do you have any advice ?

Hi and welcome !

1st check if MQTT is working by going to Dev tools, listen # (you can test too with a message in Dev tools in home assistant and listening to your MQTT broker).

2nd I need more logs on the tydom part if it’s not working (check GitHub use python version of you and open an issue).

Note : any other tydom 2 users here ? I have tydom 1 so it might be the reason data is not parsed correctly (or it can be a minor thing and just MQTT that is not working :wink:

You have added MQTT integration in home assistant ?

Thanks for your feedback.
1st : yep, my MQTT seems to work. I can listen # and if I send a command, it get a feedback.
2nd : I tried to install docker but I get “docker: invalid reference format.”
And with python version, not better…

python3.7 main.py 
Traceback (most recent call last):
  File "main.py", line 301, in <module>
    asyncio.get_event_loop().run_until_complete(main_task())
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "main.py", line 256, in main_task
    conn.request("GET", "/mediation/client?mac={}&appli=1".format(mac), None, httpHeaders)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1229, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1275, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1224, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1016, in _send_output
    self.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 956, in send
    self.connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 1384, in connect
    super().connect()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/http/client.py", line 928, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 727, in create_connection
    raise err
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 60] Operation timed out

I think I’m doing something wrong :sweat:

Hi again,
I succeed to execute python script from your other post : Tydom2mqtt - Make Delta Dore devices home assistant compatible ! =}
Result is my MQTT connexion is working using mqttconnection function.
This is the http connection to my TYDOM 2.0 that fail into timeout.

How can I investigate what is going wrong and/or how can I find the parameters send from TYDOM app to tydom 2.0 ?

Thanks for your help and advices

Me again…!
@WiwiWillou : are you able to give me the raw curl to execute in order to get Tydom response ?
Like this :

curl --location --request GET 'https://HOST:443/mediation/client?mac=TYDOM_MAC&appli=1' \
--header 'Upgrade: websocket' \
--header 'Connection: Upgrade' \
--header 'host: HOST:443' \
--header 'Accept: */*' \
--header 'Sec-WebSocket-Key: meP5gVDx7/SXq7Qo1t6Yrg==' \
--header 'Sec-WebSocket-Version: 13'

For the websocket key it’s an example generate from your function generate_random_key()
I would like to test through postman directly and see the result.
Maybe I miss some other header or params… But when I execute this, I get a timeout.

Thanks for your support !

Mmh i can’t really help from here, i just copied the connection code from an old repo : https://github.com/cth35/tydom_python

Did you try with the remote connection ? (mediation.tydom.com)

in my code :

    async def connect(self):

        print('""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""')
        print('TYDOM WEBSOCKET CONNECTION INITIALISING....                     ')

    
        
        print('Building headers, getting 1st handshake and authentication....')

        httpHeaders =  {"Connection": "Upgrade",
                        "Upgrade": "websocket",
                        "Host": self.host + ":443",
                        "Accept": "*/*",
                        "Sec-WebSocket-Key": self.generate_random_key(),
                        "Sec-WebSocket-Version": "13"
                        }
        conn = http.client.HTTPSConnection(self.host, 443, context=self.ssl_context)

        # Get first handshake
        conn.request("GET", "/mediation/client?mac={}&appli=1".format(self.mac), None, httpHeaders)
        res = conn.getresponse()
        # Get authentication
        nonce = res.headers["WWW-Authenticate"].split(',', 3)
        # read response
        res.read()
        # Close HTTPS Connection
        conn.close()

        print('Upgrading http connection to websocket....')
        # Build websocket headers
        websocketHeaders = {'Authorization': self.build_digest_headers(nonce)}

        if self.ssl_context is not None:
            websocket_ssl_context = self.ssl_context
        else:
            websocket_ssl_context = True # Verify certificate
            
    # outer loop restarted every time the connection fails
        print('Attempting websocket connection with tydom hub.......................')
        print('Host Target :')
        print(self.host)                
        '''
            Connecting to webSocket server
            websockets.client.connect returns a WebSocketClientProtocol, which is used to send and receive messages
        '''
        self.connection = await websockets.client.connect('wss://{}:443/mediation/client?mac={}&appli=1'.format(self.host, self.mac),
                                                            extra_headers=websocketHeaders, ssl=websocket_ssl_context, ping_timeout=None)
       
        return self.connection

Hi, After the update with the last version, here is my error, i use Tydom 1.0 with door sensor and climate

TYDOM WEBSOCKET CONNECTION INITIALISING....                     
Building headers, getting 1st handshake and authentication....
Upgrading http connection to websocket....
Attempting websocket connection with tydom hub.......................
Host Target :
192.168.1.5
Tydom Client is connected to websocket and ready !
Requesting 1st data...
>>>>>>>>>> Sending to tydom client..... GET /info
##################################
##################################
>>>>>>>>>> Sending to tydom client..... POST /refresh/all
>>>>>>>>>> Sending to tydom client..... GET /configs/file
>>>>>>>>>> Sending to tydom client..... GET /devices/data
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : Info detected
Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
Cannot parse response !
Error :  string indices must be integers
{'id_catalog': 'F2BD90F93B888DA02C54980F11AE4796DFCC98F447CD3FE326F5A3A964C939BF', 'os': 'ios', 'groups': [{'usage': 'window', 'picto': 'picto_window', 'group_all': False, 'id': 1293446020, 'name': 'Baie Est Droite'}, {'picto': 'picto_window', 'name': 'Baie Est Gauche', 'usage': 'window', 'id': 910283753, 'group_all': False}, {'usage': 'window', 'name': 'Baie Nord', 'picto': 'picto_window', 'id': 575301829, 'group_all': False}, {'name': 'TOTAL', 'picto': 'picto_lamp', 'usage': 'light', 'group_all': True, 'id': 1668318474}, {'name': 'TOTAL', 'id': 258981127, 'usage': 'shutter', 'picto': 'picto_shutter', 'group_all': True}, {'name': 'TOTAL', 'picto': 'picto_awning_awning', 'id': 1865462383, 'usage': 'awning', 'group_all': True}, {'name': 'Bureau Droite', 'picto': 'picto_window', 'id': 716588285, 'group_all': False, 'usage': 'window'}, {'usage': 'window', 'group_all': False, 'widget_behavior': {'inversionState': 'disabled'}, 'name': 'Bureau Gauche', 'id': 1980812653, 'picto': 'picto_window'}, {'picto': 'picto_window', 'usage': 'window', 'id': 455540512, 'group_all': False, 'name': 'Salle de bain'}, {'picto': 'picto_window', 'group_all': False, 'usage': 'window', 'id': 1982748604, 'name': 'Chambre Constance'}, {'name': 'WC', 'picto': 'picto_window', 'usage': 'window', 'id': 1165069053, 'group_all': False, 'widget_behavior': {'inversionState': 'disabled'}}, {'usage': 'window', 'id': 570421109, 'name': 'Cuisine', 'picto': 'picto_window', 'group_all': False}, {'group_all': False, 'picto': 'picto_window', 'id': 1640813503, 'name': 'Chambre Charlotte', 'usage': 'window'}, {'id': 1245751637, 'name': 'Salon gauche', 'usage': 'window', 'picto': 'picto_window', 'group_all': False}, {'name': 'Salon droit', 'picto': 'picto_window', 'group_all': False, 'id': 1020521302, 'usage': 'window'}, {'name': 'Chambre amis droite', 'usage': 'window', 'group_all': False, 'id': 12139290, 'picto': 'picto_window'}], 'scenarios': [], 'version_application': '3.10.0 (323)', 'areas': [], 'version': '1.0.1', 'date': 1601913550, 'endpoints': [{'id_device': 1589883539, 'picto': 'picto_window', 'name': 'Battant droit ', 'anticipation_start': False, 'last_usage': 'window', 'id_endpoint': 1589883539, 'first_usage': 'window'}, {'id_device': 1589883713, 'anticipation_start': False, 'picto': 'picto_window', 'id_endpoint': 1589883713, 'first_usage': 'window', 'name': 'Battant gauche', 'last_usage': 'windowFrench'}, {'name': 'CG_DD_USAGE_WINDOWFRENCH_NEW 2', 'id_endpoint': 1589883816, 'picto': 'picto_window', 'anticipation_start': False, 'first_usage': 'window', 'last_usage': 'windowFrench', 'id_device': 1589883816}, {'first_usage': 'window', 'last_usage': 'window', 'id_device': 1589883930, 'id_endpoint': 1589883930, 'name': 'Fenêtre ', 'picto': 'picto_window', 'anticipation_start': False}, {'first_usage': 'hvac', 'last_usage': 'boiler', 'id_endpoint': 1589902721, 'picto': 'picto_thermometer', 'name': 'Séjour', 'id_device': 1589902721, 'anticipation_start': False}, {'picto': 'picto_window', 'first_usage': 'window', 'id_device': 1589884607, 'anticipation_start': False, 'last_usage': 'windowFrench', 'name': 'WC', 'id_endpoint': 1589884607}, {'id_device': 1589884784, 'picto': 'picto_window', 'name': 'Battant droit', 'first_usage': 'window', 'anticipation_start': False, 'id_endpoint': 1589884784, 'last_usage': 'windowFrench'}, {'picto': 'picto_window', 'first_usage': 'window', 'last_usage': 'windowFrench', 'name': 'Battant gauche ', 'id_endpoint': 1590779132, 'anticipation_start': False, 'id_device': 1590779132}, {'first_usage': 'window', 'last_usage': 'window', 'anticipation_start': False, 'id_endpoint': 1589885658, 'id_device': 1589885658, 'name': 'Battant droit', 'picto': 'picto_window'}, {'first_usage': 'window', 'last_usage': 'window', 'anticipation_start': False, 'name': 'Battant droit', 'picto': 'picto_window', 'id_endpoint': 1589885757, 'id_device': 1589885757}, {'last_usage': 'window', 'id_device': 1589885896, 'picto': 'picto_window', 'name': 'Battant droit', 'anticipation_start': False, 'id_endpoint': 1589885896, 'first_usage': 'window'}, {'picto': 'picto_window', 'anticipation_start': False, 'name': 'Battant gauche', 'last_usage': 'window', 'id_device': 1589886026, 'first_usage': 'window', 'id_endpoint': 1589886026}, {'id_device': 1589886161, 'picto': 'picto_window', 'anticipation_start': False, 'id_endpoint': 1589886161, 'first_usage': 'window', 'name': 'Battant droit', 'last_usage': 'window'}, {'id_device': 1589902483, 'name': 'Chambre d’amis', 'first_usage': 'hvac', 'picto': 'picto_thermometer', 'id_endpoint': 1589902483, 'last_usage': 'boiler', 'anticipation_start': False}, {'id_device': 1589902673, 'name': 'Etage', 'last_usage': 'boiler', 'id_endpoint': 1589902673, 'first_usage': 'hvac', 'anticipation_start': False, 'picto': 'picto_thermometer'}, {'name': 'Porte ', 'id_device': 1590768079, 'anticipation_start': False, 'picto': 'picto_belmdoor', 'last_usage': 'belmDoor', 'first_usage': 'belmDoor', 'id_endpoint': 1590768079}, {'first_usage': 'window', 'name': 'Battant droit', 'id_endpoint': 1590827319, 'anticipation_start': False, 'picto': 'picto_window', 'last_usage': 'windowFrench', 'id_device': 1590827319}], 'moments': [], 'old_tycam': False}
Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
msg_data error in parsing !
1589883539
msg_data error in parsing !
1589883816
msg_data error in parsing !
1589883930
msg_data error in parsing !
1589884607
msg_data error in parsing !
1589884784
msg_data error in parsing !
1589885658
msg_data error in parsing !
1589885757
msg_data error in parsing !
1589885896
msg_data error in parsing !
1589886026
msg_data error in parsing !
1589886161
msg_data error in parsing !
1589902483
msg_data error in parsing !
1589902673
msg_data error in parsing !
1589902721
msg_data error in parsing !
1590768079
msg_data error in parsing !
1590779132
msg_data error in parsing !
1590827319
Incoming data parsed successfully !
>>>>>>>>>> Sending to tydom client..... POST /refresh/all
<<<<<<<<<< Receiving from tydom_client...
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
msg_data error in parsing !
1589902483

Hi, I don’t have the devices at home, could you please try to start the python script ? To pinpoint the line where the error is…

And just to know, does the others devices types work even with the error ?

hi,

i have only 14 doors detector and 3 thermostats, so all are not working unfortunately, checking in parallel with bbo76 for debuging

Hi,

First : thanks a lot for all the effort put in this addon :slight_smile:

I am new to HASS and tried to install the tydom2mqtt addon so that I can play around with my X3D equipments :smiley:

For now I have installed HASS on a raspberry pi 4. I have installed the MQTT and the Mosquitto broker addon. Then I have installed the tydom2mqtt addon and modified the TYDOM_MAC, TYDOM_IP and TYDOM_PASSWORD in the configuration tab .
I have also modified the mqtt properties, with :

MQTT_HOST: localhost
MQTT_USER: mosquitto #(user I have created in HASSIO configuration/users menu)
MQTT_PASSWORD: xxxxxx

(I left the other properties unchanged)

But I’ve got an error when I restart the addon (see below).

I am sure I have missed something in my setup but I don’t know what or where to look :frowning:

So if someone can help me :smiley:

My logs :

[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] 00-banner.sh: executing... 
-----------------------------------------------------------
Add-on: Tydom2MQTT - Beta
Link between a Delta Dore's Tydom 1.0 Hub and and a MQTT broker, unofficial of course, hassio addon version
-----------------------------------------------------------
 Add-on version: release_0.94b
 You are running the latest version of this add-on.
parse error: Expected string key before ':' at line 1, column 4
[17:03:50] ERROR: Unknown HTTP error occured
 System:   (armv7 / raspberrypi4)
 Home Assistant Core: 0.117.2
 Home Assistant Supervisor: 2020.10.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
Log level is set to INFO
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
Starting /opt/tydom2mqtt/main.py

then a few seconds later :

1604425191: Socket error on client <unknown>, disconnecting.
1604425198: New connection from 172.30.32.1 on port 1883.
[INFO] found mosquitto on local database
1604425198: New client connected from 172.30.32.1 as 63fe4315-tydom2mqtt-hassio2020-11-03 18:39:58.180843 (p5, c1, k60, u'mosquitto').
1604425246: Socket error on client 63fe4315-tydom2mqtt-hassio2020-11-03 18:39:58.180843, disconnecting.
1604425253: New connection from 172.30.32.1 on port 1883.
1604425253: New client connected from 172.30.32.1 as 63fe4315-tydom2mqtt-hassio2020-11-03 18:40:53.005635 (p5, c1, k60, u'mosquitto').
1604425368: Socket error on client 63fe4315-tydom2mqtt-hassio2020-11-03 18:40:53.005635, disconnecting.
1604425372: New connection from 172.30.32.1 on port 1883.
[ERROR] Auth error with mqtt_user

EDIT :
after several minutes I get these messages in the logs :

>>>>>>>>>> Sending to tydom client..... POST /refresh/all
<<<<<<<<<< Receiving from tydom_client...
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
msg_data error in parsing !
1541154049
Incoming data parsed successfully !

So something good is happening :smile: but don’t know what I should do next…

Yes, i tried both local IP and mediation.tydom.com.
I succeed also to launch docker image with the rights parameters (without passing through HASSIO) and the result is quite the same than @tonioa

TYDOM WEBSOCKET CONNECTION INITIALISING....                     
Building headers, getting 1st handshake and authentication....
Upgrading http connection to websocket....
Attempting websocket connection with tydom hub.......................
Host Target :
mediation.tydom.com
Tydom Client is connected to websocket and ready !
Requesting 1st data...
>>>>>>>>>> Sending to tydom client..... GET /info
##################################
##################################
>>>>>>>>>> Sending to tydom client..... POST /refresh/all
>>>>>>>>>> Sending to tydom client..... GET /configs/file
>>>>>>>>>> Sending to tydom client..... GET /devices/data
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : Info detected
Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
Cannot parse response !
Error :  string indices must be integers

MY JSON (do you need it ???)

Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
msg_data error in parsing !
1590338188


JSON (without real IDs / pass) could be useful yes !

Here it is

{'endpoints': 
  [
    {'id_device': xxxxxxxxxx, 'first_usage': '', 'id_endpoint': xxxxxxxxxx, 'picto': '', 'name': 'équipement non géré', 'last_usage': ''}
    , {'name': 'équipement non géré', 'id_endpoint': xxxxxxxxxx, 'id_device': xxxxxxxxxx, 'picto': '', 'first_usage': '', 'last_usage': ''}
    , {'id_endpoint': xxxxxxxxxx, 'last_usage': '', 'first_usage': '', 'id_device': xxxxxxxxxx, 'picto': '', 'name': 'équipement non géré'}
    , {'picto': '', 'last_usage': '', 'name': 'équipement non géré', 'first_usage': '', 'id_endpoint': xxxxxxxxxx, 'id_device': xxxxxxxxxx}
    , {'name': 'Alarme', 'id_device': xxxxxxxxxx, 'picto': 'picto_alarm', 'first_usage': 'alarm', 'id_endpoint': xxxxxxxxxx, 'last_usage': 'alarm'}
    , {'picto': '', 'last_usage': '', 'name': 'équipement non géré', 'first_usage': '', 'id_endpoint': xxxxxxxxxx, 'id_device': xxxxxxxxxx}
    , {'id_device': xxxxxxxxxx, 'picto': '', 'name': 'équipement non géré', 'id_endpoint': xxxxxxxxxx, 'last_usage': '', 'first_usage': ''}
  ]

, 'os': 'ios'
, 'moments': []
, 'version_application': '3.8.1 (277)'
, 'id_catalog': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
, 'groups': [
  {'group_all': True, 'name': 'TOTAL', 'usage': 'light', 'id': xxxxxxxxxx, 'picto': 'picto_lamp'}
  , {'picto': 'picto_shutter', 'group_all': True, 'name': 'TOTAL', 'id': xxxxxxxxxx, 'usage': 'shutter'}
  , {'group_all': True, 'id': xxxxxxxxxx, 'picto': 'picto_awning_awning', 'usage': 'awning', 'name': 'TOTAL'}
]
, 'date': 1593174091
, 'scenarios': []
, 'old_tycam': True
, 'version': '1.0.1'}

The issue comes from the empty last_usage string. I think the last PR by Baptiste try to address the issue, did you try last update ?

Sorry @WiwiWillou, I didn’t saw your last message in time !
Just done the uodate and tried again, but it seems I have the same error :cry:
Here is what I get after the JSON

Incoming data parsed successfully !
<<<<<<<<<< Receiving from tydom_client...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Incoming message type : data detected
1590338188 not in dic device_name
1590338188 not in dic device_type
msg_data error in parsing !
1590338188
1590338189 not in dic device_name
1590338189 not in dic device_type
msg_data error in parsing !
1590338189

Hi, everybody,

Very good job. Thanks.

Im a newbie with HA, could you help me please ?
I use HAssio on a nuc.
How should i install this ? HACS ?

i have ever mosquitto.

Thanks a lot

SORRY I find :wink: with hassio, add the repository and goooo :slight_smile:

Hello @WiwiWillou,
I got some news for you because I succeed to get it work!
I didn’t understand why I got this issue :

Incoming message type : data detected
1590338188 not in dic device_name
1590338188 not in dic device_type
msg_data error in parsing !

Because by searching on the config file, i well found the device id and it is my alarm.
I saw that device_name.keys() and device_type.keys() was always empty and mainly, I noticed that the config json was considered as msg_type = ‘msg_data’ and not msg_type = ‘msg_config’
The JSON received start for me by id_catalog.
I changed your script like that

          if (("id_catalog" in first) or ("date" in first) or ("ios" in first)): #ios for tonioa case (maybe for all iOs users)
                print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
                print('Incoming message type : config detected')
                msg_type = 'msg_config'
          elif ("id" in first):
                print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>")
                print('Incoming message type : data detected')
                msg_type = 'msg_data'

Start with msg_config and add id_catalog.
Finally it detected config json and fill the array device regarding last_usage value !!!
I noticed also that if I add a scenario through my tydom app, the config json start with the scenario. So maybe, it will not enter in the right msg_type again…
Don’t know if I posted on the right place this post but can you update your script to have HA addon updated ?