That’s not working unfortunately, sensor not showing up when changing to your code with the following in the logs
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 607, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _async_write_ha_state
self.hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 1222, in async_set
state = State(
File "/usr/src/homeassistant/homeassistant/core.py", line 912, in __init__
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.testrest. State max length is 255 characters.
So exceeding the 255 characters I guess is bugging it ?
JSON result was not a dictionary or list with 0th element a dictionary
Hm, yeah, seems like it
Do you need anything else extracted / something in it’s state?
If not, add
value_template: OK
If this still won’t work, please paste the entire sensor config (of course, you can remove credentials/URLs and/or use secrets), so we can take a closer look at it.
The same struggle you are now having with me is the struggle I had this entire afternoon. I’m not getting any information in the sensor, I just want to know by value or true/false that there is stock
Maybe it’s easier to use sensor below and use a template sensor to get data from this sensor but that I also get not working because of the deep nested data
Not wasting my time, happy that someone is willing to help me But unfortunately it’s not working, now the sensor is not coming up with the error of 255 characters again so it looks like it’s not looking to only inStock or shipping
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 607, in _async_add_entity
await entity.add_to_platform_finish()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 715, in add_to_platform_finish
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 596, in _async_write_ha_state
self.hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 1222, in async_set
state = State(
File "/usr/src/homeassistant/homeassistant/core.py", line 912, in __init__
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity ID: sensor.testrest. State max length is 255 characters.
Alright, after banging my head against the wall for a good hour, I think I’ve found the problem, it’s that theres a . in the key (:00.0000000Z). This issue might be related.
The thing is, the extraction works for the value_template, but not for the json_attributes_path, I’m assuming it interprets the . as part of the path, not the name.
Please file an issue since this behaviour is unexpected.
For a quick fix, just create two sensors that extract via value_template.
If you want to, you can create a template sensor to have them combined again.
Since you’d be using two sensors on the same endpoint, use rest integration, not the sensor integration.
Example:
# note that this is using the rest integration, don't put the following
# in your sensor.yaml / under sensor:
rest:
- resource: !secret stock1url
sensor:
- name: testrest_inStock
value_template: '{{value_json["availableLots"]["0001-01-01T00:00:00.0000000Z"]["9000000013"]["inStock"]}}'
- name: testrest_deliveryType
value_template: '{{value_json["availableLots"]["0001-01-01T00:00:00.0000000Z"]["9000000013"]["deliveryType"]}}'
# note that this is is using the template integration, don't put the following
# in your sensor.yaml / under sensor:
template:
- sensor:
- name: "myTestRest"
state: "OK"
attributes:
inStock: "{{states('sensor.testrest_inStock')}}"
deliveryType: "{{states('sensor.testrest_deliveryType')}}"