Repository navigation
Labels
Description
What happened?
Hello
I am updating some small home assistant script that were previously running smoothly in 4.4.x
When I use the set_state api call, the calls are successful but it messes up with the boolean that are passed as attributes:
- attributes set to False are dropped and will not appear in the entity
- attributes set to True are changed to a string "true" in home assistant
This was not the case in the 4.4.x where all attributes would be transmitted with the correct type
Look like this might be linked to the work done in #2425
Version
4.5.12
Installation type
Home Assistant add-on
Relevant log output
NothingRelevant code in the app or config file that caused the issue
attributes = {
"friendly_name": "Octopus Agile Rates",
"unit_of_measurement": "GBP/kWh",
"plunge": False,
"peak": True,
}
self.set_state(
"event.test_entity",
state=1,
attributes=attributes,
replace = True,
)Anything else?
Doing a quick hatchet job in utils.py (as per below), I can obtain the correct behavior, but this would likely fixed the other bug you were addressing
def clean_kwargs(val: Any, *, http: bool = False) -> Any:
match val:
#case True if http:
# return "true"
case str() | int() | float() | bool() | None:
return val
case datetime():
return val.isoformat()
case Mapping():
return {k: clean_kwargs(v, http=http) for k, v in val.items()}
case Iterable():
return [clean_kwargs(v, http=http) for v in val]
case _:
return str(val)
def clean_http_kwargs(val: Any) -> Any:
"""Recursively cleans the kwarg dict to prepare it for use in HTTP requests."""
cleaned = clean_kwargs(val, http=True)
pruned = remove_literals(cleaned, (None,)) # Dropped False from the list
return pruned
Reacted by Thomas B
Activity
Ten0 commentedon Oct 31, 2025
This should be tagged as bug.
Gave another try at updating from 4.4 to 4.5 as well due to this and I'm hitting this issue as well on 4.5.12.
I noted that in addition to values being unwantedly turned to strings, any key that is "falsy" ("false" or None) disappears, which causes issues due to missing keys later.
I'm not happy either about my
nulls being gone, as I do pass optional values in there.This is unexpected, since HA entities normally do support having arbitrary JSONs in the attributes, not only strings, and this limits what attributes can be used for.
It looks like this filtering, if it should ever take place, should only take place in case values are serialized as query parameters for a get request, but not in other cases.
henklars commentedon Nov 4, 2025
I'm having a problem with HASS plugin set_state and int value 0. In 4.5.11 and earlier it has been possible to set int values as the code below (pos: int).
But since upgrading to dev-image (sha256:e54ef4c1019df5d1f30364726b4b743b1555cef0d1b6fa398edbf84f1ca80d70) im having problem with int value pos == 0. Int values > 0 seems to work fine. Converting to string works as a temp fix.
Logs:
2025-11-04 20:57:29.791193 ERROR HASS: [400] HTTP POST: Bad Request {'attributes': {'unit_of_measurement': '%', 'icon': 'mdi:radiator', 'last_changed': '2025-11-04T19:45:11.349126+00:00', 'last_reported': '2025-11-04T19:45:11.349126+00:00', 'last_updated': '2025-11-04T19:45:11.349126+00:00', 'context': {'id': '01K986DRNN5HKGD0DCB4XBBATA', 'user_id': 'b55311abc7494eb8afea6b9920cc6f87'}}} 2025-11-04 20:57:29.791837 ERROR radiator_livingroom: ===== Radiator.initialize.<locals>.<lambda> for radiator_livingroom ===== 2025-11-04 20:57:29.792126 ERROR radiator_livingroom: StateCallbackFail: State callback failed for 'sensor.radiator_valve_pos_livingroom' from 'radiator_livingroom' 2025-11-04 20:57:29.792279 ERROR radiator_livingroom: args: ('sensor.radiator_valve_pos_livingroom', 'state', 100, 0) 2025-11-04 20:57:29.792415 ERROR radiator_livingroom: kwargs: { 2025-11-04 20:57:29.792503 ERROR radiator_livingroom: "__thread_id": "thread-18" 2025-11-04 20:57:29.792601 ERROR radiator_livingroom: } 2025-11-04 20:57:29.792689 ERROR radiator_livingroom: argument of type 'ClientResponseError' is not iterable 2025-11-04 20:57:29.792820 ERROR radiator_livingroom: State callbacks should have the following signature: 2025-11-04 20:57:29.792909 ERROR radiator_livingroom: state_callback(self, entity, attribute, old, new, **kwargs) 2025-11-04 20:57:29.793103 ERROR radiator_livingroom: See https://appdaemon.readthedocs.io/en/latest/APPGUIDE.html#state-callbacks for more information 2025-11-04 20:57:29.793650 ERROR radiator_livingroom: TypeError: argument of type 'ClientResponseError' is not iterable 2025-11-04 20:57:29.796062 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/site-packages/appdaemon/threads.py", line 1092, in safe_callback 2025-11-04 20:57:29.796303 ERROR radiator_livingroom: funcref() 2025-11-04 20:57:29.796460 ERROR radiator_livingroom: File "/apps/henklars-net/utility/radiator.py", line 48, in <lambda> 2025-11-04 20:57:29.796592 ERROR radiator_livingroom: self.update_frontend(), 2025-11-04 20:57:29.796721 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.796849 ERROR radiator_livingroom: File "/apps/henklars-net/utility/radiator.py", line 85, in update_frontend 2025-11-04 20:57:29.797002 ERROR radiator_livingroom: self.hass.set_state( 2025-11-04 20:57:29.797093 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/site-packages/appdaemon/utils.py", line 289, in wrapper 2025-11-04 20:57:29.797192 ERROR radiator_livingroom: return run_coroutine_threadsafe(self, coro, timeout=timeout) 2025-11-04 20:57:29.797293 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.797443 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/site-packages/appdaemon/utils.py", line 615, in run_coroutine_threadsafe 2025-11-04 20:57:29.797550 ERROR radiator_livingroom: return future.result(timeout.total_seconds()) 2025-11-04 20:57:29.797636 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.797737 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 456, in result 2025-11-04 20:57:29.797834 ERROR radiator_livingroom: return self.__get_result() 2025-11-04 20:57:29.797926 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.798072 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/concurrent/futures/_base.py", line 401, in __get_result 2025-11-04 20:57:29.798164 ERROR radiator_livingroom: raise self._exception 2025-11-04 20:57:29.798281 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/site-packages/appdaemon/adapi.py", line 1790, in set_state 2025-11-04 20:57:29.798400 ERROR radiator_livingroom: return await self.AD.state.set_state( 2025-11-04 20:57:29.798522 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.798624 ERROR radiator_livingroom: File "/usr/local/lib/python3.12/site-packages/appdaemon/state.py", line 792, in set_state 2025-11-04 20:57:29.798743 ERROR radiator_livingroom: if "entity_id" in result: 2025-11-04 20:57:29.798875 ERROR radiator_livingroom: ^^^^^^^^^^^^^^^^^^^^^ 2025-11-04 20:57:29.799086 ERROR radiator_livingroom: ===========================================================================Mausy5043 commentedon Nov 7, 2025
Same issue for me with floats being exactly
0.0.Ten0 commentedon Nov 7, 2025
@jsl12
jsl12 commentedon Nov 7, 2025
Hey there @Ten0, sorry I've been traveling and moving apartments recently. This has been kind of a tricky issue because there needs to be slightly different behavior in many situations and fixing one case seems to break another. In the previous state, it didn't work for setting the state of entities in the
input_booleandomain or something. I don't quite remember (I need to go find that issue).The fix will be in tinkering with
clean_kwargsandclean_http_kwargsmore so that it works the right way in all cases, but the main impediment is understanding what all the different cases actually are. Once that's fully known, I can include everything in the testing, and it won't ever break again 🤞Ten0 commentedon Nov 7, 2025
Apologies, I didn't mean for this to feel like pressure, I just didn't want this to go unnoticed just because it wasn't flagged as a bug. I thought you were the relevant person to tag here because you had worked on the other PR.
As I mentioned in my previous message, it seems that the actual discriminant on whether we should have one behavior or another is whether the request is a
get, with query params serialized in the URL, or not.jsl12 commentedon Nov 8, 2025
No worries, I'm (generally) the person for this kind of thing these days. Great to see some other contributions though too.
I think you're correct about the actual discriminant, but I'm also going to check out #2475 to see if that'll do it
gibman commentedon Nov 25, 2025
I see this issue after updating to latest appdaemon.
Seems to happen when I have callbacks for the "sun.sun" entity which produces negative numbers for elevation.
If I go to dev. tools within hass and forcefully set the attribute for elevation to some negative number like (-12.87)
then an error is written to the logs.
Logs:
sithmein commentedon Nov 27, 2025
Not sure if it's related but I get
after updating from 4.4.2 (yes, old) to 4.5.12. It's likely caused by calls such as
self.set_state('actor.water_valve_target', state = 0)Ten0 commentedon Nov 27, 2025
Yes that's it. Blocked on 4.4 still for the same reason.
Ten0 commentedon Feb 12, 2026
Apparently this is not fixed? #2531
Fix set_state dropping False, 0, and None values (AppDaemon#2531, App…
Fix set_state dropping False, 0, and None values