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

Troubles sending values from HA to TA (conversion negative to unsigned failed) #69

Closed
harrywa81 opened this issue Oct 13, 2024 · 3 comments
Assignees

Comments

@harrywa81
Copy link

harrywa81 commented Oct 13, 2024

Hi,
as I'm new to GitHub and this project I wanted to say a "Hi" first of all to the masterpiece of this work, @DeerMaximum. Thank you so much for your hard work at this project and its surroundings, you are doing a great job. These additions to HA are exactly what I was looking for to further optimize my heat system! (sorry for the intro...)

After following the documentation, it was possible for me (with only little problems) to receive data from TA in HA. In the other direction, it is a bit more difficult for me. CoE v1 didn't work for me at all (the was an error in the debug-log, I try to reproduce it and post it in a followup). After switching to Coe v2, some values were received in my UVR610 CAN inputs, but the values are wrong and mixed up. Furthermore, opening the "page" from the newly added virtual CAN devices showed weird characters or simply "Error".
Screenshot

I think there are many issues, some may be on my side (configuration fails) but I think I discovered at least one in the code. If I chose to send a "power value" (unit: W), there is an error in the log like this:

13.10.24-21:38:40 DEBUG httpserver(258): Send analog data to CMI with CoE version 2: values=[ValueTypeModelV2(channel=4, value=-3180.0, unit=69)] Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/ta-coe/ta_coe/httpserver.py", line 124, in _check_coe_version_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp_pydantic/view.py", line 36, in _iter return await getattr(self, method_name.lower())() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp_pydantic/view.py", line 132, in wrapped_handler return await handler(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/ta-coe/ta_coe/httpserver.py", line 267, in post coe.send_analog_message(data_to_send) File "/opt/ta-coe/ta_coe/coe/v2/coeserver_v2.py", line 66, in send_analog_message self.cmi_ip, self._builder.build_analog_message(chunk) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/ta-coe/ta_coe/coe/v2/message_builder.py", line 46, in build_analog_message return self._build_header(len(updated_values)) + self._build_value_block( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/ta-coe/ta_coe/coe/v2/message_builder.py", line 30, in _build_value_block value = self._int_to_bytes( ^^^^^^^^^^^^^^^^^^^ File "/opt/ta-coe/ta_coe/coe/v2/message_builder.py", line 11, in _int_to_bytes return int.to_bytes(integer, length=length, byteorder="little") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OverflowError: can't convert negative int to unsigned

Furthermore a request, category "nice-to-have":
In the configuration of the CoE-integration, there is no information which data is bound to which channel. If it would be there, it would make assigning data to the correct CAN input on the TA side more easier. So I have to "guess" from top to down which is the correct channel. Or am I missing something?

Thank you!

PS: (better english or german?)

@harrywa81
Copy link
Author

as written above, I'd like to add some more logs:

CoE v2, sending some "energy" values, which are plausibly sended in the CoE addon, but receiving in UVR610 results in totally wrong numbers.

13.10.24-22:15:12 DEBUG udpserver(40): Send message to 10.0.0.33:5442 : b'\x02\x00\x0c\x01(\x00\x00+\x01\x00\x00\x00'
13.10.24-22:15:20 DEBUG httpserver(258): Send analog data to CMI with CoE version 2: values=[ValueTypeModelV2(channel=2, value=56820.0, unit=11)]
13.10.24-22:15:20 DEBUG udpserver(40): Send message to 10.0.0.33:5442 : b'\x02\x00\x0c\x01(\x01\x01\x0b\x88\xab\x08\x00'
13.10.24-22:15:21 DEBUG httpserver(258): Send analog data to CMI with CoE version 2: values=[ValueTypeModelV2(channel=3, value=72275.0, unit=11)]
13.10.24-22:15:21 DEBUG udpserver(40): Send message to 10.0.0.33:5442 : b'\x02\x00\x0c\x01(\x02\x01\x0b>\x07\x0b\x00'
13.10.24-22:15:21 DEBUG httpserver(258): Send analog data to CMI with CoE version 2: values=[ValueTypeModelV2(channel=1, value=22385.0, unit=11)]

Screenshot2

and now with CoE v1, sending the same Energy values, results in an Overflow during sending:

13.10.24-22:11:16 DEBUG httpserver(218): Send analog data to CMI with CoE version 1: values=[ValueTypeModel(value=22385.0, unit=11), ValueTypeModel(value=56820.0, unit=11), ValueTypeModel(value=72275.0, unit=11), ValueTypeModel(value=-5576.0, unit=69)] page=1
Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ta-coe/ta_coe/httpserver.py", line 124, in _check_coe_version_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp_pydantic/view.py", line 36, in _iter
    return await getattr(self, method_name.lower())()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp_pydantic/view.py", line 132, in wrapped_handler
    return await handler(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ta-coe/ta_coe/httpserver.py", line 220, in post
    coe.send_analog_message(body.page, self._to_builder_model(body.values))
  File "/opt/ta-coe/ta_coe/coe/v1/coeserver_v1.py", line 70, in send_analog_message
    self.cmi_ip, self._builder.build_analog_message(page, values)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/ta-coe/ta_coe/coe/v1/message_builder.py", line 29, in build_analog_message
    return struct.pack(
           ^^^^^^^^^^^^
struct.error: 'h' format requires -32768 <= number <= 32767

@DeerMaximum DeerMaximum self-assigned this Oct 14, 2024
@DeerMaximum
Copy link
Owner

DeerMaximum commented Oct 26, 2024

Hi,

foremost it is normal that when you try to open the CoE Node over the web interface that you get this cryptic window.
The error with CoE V1 is known and one of the reasons V2 was created. The new version support a wider value area.

About your wrong energy values, can you take a look at the CoE state page in the C.M.I.: http://IP/#status_coe.cgi
There you can see with values are sent to the C.M.I. I have tried to send the values my self, and they were correct.

coe_value

And about your “nice-to-have” request, you can see the order in the attributes of the binary_sensor.coe_send_value_state entity. Also with #67 there will be a better UI.

@harrywa81
Copy link
Author

Hello @DeerMaximum , thank you very much for the update and the explanations.

  • I didn't realize that "CoE Status" site before, nice!! The shown values there look correct, also for large values, thank you, thats great!
  • I will just ignore that fancy CoE node then in the "CAN overview", kinda strange
  • This binary_sensor with the attributes is awesome, there you can see the channels clearly. Didn't know that before too!

grafik

Great work, thank you so much. If you need a tester for new features or so, gime a shout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants