Trying to pull some json from ambientweather.net but the entire line is contained within square brackets and HA doesn’t like what I’m doing
I created a simple copy of the json and removed the brackets, and everything processes fine. So, somehow I need to either remove the [ ] or change something in my configuration just not sure what.
I have, but the likelihood of me typing something incorrectly is very high.
What works on my version without brackets is (there’s a bunch more sensors, just showing wind direction for this example)
When I use the json with brackets, I get a bunch of errors. And the ‘sensor.weathertest’ also has no data
2018-05-12 13:07:51 WARNING (Thread-10) [homeassistant.components.sensor.rest] JSON result was not a dictionary
2018-05-12 13:07:51 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.weathertest. State max length is 255 characters.
2018-05-12 13:08:08 WARNING (MainThread) [homeassistant.components.sensor.template] Could not render template Wind Direction, the state is unknown.
I never used that sensor, but according the warning message and the source code of that component, the json_attributes didn’t support JSON array as top-level. Therefore, states.sensor.weathertest.attributes is always None in your case.
Its workflow is first parse value, assign to attributes, then try to parse value_template, rewrite value. It looks buggy for me. The simple fix should be first parse value_template, then parse value, then assign attributes.
That’s a no-no in python. You are trying to assign a string inside a string without using the proper punctuation. Notice how the editor is even messing it up by showing winddi as black where the rest is red?
I know this is over a year old, but here is how I got it working with json_attributes:
I’m using a command line sensor with curl and then I pipe everything to python and print the first item of the list (watch for the escape quotes in the command)
I know this is an old thread but I was working on something similar and thought I’d share: I just submitted a PR which implements the same json_attributes_template config option in rest that mqtt uses to let you manipulate a JSON REST response back into state attributes.