Bepacom-Raalte / Bepacom-BACnet-IP-Integration

Bepacom BACnet Integration Repository
Apache License 2.0
12 stars 2 forks source link

Values are not getting updated in HomeAssistant #18

Open CV-Private opened 4 months ago

CV-Private commented 4 months ago

I've been able to successfully install the Bepacom-BACnet-IP-Installation. It found my GTW-21 BACnet device from the heatpump manufacturer Brötje (BDR Thermea Group). It is a BACnet certified device, to which I can connect with YABE normally.

I'm able to see the Present Values in the HomeAssistant Entities.

However, the values are not getting updated at all. It look like they have been read once, and now they're frozen forever. This is what I see in HA. It would be expected, though, that the temperature value would change very dynamically over time.

image

What did I miss to configure? Any help would be much appreciated! Best regards, Christian

Bepacom-Raalte commented 4 months ago

Hey Christian,

I think the configuration should be alright. Might be that there's a little bug somewhere.

Could you tell me which add-on and integration versions you're using? In the add-on, if you look at the web UI, do values change in there? Do you get any errors in the logs? Either in Home Assistant or in the add-on?

Answers on these questions can help narrow down what's causing these issues.

CV-Private commented 4 months ago

Dear Bepacom, thanks for your swift response!

Here's the HA version information:

image

The values are not getting updated anywhere, neither in the WebUI nor in the visualization. Below is a screenshot that shows the same 47,1°C value that is shown in the flat chart in my first post. The value is unchanged since the last HA restart.

image

Attached is the Debug log, and I do see Errors related to the Bacnet refresh. Maybe that helps to pinpoint the reason? Note that I deleted two days of logging to reduce the file size.

CV_home-assistant_bacnet_interface_2024-03-05T08-06-43.071Z.log

An another note: how's the refresh actually done? Is the Bepacom integration using the COV (Change of Value) method, or is it polling the values in regular intervals? If it would poll in intervals: where can the interval be configured? I see the same set of error logs every minute. Polling intervals of 1 min might be OK for certain purposes, but in case of more dynamic values, it should be possible to configure a higher update rate if COV wouldn't be possible.

Bepacom-Raalte commented 4 months ago

Hey Christian,

By default, the add-on uses CoV. If you want to disable this and continue by polling, you could do the following:

afbeelding

This will set the polling time to 15 seconds and no CoV subscriptions will be made. You could set it even faster, but it might congest your network.

Did you encounter any errors in the add-on logs? I think the issue originates from the add-on. Are you using the dev version of the add-on?

CV-Private commented 4 months ago

Thanks, that's good to know! CoV is certainly my preference.

I'm not using the dev version of the add-on. This is the set of errors that occurs each minute in the log file:

2024-03-05 09:05:51.410 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 256, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 412, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 183, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 989, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1110, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1047, in __async_calculate_state
    state = self._stringify_state(available)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 995, in _stringify_state
    if (state := self.state) is None:
                 ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/sensor/__init__.py", line 547, in state
    native_unit_of_measurement = self.native_unit_of_measurement
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bacnet_interface/sensor.py", line 137, in native_unit_of_measurement
    self.device_class == SensorDeviceClass.TEMPERATURE
    ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/bacnet_interface/sensor.py", line 111, in device_class
    in self.coordinator.data.devices[self.deviceid]
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'devices'
2024-03-05 09:05:51.417 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/bacnet_interface/coordinator.py", line 65, in listen
    await self.interface.listen(callback=self.async_set_updated_data)
  File "/usr/local/lib/python3.12/site-packages/aioecopanel/aioecopanel.py", line 71, in listen
    message = await self._client.receive()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_ws.py", line 232, in receive
    raise RuntimeError("Concurrent call to receive() is not allowed")
RuntimeError: Concurrent call to receive() is not allowed
Bepacom-Raalte commented 4 months ago

Could you also post the add-on logs? Maybe there's something useful in there.

CV-Private commented 4 months ago

Where do I find those add-on logs?

Bepacom-Raalte commented 4 months ago

On the add-on page, next to the configuration tab, there's a Log tab. In there you should be able to see if there's anything odd happening.

afbeelding

CV-Private commented 4 months ago

Ok, got it! Here's that log as a txt file:

Bepacom-BACnet-Log_2024-03-06.txt

Note that the Device ID 1507482 in this log is the Yabe Room Simulator that I used for some testing.

My real BACnet Device GTW-21 has Device ID 1

image

CV-Private commented 4 months ago

Below is the error message in HA when I'm trying to write to setpoint parZoneRoomManualSetpoint-3 AV_1688:

image

The object is writeable, as per the GTW-21 documentation:

image

This is how the object looks like in Yabe, from where I can change the Present Value:

image

Bepacom-Raalte commented 4 months ago

Could you try the following for me?

In HACS please redownload the integration and then select the main version. This is the latest version pushed to GitHub. I hope this should at least solve the NoneType issue.

afbeelding

CV-Private commented 4 months ago

Some progress: after the update and HA restart, I am initially able to write the value. If no errors occur, then the value is getting accepted by the controller, and changes are visible in the HA graph:

image

However, after several successful write actions, the same NoneType error occurs again, and new values are not getting written before I restart HA.

There's not much to see in the Bepacom log:


2024/03/07 10:26:48 [info] 325#325: *359 client 127.0.0.1 closed keepalive connection
ERROR:    Disconnected...

2024/03/07 10:36:48 [info] 325#325: *368 client 127.0.0.1 closed keepalive connection
2024/03/07 10:37:20 [info] 325#325: *370 client 127.0.0.1 closed keepalive connection
2024/03/07 10:37:52 [info] 325#325: *372 client 127.0.0.1 closed keepalive connection
2024/03/07 10:38:38 [info] 325#325: *374 client 127.0.0.1 closed keepalive connection
ERROR:    Disconnected...

There are some errors in the HA log, though:

Bepacom-BACnet-Log_2024-03-07.txt

Bepacom-Raalte commented 4 months ago

So it seems the integration is at fault. For some reason the data gets lost. After a restart of Home Assistant it works again for a little bit and then stops? Is there a consistent way to get it to crash like this

Could you reinstall through HACS again? I pushed some changes again for the main.

CV-Private commented 4 months ago

In the meantime, I made the following steps:

Observations: 1) Values written from HA are changing the setting in my room controller (good).

2) The Present Value in the HA entity is not getting updated when I change the temperature setting on my room controller (not good).

3) Changes that I make in HA with the up/down buttons are being queued and sequentially processed, which makes the process quite slow. For example, when I press the up-button 10 times to adjust by +1°C, then all ten 0.1°C steps are being written, one after another, which takes quite some time. It would be better to only send the latest update to the BACnet and delete previous commands from the queue as long as they're still unprocessed.

4) The latest repository update did NOT yet fix the NoneType error that occurs after a while. Unfortunately, I have not been able yet to identify a trigger for the failure. So far, it occurred at some point after every reboot, but not at a specific time or after a particular action. If the failure occurred, then I could always resolve it by restarting HA. That at least is 100% reproducible.

5) I noticed in the Bepacom log that there are many log entries like below. Could that indicate a problem with the data-base size?

ERROR: Error while subscribing to device,1, analog-value,7505: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,7506: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,7507: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21001: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21020: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21021: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21022: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21023: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21024: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21025: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21026: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21027: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21028: resources: no-space-to-add-list-element ERROR: Error while subscribing to device,1, analog-value,21030: resources: no-space-to-add-list-element

GravySeal commented 4 months ago

In the add-on, I made some changes so logging can be exported. Could you, in the add-on store, press the button "Check for updates"?

image

After waiting for a couple of seconds, on the add-on page, press Rebuild.

image

If everything went correctly, in the configuration there should be a new setting available called "Log Export". Please enable this to get logs written to Home Assistant's /share folder as well as make the logs downloadable through the web UI.

image

This way we're not bound to Home Assistant's logging limit and I can see a little more detailed what's actually happening. When you run the add-on until the integration fails, please export those logs through the web UI and paste the file here. Hopefully everything will be clear then...

CV-Private commented 4 months ago

I just installed the Developer Version 1.3.4 and turned the Logs On. I also changed the logging level to Debug. I'm wondering now where to find the /share folder and how to export logs through the webUI. Do you mean this Protocol tab?

image

Unfortunately, I'm having big problems with the new add-on version. Since I loaded it, I'm not able to connect to the GTW-21 and the Add-On shows a configuration error. This is new and I didn't see that with version 1.3.3:

image

Here's a log that I got after one of the initial restarts:

Bepacom-BACnet-Log_2024-03-09.txt

I tried to change the configuration without success. After some more restarts, I saw in the log that the Add-On did get some device information from the GTW-21, but the entities were still not working:

Bepacom-BACnet-Log_2024-03-09b.txt

The GTW-21 Entities had a red circle and were not usable in the Dashboard. After many restarts and attempt to reset/restore the configuration, I deleted the GTW-21 device and all entities from HA and removed and reinstalled the Add-On.

Now it doesn't even recognized the GTW-21. The Who-Is requests from 192.168.66.69 came from a Node-Red server in my network. I turned that off meanwhile.

I'm not sure what else I could do, as I can't establish the connection from Add-On v1.3.4 to the GTW-21.

GravySeal commented 4 months ago

Hmm... A little bit of a difficult situation, but to get the logs the way I mean is through the web UI. When pressing this button, it should download the log up until that point in debug level. No need to configure that in the add-on.

image

As you don't detect the GTW-21 anymore, it might be the best to reset the configuration to default, or at least to when it worked. Before you try again, please check for updates and then rebuild again. I made a quick change that'll give me ever so slightly more info.

CV-Private commented 4 months ago

Ok, got it now what you mean with WebUI! :-) The log download works.

This morning, I completely removed and reinstalled the Developer v1.3.4 Add-On, including reloading, rebuilding and rebooting and resetting to defaults.

Unfortunately, it was still not adding the GTW-21, but there were new errors in the log:

Bepacom-BACnet-Log_2024-03-10.txt

After removing v1.3.4 and installing the regular version 1.3.3, the Add-On has found the GTW-21 device and all 1279 entities, and I can use my test object parZoneRoomManualSetpoint-3, AV_1688:

image

Here are its properties:

image

So, something must have been broken from v1.3.3 to 1.3.4...

CV-Private commented 4 months ago

By the way, as I'm seeing errors of type "unknown-property" in the log, I'd like to share with you the Configuration Manual and EDE file that came with the GTW-21 module. Maybe there's useful information in it?

Configuration Manual (EN FR DE ES IT PT NL) - NOT-7763253-02.pdf

FG040D_X_00_EDE R1.2.1.csv

GravySeal commented 4 months ago

The "unknown-property" error is not so important. It's there because the add-on is asking a specific set of properties to every device. Some devices don't have every property, so it'll just return that.

As for the bigger issue, could you maybe check for updates and rebuild again? I think we should be able to get a little further again.

CV-Private commented 4 months ago

Progress! The updated Developer Add-On 1.3.4 has found the GTW-21 and all entities.

Initially, I was able to set the parZoneRoomManualSetpoint-3, AV_1688.

However, after a couple of minutes, the NoneType error ocurred again.

I downloaded the log file and it was super-big (>980 MB), probably because I still had the debug level on.

I noticed that at the end of the log file, there are a 515 error messages about "no-space-to-add-list-element".

Below are the last couple of lines from the debug log.

.
.
.
ERROR->BACnetIOHandler.py->create_subscription_task:    Error while subscribing to device,1, analog-value,21027: resources: no-space-to-add-list-element
ERROR->BACnetIOHandler.py->create_subscription_task:    Error while subscribing to device,1, analog-value,21028: resources: no-space-to-add-list-element
ERROR->BACnetIOHandler.py->create_subscription_task:    Error while subscribing to device,1, analog-value,21030: resources: no-space-to-add-list-element
INFO->h11_impl.py->send:    172.30.32.2:0 - "GET /webapp HTTP/1.0" 200
INFO->h11_impl.py->send:    172.30.32.2:0 - "GET /css/styles.css HTTP/1.0" 200
INFO->h11_impl.py->send:    172.30.32.2:0 - "GET /apiv1/json HTTP/1.0" 200
INFO->websockets_impl.py->asgi_send:    ('172.30.32.2', 0) - "WebSocket /ws" [accepted]
INFO->server.py->handshake:    connection open
ERROR->webAPI.py->websocket_endpoint:    Disconnected...

INFO->server.py->handler:    connection closed
DEBUG->webAPI.py->websocket_writer:    Websocket writer cancelled: 

Would it be possible that the NoneType error messages are occurring from the point in time when the Add-On runs out of resource when building the list?

CV-Private commented 4 months ago

PS: how can I delete the big log file?

GravySeal commented 4 months ago

If you download the samba add-on, you can add the /share directory as a network location. In there you can delete the log files. I recommend only turning on the export logs option if you're running the add-on shortly.

The no-space-to-add-list-element comes from the BACnet controller, basically telling us it's CoV list is full. It might be worth it to try and see if a reboot will resolve this error?

CV-Private commented 4 months ago

Rebooting the GTW-21 is a bit of an effort, therefore I firstly tried something else instead. I set all subscriptions in the Add-On Konfiguration to false and restarted it. Now I don't see those resource-errors in the log anymore.

Then I subscribed manually in the Add-On Web-UI to analog-value 1688:

image

After the subscription, I don't get the NoneType error anymore, and I see the Present_Value in the Dashboard getting updated when I change the temperature on my room controller. Very good! :-)

I have also confirmed that the inactive subscription is the trigger for the NoneType error.

When I remove the subscription, or when it expires, then the NoneType error occurs. When I subscribe to the object, then the NoneType error does NOT occur.

However, it is strange that the Add-On WebUI still shows the object as "subscribed" after the lifetime expired. It doesn't seem to renew the subscription. To resolve the NoneType error, I have to remove the subscription and re-subscribe again.

How can I establish a permanent subscription with infinite lifetime, or advise the Add-On to renew the subscription upon expiry?

Here are the latest lines of the Protokoll and there are some error messages:

2024/03/10 18:50:07 [warn] 325#325: *90 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/7/00/0000000007 while reading upstream, client: 172.30.32.2, server: , request: "GET /webapp HTTP/1.1", upstream: "http://127.0.0.1:7813/webapp", host: "192.168.66.62:8123", referrer: "http://192.168.66.62:8123/hassio"
ERROR->webAPI.py->websocket_endpoint:    Disconnected...

2024/03/10 18:50:30 [info] 325#325: *90 client 172.30.32.2 closed keepalive connection
2024/03/10 18:50:47 [info] 325#325: *95 client 172.30.32.2 closed keepalive connection
2024/03/10 18:51:42 [info] 325#325: *98 client 172.30.32.2 closed keepalive connection
2024/03/10 18:52:06 [info] 325#325: *102 client 127.0.0.1 closed keepalive connection
2024/03/10 18:55:31 [warn] 325#325: *104 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/8/00/0000000008 while reading upstream, client: 172.30.32.2, server: , request: "GET /webapp HTTP/1.1", upstream: "http://127.0.0.1:7813/webapp", host: "192.168.66.62:8123", referrer: "http://192.168.66.62:8123/hassio"
ERROR->webAPI.py->websocket_endpoint:    Disconnected...

2024/03/10 18:56:02 [info] 325#325: *104 client 172.30.32.2 closed keepalive connection
2024/03/10 18:56:48 [warn] 325#325: *111 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/9/00/0000000009 while reading upstream, client: 172.30.32.2, server: , request: "GET /webapp HTTP/1.1", upstream: "http://127.0.0.1:7813/webapp", host: "192.168.66.62:8123", referrer: "http://192.168.66.62:8123/hassio"
ERROR->webAPI.py->websocket_endpoint:    Disconnected...

ERROR->BACnetIOHandler.py->create_subscription_task:    Error while subscribing to device,1, device,1: object: optional-functionality-not-supported
2024/03/10 18:57:30 [info] 325#325: *111 client 172.30.32.2 closed keepalive connection
2024/03/10 18:58:39 [warn] 325#325: *121 an upstream response is buffered to a temporary file /var/lib/nginx/tmp/proxy/0/01/0000000010 while reading upstream, client: 172.30.32.2, server: , request: "GET /webapp HTTP/1.1", upstream: "http://127.0.0.1:7813/webapp", host: "192.168.66.62:8123", referrer: "http://192.168.66.62:8123/hassio"
ERROR->webAPI.py->websocket_endpoint:    Disconnected...

2024/03/10 18:59:18 [info] 325#325: *121 client 172.30.32.2 closed keepalive connection
2024/03/10 18:59:52 [info] 325#325: *131 client 172.30.32.2 closed keepalive connection
2024/03/10 19:00:14 [info] 325#325: *135 client 127.0.0.1 closed keepalive connection
Bepacom-Raalte commented 3 months ago

It seems there's a problem with the CoV subscriptions then. The CoV lifetime is a little difficult to track. I've tried it before, but it just caused a lot of slowdowns and other problems. Not every device supports permanent CoV subscriptions, so I can't really default to that.

It's interesting that it suddenly works if you manually resubscribe. Could you perhaps paste the logs where you run it for a little bit until you get the NoneType issue again? Maybe I could see something in there that can help us figure it out.

As for the errors in your previous log (Protokoll), these are normal responses. The disconnect happens when you close the web page, as there's a websocket disconnecting in the background.

CV-Private commented 3 months ago

I'll try to capture the logs in HA. Is there any way for turning the logging On and Off without restarting the add-on? At each restart, the add-on scans all datapoints and the log gets huge (hundreds of MB), but since we're only interested in the last part of the log after the enumeration has been completed, I'm trying to find a less time consuming and data hungry method for obtaining the needed logs.

In the meantime I CoV-subscribed in Yabe to the analog-value 1688. Since it's a set point, the value won't change unless I'd change it manually. In the plot below, you see a change from 22°C to 22.5°C that I made on the room controller.

Interestingly, there's a new reading of the value every minute, even though the value didn't change. There's no 1 min interval configured in Yabe.

image

I don't know what triggers the 1 minute update, i.e. whether it's being pushed by the GTW-21 or polled by Yabe. I just found that the standard CoV Lifetime setting in Yabe is 120s:

image

What I can also tell is that I had Yabe running for days, and the subscription didn't stop.

I didn't find a ways for subscribing in the Add-On with the polling method instead of CoV. Is polling in regular intervals supported by the Add-On?

Bepacom-Raalte commented 3 months ago

Yabe has a very short subscription time of 120 seconds. These intervals are when Yabe resubscribes. Polling in the add-on can be done by setting the update interval option to a short interval, like 15 seconds or so. If you set all the CoV options to off in the add-on, do you get NoneType errors then? Might be worth it to try shorter CoV lifetimes in the add-on. Maybe it could give less errors.

CV-Private commented 3 months ago

1) Yes, I'm getting NoneType errors in the Add-On when all subscriptions are removed. In this case, the object's PresentValue is not getting updated in the Dashboard, and all write attempts fail with the NoneType error.

2) I tried 120s CoV lifetime in the Add-On before, but without seeing a difference. I'm not sure exactly how long it takes before the NoneType error occurs after re-subscribing. Even with long lifetime values, it didn't take longer than a couple of minutes.

3) I don't see any option in the Web-UI of the Add-On for configuring the subscrition for CoV or Polling. How can I do that? Just by leaving Lifetime empty?

CV-Private commented 3 months ago

My Add-On is currently in a weird state after I enabled Debug Log Export and restarted HA.

I see the device and all entities in the WebUI, and I can write to Analog_Value 1688. The values are being accepted by GTW-21, as I can see in Yabe:

image

image

However, the entity is not available in HA, even if I subscribe to the object in the WebUI:

image

The two write actions (setting the value to 23°C and to 24°C do neither appear in the Protocol nor in the Log file. Here are the last lines of the Log:

{'objectIdentifier': ('positiveIntegerValue', 7468), 'objectType': <ObjectType: positive-integer-value>, 'objectName': 'varCascadeApSerialNumber-9', 'description': 'EM228', 'presentValue': 0, 'statusFlags': <StatusFlags: out-of-service>, 'outOfService': 1, 'units': '255', 'eventState': 'normal', 'covIncrement': 1, 'minPresValue': 0, 'maxPresValue': 4294967295}, 'positiveIntegerValue:7481': {'objectIdentifier': ('positiveIntegerValue', 7481), 'objectType': <ObjectType: positive-integer-value>, 'objectName': 'varCascadeApErrorCustomCode-10', 'description': 'EM068', 'presentValue': 0, 'statusFlags': <StatusFlags: out-of-service>, 'outOfService': 1, 'units': '255', 'eventState': 'normal', 'covIncrement': 1, 'minPresValue': 0, 'maxPresValue': 4294967295}, 'positiveIntegerValue:7498': {'objectIdentifier': ('positiveIntegerValue', 7498), 'objectType': <ObjectType: positive-integer-value>, 'objectName': 'varCascadeApSerialNumber-10', 'description': 'EM228', 'presentValue': 0, 'statusFlags': <StatusFlags: out-of-service>, 'outOfService': 1, 'units': '255', 'eventState': 'normal', 'covIncrement': 1, 'minPresValue': 0, 'maxPresValue': 4294967295}}}
2024/03/12 17:45:42 [info] 325#325: *34 client 172.30.32.2 closed keepalive connection
INFO->BACnetIOHandler.py->do_WhoIsRequest:    Received Who Is Request from 192.168.66.69
INFO->BACnetIOHandler.py->do_WhoIsRequest:    Received Who Is Request from 192.168.66.69

I haven't had that situation before.

CV-Private commented 3 months ago

PS: After rebooting HA, that situation is resolved, which means: as before.

CV-Private commented 3 months ago

Not sure if that helps, but I tried to set the AV_1688 manually in the HA service _number.setvalue, using the HA Developer Tools.

Even when that is changing the value in the GTW-21, the service returns an Unknown Error, which seems to be suspicious:

image

Anyway, the success of this manual methods also depends on the age of the subscription, which still works only for a couple of minutes after removing/renewing the subscription to AV_1688 in the WebUI of the Add-On.

So, no matter whether the new value gets written to the BACnet or not, the Unknown Error occurs with every change of the value.

I did this test because the error in the Dashboard refers to the number.set_value service:

image

Unfortunately, I can't find any further details about the "Unknown Error".

CV-Private commented 3 months ago

I also found that I can always write to the AV_1688 presentValue from the WebUI of the Add-On, regardless of the subscription age. I would therefore conclude that the BACnet API generally works.

I don't know how to do a Read request from the WebUI. The presentValue in the WebUI does not automatically get updated after I wrote a new value.

With respect to the NoneType error in the Dashboard, I'm suspecting that problem is somewhere in the communication between the HA Entity and the BACnet API, and it must somehow depend on the subscription age.

Bepacom-Raalte commented 3 months ago

You're right about the communication between HA and the add-on. The add-on is basically an application that's run beside Home Assistant. The integration is Home Assistant itself and fetches the data from the add-on.

At first it requests all the BACnet data the add-on gathered and builds the entities from that. Then it tries to establish a websocket connection so data can be send whenever it's coming in. Each websocket message then updates the data displayed in Home Assistant.

What I suspect happens is that through some CoV update maybe data gets mangled. Then gets sent to Home Assistant and Home Assistant gets confused.

If you can check for updates and update the add-on, I made some changes. The logs now don't include websocket data anymore (which is the main cause for huge log size) as well as the size is limited to 10MB. The logs won't be saved in /share anymore, but inside the add-on and gets cleaned when the add-on restarts. The add-on also shouldn't send empty data anymore.

CV-Private commented 3 months ago

I installed the latest Addd-On version and I see new messages in the log. Here are the last parts of two of the latest log:

bacnet_addon_logs.txt

Those write actions were triggered from the Dashboard, and they confirm the discrepancy between the value to be written and the write result, for example:

DEBUG->main.py->writer_task: Writing: device,1, analog-value,1688, present-value, 25.0, 15 INFO->main.py->writer_task: response: Acknowledged INFO->main.py->writer_task: Write result: 23.0

bacnet_addon_logs2.txt

Those write actions were also triggered from the Dashboard while a subscription was still active. you can see the return values somewhat correlated to the write value, but the order is scrambled as I used the down-button with 0.1°C steps:

Bepacom-Raalte commented 3 months ago

Could you test if you still get the NoneType issue with default settings? I think that's a priority issue to tackle first.

If these logs are what you're getting out of the add-on without editing, you should check for updates and rebuild again.

The writing seems to work. When a write request has been acknowledged, it immediately sends out a read request to that property. It could be that the property gets read too fast for the GTW-21 to process the write, as it does go to the written value eventually.

CV-Private commented 3 months ago

1) I'm getting the NoneType error with default settings (priority 15), as well as with priority 8 in the Configuration. I'm using Priority 8 (Manual Operator), because that should be the right one for manual setpoints, and I know that this priority always works when I write the value from the WebUI. As you can see in the first log of my previous post, write requests with Priority 15 did not change the write result, therefore I'm assuming that this Priority is too low for setpoint AV_1688 of my device. This is my current setting:

image

2) The NoneType errors occur irrespective of the priority, and they start occurring in the Dashboard within 1-2 minutes after I newly subcribed to the object. When the NoneType errors occurs, then nothing gets written to the log file. In this case, it seems that the write request from the Entity is not being passed on to the BACnet Interface for whatever reason (probably related to the subscription).

3) You raised a good point about immediately reading the write results! I think the GTW-21 needs a little bit of processing time before it uses the new value, therefore a small delay should be added before checking the write result. I've seen configuration fields for "Delay" settings in BACnet interfaces for Node-Red, without knowing what they're supposed to do. It could very well be that the delay setting addresses exactly this point, i.e. the time the BACnet device needs for processing write requests.

Bepacom-Raalte commented 3 months ago

The reason writing through the integration doesn't work with the NoneType error is because for some reason it's data is gone.

The integration needs all the BACnet data in JSON format to work, and because of the subscriptions the data sent to the integration is unusable. Because of this the NoneType occurs, I think. When this data is gone, it has no idea what object is what entity and what entity is what object.

For this reason, the full logs of the add-on are valuable to me as I can see what's happening. If I see something odd happening, I can hopefully deduce where in the software it goes wrong.

Priority doesn't have an effect on CoV, but is important for overwriting BACnet present value's. 16 is the lowest priority, 8 is usually manual priority and 1 is emergency priority and thus should overwrite anything if it allows writing.

CV-Private commented 3 months ago

Let me know if there are any steps or test sequences that I can do to collect useful logs for you.

Bepacom-Raalte commented 3 months ago

If you map the startup sequence of your add-on and let it run for maybe 2 or 3 minutes, that should give me enough information for the next step hopefully.

Bepacom-Raalte commented 3 months ago

Did you perhaps get to try the dev version 1.4.0 already?

CV-Private commented 3 months ago

I have tried in the past days to configure a Sensor/Entity manually, but my YAML and Template knowledge is not yet sufficient for making it happen.

I just tried the Add-On v1.4.0, but the behavior is pretty much the same as before. It works for a short time when I manually subscribe, but soon thereafter, I'm getting the same NoneType error again. Attached is the downloaded Logfile.

bacnet_addon_logs_2024-03-19.zip

CV-Private commented 3 months ago

By the way, I am able to read the correct analogValue:1688 presentValue even without active subscription using the API, but due to insufficient programming knowledge, I'm struggling how to convert the response value to a number that the sensor entity can accept.

image

GravySeal commented 3 months ago

It's truly a massive amount of objects on your device... Do you have a specific selection of objects you want to read out? Do you wish to write as well? We might be better off with some blacklist or whitelist to only use objects we are interested in... In the API docs, there's an endpoint called /apiv1/json. Could you execute that for me, download and share the resulting file?

To get the API response translated to an entity in Home Assistant without using the integration, you can put the following in Home Assistant's Configuration.yaml:

sensor:
  - platform: rest
    name: GTW-21 - Temperature
    state_class: measurement
    unit_of_measurement: "°C"
    method: GET
    resource: http://97683af0-bacnetinterface:8099/apiv1/device:1/analogValue:1688/presentValue

This will create a sensor with Home Assistant's included RestAPI sensor You can adjust the name to anything you want. The resource is the address the data will be pulled from. The 97683af0-bacnetinterface:8099 part will change to 97683af0-bacnetinterface-dev:8099 when using the development version.

CV-Private commented 3 months ago

My plan is to read certain values from the GTW-21 and from other inputs, make decisions base on some rules and write values back, for example to Setpoints of the heating, or for switching the heatpump off while other power-hungry devices are on (for load-balancing). I'd guess this is what most HA users have in their mind as well.

I would only need a small number of GTW-21 objects - maybe 10 to 20 inputs, and 5 setpoints. Ideally, I'd like to be able to select in the Add-On for which of the available objects I need a HA Entity. Only the selected entities would then be created. Currently, I'm deactivating most of the HA entities after they have been created, and I set the automatic subscriptions in the Add-On configuration to false.

I have no idea about other BACnet devices, but I was blown away by the sheer number of objects. Here's the /apiv1/json response:

response_1710871301647.json

I just tried (again) to set up the sensor manually in the configuration.yaml, but I don't see any new entity or device in HA, unfortunately (restart was done).

image

GravySeal commented 3 months ago

There's really a huge amount of objects in this single device. It also doesn't help it doesn't support splitting up BACnet messages into smaller segments, as that speeds up reading the device significantly.

What I want to make now is a whitelist configuration option. For each object you want to read, you will have to put the device identifier as well as the object into a list. Then when starting the add-on, it should only read those. It'll take a little while to develop though.

For now, I recommend setting the update interval in the add-on configuration to at least 60 seconds. The reading takes a long time with so many objects, and I think it won't do the device or the add-on any good to poll faster than that. Then with all the CoV subscriptions off, hopefully it should at least be stable for the time being.

I don't see anything strange happening in the .json file you shared. Could you help me narrow done something in the integration? In a file editor, go to custom_components/bacnet_interface/coordinator.py, and adjust the function at the bottom as follows From:

313673836-8b876b5f-c60d-45c2-bb5b-6aa3d76d65d8 to:

313673744-5b2d795d-ff63-48ae-8254-863dbe0784f1

This should cut out the websocket and only update through json every minute. I wonder if the NoneType can appear this way.

CV-Private commented 3 months ago

Sure, will do, but my coordinator.py file looks slightly different (I have the Dev version installed):

image

Is it ok as follows?

image

GravySeal commented 3 months ago

Ah yeah, that should work too! Let me know if you get the NoneType issue this way after restarting Home Assistant.

CV-Private commented 3 months ago

The Whitelist plan sounds good!

My BACnet device has so many options because the heatpump can be installed in a large variety of use-cases with different options, such as:

Therefore it has so many parameters and variables, but only a small subset will normally be used in a typical configuration.

I don't know other BACnet devices, but I would expect that most manufacturers are also going the platform-based route with a ton of configuration options, therefore it's probably a smart idea to have whitelist for reducing the number of objects only to those that are relevant for the individual use-case.

The other objects will most likely never be used, or they might not have any effect at all if certain features are not even available in certain configurations. For example, I can't use the cooling feature at all, therefore any object related to cooling is irrelevant to me.

CV-Private commented 3 months ago

Good news! The NoneType error seems to be gone, and I can write from the HA Entity to the BACnet Setpoint without having to subscribe.

I do need to subscribe to the object, though, in order to get the HA entity value updated when I change the temperature setpoint on my room controller. Without subscription, the HA entity does not get updated, even if I wait much longer than the configured update interval.

An expired subscription is still not getting renewed automatically. I still have to remove the subscription and then subscribe again.

It would be great if polling intervals could be configured per entity. Some objects need a more frequent update rate than others. A global update interval setting may cause unnecessary data traffic. Polling is probably also more failsafe than relying on CoV subscription.

Bepacom-Raalte commented 3 months ago

Awesome, so the NoneType issue is related to the websocket connection between the add-on and integration. Could you install the integration v0.1.6b2 beta version through HACS? I'd like to see if there NoneType issue remains with this version.

CV-Private commented 3 months ago

I'm seeing the version v0.1.6b2 beta on Github and I can select and download it in HA but I'm struggling to get it installed.

I reloaded, rebuilt and restarted the Add-On and HA many times, but no matter what I do, I'm not able to get v0.1.6b2 being shown here:

image

Here's where I selected the Beta version for download in HACS:

image

What else do I need to do to run the beta?