LordMike / MBW.BlueRiiot2MQTT

Utility to map between Blue Riiots pool API, and Home Assistant MQTT
47 stars 2 forks source link

Seperate weather updates as these can fail independently #48

Open ggggh opened 3 years ago

ggggh commented 3 years ago

Had this setting (BlueRiiot__ReportUnchangedValues: "true") working fine, but suddenly stopped working yesterday, and now unchanged values are no longer reported. This happened without any sort of change on my side, so assuming the API changed somehow?

ggggh commented 3 years ago

Magically working again now! I'll close, and will reopen if it happens again

LordMike commented 3 years ago

There is a risk that some of the logic conflicts. F.ex. I do a lot of comparisons to ensure I don't resend identical values (what this setting negates).

I can imagine a situation where where the same (new) value is read twice, there is a risk that the second read could be "identical" to the previous (also new) reading. Not sure how this plays out in code, but it seems likely that it either would be the case that the setting doesn't (always) work - or that it seems like it doesn't work.. :)

Do report back if it doesn't work.

ggggh commented 3 years ago

It started working again when I restarted the docker container, so I assume it had got itself in some sort of mess :) It had been running for over a month repeating those values well, so maybe some strange value combination suddenly triggered it...

ggggh commented 3 years ago

Happening again today. Would any logging or output help before I restart docker again?

ggggh commented 3 years ago

Actually, now have a feeling it is related to what I thought was an unrelated error on not being to get values for weather, as it sort of matches the same timeline System.Exception: API responded with an error: Cannot read property 'current' of undefined. The app is not able to get the weather data either, so retrieving it is not a problem in your code, but maybe you need to handle that exception differently as it is then affecting the ReportUnchangedValues functionality?

LordMike commented 3 years ago

Ah, I see. Nice to know also, that their serverside thingy is likely javascript :P

When that exception occurs, the entire update loop will be disrupted (and run again later). You should see values like last_bad on the operational sensor in HASS. See https://github.com/LordMike/MBW.BlueRiiot2MQTT/blob/b6a71ba204141cd6fb1e520b04576ac0222b2c3f/MBW.BlueRiiot2MQTT/Service/PoolUpdater/SingleBlueRiiotPoolUpdater.cs#L92-L97 for details.

It will affect the unchanged logic, as after the exception occurs, the call to MarkAllValuesDirty won't happen.

But then again, once the error subsides, all values should again be pushed.

Actually, I now see another issue: When a pool (any pool if you have several) is updated, then all values are pushed again, even the ones that weren't updated... Like another pools values, or the other sensors BR2MQTT provides... Should probably change that to just the sensors that could've been updated.

ggggh commented 3 years ago

By the way, the weather update on the app is working again, and as expected ReportUnchangedValues also working now.

LordMike commented 2 years ago

I've made some code that splits out the weather updates from the regular pool updates. Turns out this is a seperate API call for BR, so it can fail independently of everything else. Will test it out myself, and then tweak a bit more.

I've also made it so that the weather updates can operate at a different interval than the regular updates. I think maybe the weather doesn't change all that often .. :)