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
"Event is not JSON serializable" occurs when using templating in Bayesian sensor #33929
Comments
@jlmcgehee21 I think that this might be caused by your PR #30962. Would you be able to take a look? It happens if data is stored in device state attributes that is not JSON serializable. |
@balloob — yes I will address this. Would a top-level test that searches through all modules and asserts that state attributes are serializable be desirable? I’m thinking in this manner because (as a non core-contributor) I didn’t know this was a spec for state attributes, but a failing test would have alerted me to this fact. |
You can't make a top level test because you need to know how to set up every integration. Instead, each integration should crash if state attributes cannot be written. But we do have tests for templates right? |
Not sure I quite understand what you’re getting at. It should of course be easy to add a test that is scoped to the Bayesian Binary Sensor. I’m just thinking about the next dev who makes a component and is not aware that the functionality of other components may be coupled to the serializability of their module’s state attributes. |
I don't think there's currently any tests for the templates in the bayesian sensor. I added them in #29122, but that request was not merged. We could add those tests after this issue is resolved in a separate PR? I can't seem to create a link to the lines of code, but it's line 153 to 216 in test_binary_sensor.py |
With the heavy refactoring of the code I can't be sure why certain changes have been done (some of them seem counter-intuitive to me), but it appears this doesn't do what the original coder expects:
It returns a list of dicts since it's an orderdedDict, I assume it is supposed to return the current prob_given_true values?
I am however quite unsure of the code's logic at this point so hesitant to provide this as fix. |
Just chiming in: this issue is still a blocker for many users. If you use templating, HASS becomes unusable because it'll keep logging this many times per second and the web interface never loads. This is still happening in 0.108.7. Only solution is to do a rollback to 0.107.7 via |
Another temporary solution is by changing the code by hand using the fix I provided above. Am waiting on @jlmcgehee21 since I believe he is the one who wrote the new code for the sensor. I'm not sure if my change is what is expected, so I'm afraid it'll break other things if I provide a pull request. If I go to the code right now either I don't understand fully what is going on, or it is very inefficient. I'm working on the assumption of the first for the moment. |
Unfortunately this isn't an option for many users. As @lbschenkel says, I'm stuck on 107.7. |
Pull request referenced by @jlmcgehee21 fixes it for me :) [edit] ooh the observations are listed much more readable now in the web-interface, that wasn't always the case was it? |
It looks like it’s scheduled to be included in 0.109 on Wednesday. |
@sophof, yes that was the intent, but that pesky |
The problem
Beginning in 0.108.0, when using templating in a Bayesian sensor, I'm seeing "Event is not JSON serializable" errors in the log. If I delete the observations that use templating from the sensor, the error goes away. These errors do not appear in 0.107.7.
Environment
Problem-relevant
configuration.yaml
Traceback/Error logs
Additional information
The text was updated successfully, but these errors were encountered: