To be on the safe side, I would like to hear your opinion again. I’ve only been with HA for a good 2 months. But I am a professional programmer.
Code-wise it should fit +/-.
But maybe you have an idea how I can prevent HA from running amok?
It seems to be a BUG in any case.
=================================================
I have programmed 2 REST interfaces to an external provider.
The retrieval works. I get the appropriate data back according to the API interface.
BUT: I can only retrieve data in a defined interval. This varies.
When I restart HA, the two REST sensors are started. I see 2 API accesses at the external provider. So far ok.
Without automation, both sensors retrieve every 30 sec. As far as I have read, this is the default setting.
Set to 24h using scan_interval: 86400.
This also works. Both REST sensors are only retrieved once. Then no more.
BUT:
http://homeassistant.local:8123/developer-tools/yaml
“All YAML configurations” => then HA ammok runs.
Queries are made every second or so. With the external provider, accesses increase rapidly.
Describe the behavior you expected
If I can’t specify a start condition in the REST sensor, then I expect the scan_interval to always be implemented.
Then the start + its logic must make an automation.
Steps to reproduce the issue
AI could not find a code error
AI could not present a solution either
So for now I assume that my code is correct.
Here is my code:
/homeassistant/configuration.yaml
`default_config:
recorder:
db_url: mysql://homeassistant:homeassistant@core-mariadb/homeassistant?charset=utf8mb4
homeassistant:
unit_system: metric
currency: EUR
time_zone: Europe/Berlin
language: de
packages:
knx: !include 1_KNX.yaml
wettervorhersage: !include 2_Wettervorhersage.yaml
strom: !include 3_Strom.yaml
email: !include 4_Email_versand.yaml
neue_wettervorhersage: !include 5_neue_Wettervorhersage.yaml`
/homeassistant/5_neue_Wettervorhersage.yaml
`automation:
alias: "Bedingte Aktualisierung des Solarprognose REST-Sensors"
trigger:
platform: state
entity_id: sensor.solarprognose_raw_json_hourly
attribute: preferredNextApiRequestAt
for:
seconds: 30 # Verzögerung hinzugefügt, bevor die Automation ausgelöst wird
condition:
condition: template
value_template: >
{% set next_request_epoch = state_attr('sensor.solarprognose_raw_json_hourly', 'preferredNextApiRequestAt')['epochTimeUtc'] | int if state_attr('sensor.solarprognose_raw_json_hourly', 'preferredNextApiRequestAt') is not none else None %}
{% set now = now().timestamp() | int %}
{{ next_request_epoch is not none and now >= next_request_epoch }}
action:
service: system_log.write
data:
message: "Automation ausgelöst, next_request_epoch: {{ next_request_epoch }}, now: {{ now }}, last_update: {{ last_update }}"
level: debug
condition: template
value_template: >
{% set next_request_epoch = state_attr('sensor.solarprognose_raw_json_hourly', 'preferredNextApiRequestAt')['epochTimeUtc'] | int if state_attr('sensor.solarprognose_raw_json_hourly', 'preferredNextApiRequestAt') is not none else None %}
{% set now = now().timestamp() | int %}
{% set last_update = state_attr('sensor.solarprognose_raw_json_hourly', 'last_update_time') | int %}
{{ next_request_epoch is not none and now >= next_request_epoch and now - last_update > 1800 }}
service: homeassistant.update_entity
target:
entity_id:
- sensor.solarprognose_raw_json_hourly
- sensor.solarprognose_raw_json_daily
sensor:
platform: rest
name: solarprognose_raw_json_hourly
resource: https://www.solarprognose.de/web/solarprediction/api/v1
scan_interval: 86400 # 24h = unbeding drin lassen, da HA sonst alle 30sek abholt. Abholung von einer logik (automation)
headers:
Content-Type: application/json
params:
access-token: 123456789 # change
project: Garage
algorithm: mosmix
item: inverter
id: 123456789 # change
type: hourly
_format: json
method: GET
value_template: >
{% if value_json %}
{{ "JSON received at " ~ now().strftime('%d.%m.%Y %H:%M:%S') }}
{% else %}
no_data
{% endif %}
json_attributes:
preferredNextApiRequestAt
status
message
data
iLastPredictionGenerationEpochTime
datalinename
platform: rest
name: solarprognose_raw_json_daily
resource: https://www.solarprognose.de/web/solarprediction/api/v1
scan_interval: 86400 # 24h = unbeding drin lassen, da HA sonst alle 30sek abholt. Abholung von einer logik (automation)
headers:
Content-Type: application/json
params:
access-token: 123456789 # change
project: Garage
algorithm: mosmix
item: inverter
id: 123456789 # change
type: daily
_format: json
method: GET
value_template: >
{% if value_json %}
{{ "JSON received at " ~ now().strftime('%d.%m.%Y %H:%M:%S') }}
{% else %}
no_data
{% endif %}
json_attributes:
preferredNextApiRequestAt
status
message
data
iLastPredictionGenerationEpochTime
datalinename`
for the sake of completeness… but not important for this problem. the JSON header response
{"preferredNextApiRequestAt":{"secondOfHour":1839,"epochTimeUtc":1736422239},"status":0,"iLastPredictionGenerationEpochTime":1736422018,"weather_source_text":"<a target=\"_blank\" href=\"https://www.dwd.de/DE/service/copyright/copyright_node.html\"><img src=\"https://www.solarprognose.de/web/img/dwd_logo_258x69.png\"></a>","datalinename":"Fronius Verto 25Kwh","data":{"1736409600":[0,0],"1736413200":[0.507,0.507],"1736416800":[1.089,1.596],"1736420400":[1.685,3.281],"1736424000":[1.833,5.114],"1736427600":[1.972,7.086],"1736431200":[1.451,8.537],"1736434800":[0,8.537],"1736492400":[0,0],"1736496000":[0.111,0.111],"1736499600":[0.609,0.72],"1736503200":[1.385,2.105],"1736506800":[1.982,4.087],"1736510400":[2.444,6.531],"1736514000":[2.082,8.613],"1736517600":[1.572,10.185],"1736521200":[0,10.185]}}
What version of Home Assistant Core has the issue?
2025.1.1