I need help: RestfulSensor Json

I’ve been using Home Assistant for some time now.
Until now I was always able to help myself - also thanks to the community - and up to now I have managed all desired automations on my own.

Until now :slight_smile:

With the help of the “RESTful Sensor” I try to read out an API of the German electricity provider “Awattar” and make it available as a sensor in HomeAsisstant.

This doesn’t really work.

Output Awattar-Json-API:

{
“object”: “list”,
“data”: [
{
“start_timestamp”: 1559116800000,
“end_timestamp”: 1559120400000,
“marketprice”: 46.41,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559120400000,
“end_timestamp”: 1559124000000,
“marketprice”: 45,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559124000000,
“end_timestamp”: 1559127600000,
“marketprice”: 40.89,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559127600000,
“end_timestamp”: 1559131200000,
“marketprice”: 39.9,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559131200000,
“end_timestamp”: 1559134800000,
“marketprice”: 39.92,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559134800000,
“end_timestamp”: 1559138400000,
“marketprice”: 38.29,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559138400000,
“end_timestamp”: 1559142000000,
“marketprice”: 40.53,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559142000000,
“end_timestamp”: 1559145600000,
“marketprice”: 45.52,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559145600000,
“end_timestamp”: 1559149200000,
“marketprice”: 50.27,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559149200000,
“end_timestamp”: 1559152800000,
“marketprice”: 53.43,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559152800000,
“end_timestamp”: 1559156400000,
“marketprice”: 53.92,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559156400000,
“end_timestamp”: 1559160000000,
“marketprice”: 47.76,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559160000000,
“end_timestamp”: 1559163600000,
“marketprice”: 40.77,
“unit”: “Eur/MWh”
},
{
“start_timestamp”: 1559163600000,
“end_timestamp”: 1559167200000,
“marketprice”: 34.55,
“unit”: “Eur/MWh”
}
],
“url”: “/de/v1/marketdata”
}

Target:
I would like to create a sensor (time series) that provides me with the current price for the current hour.

Time of Day: XX.XX Eur/MWh

Previous approach:

sensor:

This creates a sensor with these values as the status of the sensor:

  "start_timestamp": 1559120400000,
  "end_timestamp": 1559124000000,
  "marketprice": 45,
  "unit": "Eur/MWh"

How do I get the individual points in time into a sensor?
Unfortunately that was it.

I really don’t have any experience in querying an API interface and am therefore grateful for any help.

After a few days of fiddling around, the current electricity price is now displayed in Home Assistant.

If someone needs it:

configuration.yaml:

  • platform: rest
    resource: https://api.awattar.de/v1/marketdata
    name: Aktueller Strompreis
    value_template: ‘{{ ((value_json.data[0].marketprice|float*100)/1000) | multiply(1.19) |round(2) }}’
    unit_of_measurement: “Cent/KWh”

automations.yaml:

alias: ‘Strompreis Awattar: Stündlich aktualisieren’
trigger:

  • hours: /1
    platform: time_pattern
    condition: []
    action:
  • data:
    entity_id: sensor.aktueller_strompreis
    service: homeassistant.update_entity
    initial_state: true

Now I would like to import the future electricity prices once a day and save them as a sensor.
Unfortunately I can’t get any further at this point.
How do I access the individual objects within the array? How do I extract the properties as an atribute?

Unfortunately, my previous approaches do not provide any values.

1 Like

Did you figure out how to get the future data imported? Would be nice to know the cheapest hours to charge the car, or run the washing machine and to manage it thru automations.

I am interested, too. Any suggestions?

Here is a solution based on HA’s RESTful sensor and HA templates:

And here is my own solution based on the Node RED add-on for HA:

Hey, thanks I used your restful sensor aswell I am just curious why you use | multiply(1.19) on the sensor ?

The other question I have is about the API calls you make. You are allowed to make 100per day so without defining scan_intervall it will default to 15 seconds wont’t it? So you make to many calls?