Rest Sensor: how to avoid empty JSON dictionary

Hi,
I have an issue/request for Rest Sensor.
I have a rest sensor that is retrieving data from an InfluxDB instance.
I’m using this configuration:


- authentication: basic
  username: user
  password: psw
  scan_interval: 300
  resource_template: url
  sensor:
    - name: Rest Pannelli Solari
      value_template: "OK"
      json_attributes_path: "$.results[0].series[0]"
      json_attributes:
        - values

I use a query in the url created using Graphana UI.
Everything is working fine, except for a minor issue.
I query all the data for the current day from a sensor, grouped by 5m. From midnight until somewhere after sunrise (time change on daily basis) there is no data available, therefore the rest sensor returns this error

Logger: homeassistant.components.rest.sensor
Source: components/rest/sensor.py:166
Integration: RESTful ([documentation](https://www.home-assistant.io/integrations/rest), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+rest%22))
First occurred: 23 marzo 2021, 0:04:06 (984 occurrences)
Last logged: 7:19:46

JSON result was not a dictionary or list with 0th element a dictionary

How can I prevent to have this error collected all night, at every sensor update?
Template of some sort?

Thanks
Matteo

Hi @MatteGary, did you ever find a solution to this? I’m experiencing the same behaviour and would like to eliminate these warnings from my logs.

Hi Regan,
It has been a long time since I posted this, but unfortunately I didn’t find any useful solution…
One idea that I tried along the way is this one:

Set the scan_interval to a really high value, and then use an Automation to trigger the update of the entity using homeassistant.update_entity service.

In this way you can prevent from doing the rest polling during night or depending to other condition (state of another entity for instance). I tried using both the ping platform and the WakeOnLan switch as condition in the automation to trigger the update of the entity.

I had the same issue with a FV Inverter on TCP, which is automatically turned off during the night, and there I cannot use the WOL switch. In that situation, I’m still trying some new stuff, like using an integration and disable/enable it via Spook during the night. In this case (since the entity value will became unavailable when the integration is disabled) I’m using a template to “filter out” the unavailable values.

Hope that this can help you, let me know if you need more info!

Thanks, Matteo! I’ll give this a try.