Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Things network integration is not working in 2024.8.0 #123439

Closed
elji-lennart opened this issue Aug 9, 2024 · 20 comments · Fixed by #124370
Closed

The Things network integration is not working in 2024.8.0 #123439

elji-lennart opened this issue Aug 9, 2024 · 20 comments · Fixed by #124370

Comments

@elji-lennart
Copy link

The problem

The Things network can not start

failed trying to configure again

What version of Home Assistant Core has the issue?

2024.8.0

What was the last working version of Home Assistant Core?

2024.7.4

What type of installation are you running?

Home Assistant OS

Integration causing the issue

The things network

Link to integration documentation on our website

No response

Diagnostics information

2024-08-09 11:40:26.785 ERROR (MainThread) [homeassistant.components.thethingsnetwork.coordinator] Unexpected error fetching TheThingsNetwork_my-devices-elji data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 354, in _async_refresh
self.data = await self._async_update_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/thethingsnetwork/coordinator.py", line 51, in _async_update_data
measurements = await self._client.fetch_data()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ttn_client/client.py", line 57, in fetch_data
return await self.__storage_api_call(f"?last={fetch_last}&order=received_at")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ttn_client/client.py", line 104, in __storage_api_call
ttn_values[device_id] = ttn_parse(application_up)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ttn_client/parsers/init.py", line 23, in ttn_parse
return parser(uplink_data)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/ttn_client/parsers/sensecap.py", line 25, in sensecap_parser
if not decoded_payload["valid"]:
~~~~~~~~~~~~~~~^^^^^^^^^
KeyError: 'valid'

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Aug 9, 2024

Hey there @angelnu, mind taking a look at this issue as it has been labeled with an integration (thethingsnetwork) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of thethingsnetwork can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign thethingsnetwork Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


thethingsnetwork documentation
thethingsnetwork source
(message by IssueLinks)

@angelnu
Copy link
Contributor

angelnu commented Aug 9, 2024

@elji-lennart , could you please attach the payload with problem? It seems like the field valid us not present which was always there in the examples you sent previously.

I can add a simple toleration for the missing field but it would better to understand the problematic payload.

@elji-lennart
Copy link
Author

elji-lennart commented Aug 10, 2024 via email

@elji-lennart
Copy link
Author

elji-lennart commented Aug 11, 2024 via email

@angelnu
Copy link
Contributor

angelnu commented Aug 11, 2024

The problem is not related to the instalation (so reinstalling is not needed) but my library assuming there is always a valid field. I will release a patch for these cases. But having more examples of payload messages of these vendor would help to ensure that all other assumptions in the decoder are ok.

@lichtteil
Copy link
Contributor

lichtteil commented Aug 17, 2024

I think this happens when you use a SenseCAP device with a custom uplink parser. For example my GPS tracker T1000 is not recognised as such a device because of the way the device specific parser returns the payload.
I use the parser from here https://www.aeq-web.com/seeed-sensecap-t1000-lorawan-gps-tracker-ttn-payload-decoder/ to have TTN recognise the device as a GPS tracker with a location. That way it can also be used as a TTN mapper.

I guess the check if a device specific parser should be used has to consider not only the device brand but also how the payload is formed (which makes the check more complex).

Also maybe there should be a check if the key "valid" exists so that the component does not break if not: https://github.com/angelnu/thethingsnetwork_python_client/blob/main/src/ttn_client/parsers/sensecap.py#L25

@elji-lennart
Copy link
Author

elji-lennart commented Aug 17, 2024 via email

@lichtteil
Copy link
Contributor

2024.7.4 used ttn_client==1.0.0 and 2024.8.2 uses ttn_client==1.1.0. As you can see here: https://github.com/angelnu/thethingsnetwork_python_client/releases/tag/v1.1.0 the SenseCAP parser was introduced which now makes problems when custom payload parsers are used.

I fixed the issue for me by always using the default parser in https://github.com/angelnu/thethingsnetwork_python_client/blob/main/src/ttn_client/parsers/__init__.py#L19

I also added a key valid to my parsed payload and will try if it helps as soon as the TTN storage doesn't contain the "old" format without the valid key any more.

@angelnu
Copy link
Contributor

angelnu commented Aug 21, 2024

@lichtteil - could you please post an example of a decoded msg for a GPS? I could then add support for it in the SenseCAP parser in preparation to support device trackers in the home-assistant integration.

BtW: I just released ttn_client==1.2.0 which adds support for SenseCAP msgs without a valid field - I assume it is false when not found.

@tbrasser
Copy link

tbrasser commented Aug 25, 2024

Facing this same issue, modified the decoder to always add valid: true to decoded payload, but the integration is still not loading, possibly it fetches historical (wrong) decoded payloads too?

EDIT: really would like to be able to use custom parser even when adding the device to TTN via the end device repository. So maybe a fallback to the default parsing even for sensecap devices (etc) if the incoming decoded payload is not in the expected format?

EDIT: probably a workaround is to add the end device to TTN app without selecting the entry in their repository but adding all details manually (e.g this lib will think it's a diy device and use the default decoder) correct?

@angelnu
Copy link
Contributor

angelnu commented Aug 25, 2024

@tbrasser - could you please test with the dev version of HA or use the ttn_client version >= 1.2.0 ? It has the fix to tolerate (ignore) sepcap payloads without a valid field.

BTW: since @joostlek picked it as hotfix it should get also picked in a few days in HA core 2024.8.3.

About picking up the default parse - it is quite limited vs the ones dedicated to the device as it is not able to pick up any metadata on the device. This is not really great. So while adding the support to always pick up the default parser is technically easy to add (parameter to the client library, checkbox in the HA integration) I do not see the value of it. I think getting the custom parser to be more robust is better in the longer term. The problem is that since I do not know any Sensecap device I am only able to add testcases for the payloads other users post: this is why I was asking for more examples of payloads so I can add them and ensure the parser can cope and, later, even get the metadata.

In the custom integration that preceded this official one I had a menu for the integration to add the metada in HA. It was not "great" as the support for autogenerated UI in the HA config menus is limited but it is better than having to manually enter it for each device. I will open an issue to track how to implement the metadata settings.

@tbrasser
Copy link

Main reason to not want to use sensecaps parser is because it's not compatible with TTN device location.

If we get better data (for HA) using it then I can switch over np.

What do you want/need? I got 2x T1000-A tracker and can give you any output you want. :)

@elji-lennart
Copy link
Author

elji-lennart commented Aug 26, 2024 via email

@elji-lennart
Copy link
Author

elji-lennart commented Aug 26, 2024 via email

@tbrasser
Copy link

You need to add valid: true to the decoded payload.

@elji-lennart
Copy link
Author

elji-lennart commented Aug 26, 2024 via email

@angelnu
Copy link
Contributor

angelnu commented Aug 26, 2024

What do you want/need? I got 2x T1000-A tracker and can give you any output you want. :)

Just a decoded msg should be enough.

2024-08-26 07:48:40.780 WARNING (MainThread) [ttn_client.parsers.sensecap] Ignoring message without valid=true for device s2120: {'Humidity': 74, 'Illumination': 0, 'Pressure': 1013.8, 'Rain gauge': 0, 'Solar radiation': 0, 'Temperature': 14.9, 'UV': 0, 'Winddirection': 233, 'WinddirectionText': 'SV', 'Windspeed': 3.9}

Uhm, if I understood the spec the valid field should be present - if this is not the case I could default in the parser to valid=true when not found (perhaps this was introduced later?). Are you using the latest sensecap decoder from https://wiki.seeedstudio.com/SenseCAP_Decoder/ ?

@elji-lennart
Copy link
Author

elji-lennart commented Aug 26, 2024 via email

@elji-lennart
Copy link
Author

elji-lennart commented Aug 26, 2024 via email

@lichtteil
Copy link
Contributor

Anyone found a permanent workaround for this issue? Forking the component and the Python library seems to be to much work with maintaining/updating.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants