Help setting sensor state #9
-
Sorry to ask this here, but can't find any documentation to help me use this to set a sensor state. I have a simple single value payload and entitiy_id, but am not sure what the right function call is. example.py only shows light control. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 12 replies
-
First off I want to thank you for your interest in the project. You're right there isn't any documentation on it yet. Upon further investigation, I've found that there's an endpoint on home assistant that we haven't made a function call for yet. I assume you want to change the sensor state in Home assistant but don't want to trigger any real world events which would be done with service triggering. If this is what you're looking for then I apologize for not including it yet. I'll get right on it and will let you know when it's added! Thanks! |
Beta Was this translation helpful? Give feedback.
-
Yes, I’ve got some code which talks via modbus to a solar invertor and I want to update states in HA with the stats like solar, load, export, grid etc… if there’s a way to simply do that that’d be awesome! If it can be done as a service then happy to do it that way, if you can show me how. |
Beta Was this translation helpful? Give feedback.
-
The biggest question I have which basically decides which function you need to use, is whether or not you need your entity states backed by real world hardware components. |
Beta Was this translation helpful? Give feedback.
-
Sounds great! I'll get working on adding that function to the library and I'll let you know when it's done! |
Beta Was this translation helpful? Give feedback.
-
Should only be a few hours to complete. |
Beta Was this translation helpful? Give feedback.
-
Okay. It's now added! To utilize the new function client.set_entity('my_fabulous.entity', state='fabulous_of_course', some_attribute='foobar') Now as you noted there is a lack of documentation to the project. The next steps for us would be to probably start working on that and we have a few ideas. So stay tuned! |
Beta Was this translation helpful? Give feedback.
-
Try upgrading to the latest debug version "0.1.1.post1" and then running your code. It should print the json response from HA so we can verify that this is exactly where the KeyError is being raised from, like the error output says it is. |
Beta Was this translation helpful? Give feedback.
-
Ok after upgrading to version "0.1.2" The empty attributes key bug the json body of set_entity should be fixed! Let me know if it's not. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Found it for real! In "https://github.com/home-assistant/core/blob/dev/homeassistant/components/api/__init__.py" on line 254-257: try:
data = await request.json()
except ValueError:
return self.json_message("Invalid JSON specified.", HTTP_BAD_REQUEST) This is where the error is coming from so now I think I know how to fix it! Expect solution soon. |
Beta Was this translation helpful? Give feedback.
-
After much research I have concluded that it is a bug where the Content-Length header integer isn't matching the length of the post json body, which is a problem with requests so there's not much I can do about that so I'm going to open an issue with all relevant information on both python requests GitHub repository and one of this one labeling it a bug. Stay tuned for updates on this, with the upcoming developments planned for this project I think we will get it fixed soon! Thanks for your patience. |
Beta Was this translation helpful? Give feedback.
After much research I have concluded that it is a bug where the Content-Length header integer isn't matching the length of the post json body, which is a problem with requests so there's not much I can do about that so I'm going to open an issue with all relevant information on both python requests GitHub repository and one of this one labeling it a bug. Stay tuned for updates on this, with the upcoming developments planned for this project I think we will get it fixed soon! Thanks for your patience.