How do I store results from a RESTFul command for use in dashboard

I’m pretty new to this!

First I did a REST sensor like:


#Get Crossrate for EUR/SEK

  • platform: rest
    name: EUR Crossrate
    resource_template: https://api.riksbank.se/swea/v1/CrossRates/SEKEURPMI/SEKETT/{{ now().strftime(‘%Y-%m-%d’) }}
    headers:
    Cache-Control: no-cache
    Ocp-Apim-Subscription-Key: !Secrets xyz
    method: GET
    value_template: “{{ value_json[0].value | float | round(2) }}”
    scan_interval: 86400

Result:

[{
“date”: “string”,
“value”: 0
}]

It worked fine but it pulled to many times from the source. I only want to do this 17:00 Mon-Fri

So I tried a rest_command instead(to use in automation):


#Get Crossrate for EUR/SEK
rest_command:
usd_request:
url: https://api.riksbank.se/swea/v1/CrossRates/SEKEURPMI/SEKETT/{{ now().strftime(‘%Y-%m-%d’) }}
headers:
Cache-Control: no-cache
Ocp-Apim-Subscription-Key: !Secrets xyz
method: GET

It works when I tested this in Sevices

BUT how can I store the result, so I can use it in the dashboard?

Your first attempt was better, its storing the result.

In order to use a more intelligent schedule for RESTful sensors, set the scan interval to a large number, and then use an event to trigger the fetch and store, something like:

alias: "Get the REST Data"
description: ""
trigger:
  - platform: time
    at: "07:00:00"
condition: []
action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.my_rest_sensor
    data: {}
mode: single

You can of course have it run every x hours, but only certain days and anything you want with events.