Hi!
I have a problem where my rest sensor state is displaying unknown for 1 minutes and correct 1 minute
This is my code, i need help or direction on what i’m doing wrong. first time it gets called it’s no error in the log. second time it gets length error
- platform: rest
resource: https://api.tibber.com/v1-beta/gql
method: POST
force_update: true
timeout: 30
scan_interval: 60 # Poll every hour
headers:
Authorization: "Bearer apitoken"
Content-Type: "application/json"
payload: '{"query": "{ viewer { homes { currentSubscription { priceInfo { today { total startsAt } tomorrow { total startsAt } } } } } }"}'
json_attributes_path: "$.data.viewer.homes[0].currentSubscription.priceInfo"
json_attributes:
- today
- tomorrow
value_template: >
{% set today_totals = state_attr('sensor.rest_sensor', 'today') %}
{% set tomorrow_totals = state_attr('sensor.rest_sensor', 'tomorrow') %}
{% if not today_totals%}
Waiting for data...
{% else %}
Today:
{% for item in today_totals %}
- {{ item.total }}
{% endfor %}
{% endif %}
{% if not tomorrow_totals%}
Waiting for data...
{% else %}
Today:
{% for item in tomorrow_totals %}
- {{ item.total }}
{% endfor %}
{% endif %}
2024-07-17 20:14:12.673 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://api.tibber.com/v1-beta/gql
2024-07-17 20:14:12.860 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data":{"viewer":{"homes":[{"currentSubscription":{"priceInfo":{"today":[{"total":0.4036,"startsAt":"2024-07-17T00:00:00.000+02:00"},{"total":0.4009,"startsAt":"2024-07-17T01:00:00.000+02:00"},{"total":0.3971,"startsAt":"2024-07-17T02:00:00.000+02:00"},{"total":0.389,"startsAt":"2024-07-17T03:00:00.000+02:00"},{"total":0.3809,"startsAt":"2024-07-17T04:00:00.000+02:00"},{"total":0.3756,"startsAt":"2024-07-17T05:00:00.000+02:00"},{"total":0.3982,"startsAt":"2024-07-17T06:00:00.000+02:00"},{"total":0.4323,"startsAt":"2024-07-17T07:00:00.000+02:00"},{"total":0.4411,"startsAt":"2024-07-17T08:00:00.000+02:00"},{"total":0.4313,"startsAt":"2024-07-17T09:00:00.000+02:00"},{"total":0.3966,"startsAt":"2024-07-17T10:00:00.000+02:00"},{"total":0.3691,"startsAt":"2024-07-17T11:00:00.000+02:00"},{"total":0.3794,"startsAt":"2024-07-17T12:00:00.000+02:00"},{"total":0.3574,"startsAt":"2024-07-17T13:00:00.000+02:00"},{"total":0.2524,"startsAt":"2024-07-17T14:00:00.000+02:00"},{"total":0.1993,"startsAt":"2024-07-17T15:00:00.000+02:00"},{"total":0.2261,"startsAt":"2024-07-17T16:00:00.000+02:00"},{"total":0.2682,"startsAt":"2024-07-17T17:00:00.000+02:00"},{"total":0.2799,"startsAt":"2024-07-17T18:00:00.000+02:00"},{"total":0.2988,"startsAt":"2024-07-17T19:00:00.000+02:00"},{"total":0.3001,"startsAt":"2024-07-17T20:00:00.000+02:00"},{"total":0.2942,"startsAt":"2024-07-17T21:00:00.000+02:00"},{"total":0.3091,"startsAt":"2024-07-17T22:00:00.000+02:00"},{"total":0.2689,"startsAt":"2024-07-17T23:00:00.000+02:00"}]}}}]}}}
2024-07-17 20:15:12.862 DEBUG (MainThread) [homeassistant.components.rest.data] Updating from https://api.tibber.com/v1-beta/gql
2024-07-17 20:15:13.063 DEBUG (MainThread) [homeassistant.components.rest.data] Data fetched from resource: {"data":{"viewer":{"homes":[{"currentSubscription":{"priceInfo":{"today":[{"total":0.4036,"startsAt":"2024-07-17T00:00:00.000+02:00"},{"total":0.4009,"startsAt":"2024-07-17T01:00:00.000+02:00"},{"total":0.3971,"startsAt":"2024-07-17T02:00:00.000+02:00"},{"total":0.389,"startsAt":"2024-07-17T03:00:00.000+02:00"},{"total":0.3809,"startsAt":"2024-07-17T04:00:00.000+02:00"},{"total":0.3756,"startsAt":"2024-07-17T05:00:00.000+02:00"},{"total":0.3982,"startsAt":"2024-07-17T06:00:00.000+02:00"},{"total":0.4323,"startsAt":"2024-07-17T07:00:00.000+02:00"},{"total":0.4411,"startsAt":"2024-07-17T08:00:00.000+02:00"},{"total":0.4313,"startsAt":"2024-07-17T09:00:00.000+02:00"},{"total":0.3966,"startsAt":"2024-07-17T10:00:00.000+02:00"},{"total":0.3691,"startsAt":"2024-07-17T11:00:00.000+02:00"},{"total":0.3794,"startsAt":"2024-07-17T12:00:00.000+02:00"},{"total":0.3574,"startsAt":"2024-07-17T13:00:00.000+02:00"},{"total":0.2524,"startsAt":"2024-07-17T14:00:00.000+02:00"},{"total":0.1993,"startsAt":"2024-07-17T15:00:00.000+02:00"},{"total":0.2261,"startsAt":"2024-07-17T16:00:00.000+02:00"},{"total":0.2682,"startsAt":"2024-07-17T17:00:00.000+02:00"},{"total":0.2799,"startsAt":"2024-07-17T18:00:00.000+02:00"},{"total":0.2988,"startsAt":"2024-07-17T19:00:00.000+02:00"},{"total":0.3001,"startsAt":"2024-07-17T20:00:00.000+02:00"},{"total":0.2942,"startsAt":"2024-07-17T21:00:00.000+02:00"},{"total":0.3091,"startsAt":"2024-07-17T22:00:00.000+02:00"},{"total":0.2689,"startsAt":"2024-07-17T23:00:00.000+02:00"}]}}}]}}}
2024-07-17 20:15:13.064 ERROR (MainThread) [homeassistant.helpers.entity] Failed to set state for sensor.rest_sensor, fall back to unknown
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1205, in _async_write_ha_state
hass.states.async_set(
File "/usr/src/homeassistant/homeassistant/core.py", line 2302, in async_set
state = State(
^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1773, in __init__
validate_state(state)
File "/usr/src/homeassistant/homeassistant/core.py", line 239, in validate_state
raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state with length 389. State max length is 255 characters.