This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

External eletric pricing on API
#2
(09.02.2022, 09:20)Tue Wrote: Hello there

I'm newbee to scripting to a API, I need you help to get me startet. I can from bellow link get the eletric pricing for the next 24 hours (is updated everyday at 14:00 for the next day)

https://api.energidataservice.dk/datasto...rDK%22:%222022-02-09T10:00:00%22,%22PriceArea%22:%22DK1%22%7D

I do have some docomentation for it:

https://www.energidataservice.dk/guides/api-guides

And I do know that I need to make some ssl.https.request(url) there I change from current time (date = os.date('*t')) and make a new string with date.time and so on. But anybody that can help me in the right directions?

I want to make a routine that charges my eletrich car in the correct time, I ca get acces to my car date here: https://www.platform.tronity.io/ (still working progess on how for me :-)) https://app.platform.tronity.io/docs

In advance thx


This is what I got so far, how do I decode json in Lua?

Code:
--[[************************************************************************************************
Created: 2022-02-09
Get eletric pricing from Norpol and set car charge when good :-)
************************************************************************************************]]--
require('json')
https = require 'ssl.https'
local date = os.date('*t')
local data = ' '
local url = ' '

for i=1, 24 do
  date.hour = date.hour + 1
  if date.hour > 23 then
    date.day = date.day + 1
    date.hour = 0
  end  -- Missing if month changes or year (to come later)
 
    data = date.year .. '-' .. date.month .. '-' .. date.day .. 'T' .. date.hour .. ':00:00' -- Make the date/clock string to request
    url = 'https://api.energidataservice.dk/datastore_search?resource_id=elspotprices&filters=%7B%22HourDK%22:%22' .. data .. '%22,%22PriceArea%22:%22DK1%22%7D' -- Here is the requst string :-)
    status = ssl.https.request(url) -- Here comes reply from server

  log(status) -- How do I decode it and get it into a time table
end

--[[
This is returned format..:
{
  "help": "https://api.energidataservice.dk/help_show?name=datastore_search",
  "success": true,
  "result": {
    "include_total": true,
    "resource_id": "c86859d2-942e-4029-aec1-32d56f1a2e5d",
    "fields": [
      {
        "type": "int",
        "id": "_id"
      },
      {
        "type": "timestamptz",
        "id": "HourUTC"
      },
      {
        "type": "timestamp",
        "id": "HourDK"
      },
      {
        "type": "text",
        "id": "PriceArea"
      },
      {
        "type": "float8",
        "id": "SpotPriceDKK"
      },
      {
        "type": "float8",
        "id": "SpotPriceEUR"
      }
    ],
    "records_format": "objects",
    "records": [
      {
        "_id": 2023070,
        "HourUTC": "2022-02-09T09:00:00+00:00",
        "HourDK": "2022-02-09T10:00:00",
        "PriceArea": "DK1",
        "SpotPriceDKK": 885.32, <-***************************** This is the value what I need ***********************
        "SpotPriceEUR": 118.94
      }
    ],
    "_links": {
      "start": "/datastore_search?filters=%7B%22HourDK%22%3A%222022-02-09T10%3A00%3A00%22%2C%22PriceArea%22%3A%22DK1%22%7D&resource_id=elspotprices",
      "next": "/datastore_search?offset=100&filters=%7B%22HourDK%22%3A%222022-02-09T10%3A00%3A00%22%2C%22PriceArea%22%3A%22DK1%22%7D&resource_id=elspotprices"
    },
    "filters": {
      "HourDK": "2022-02-09T10:00:00",
      "PriceArea": "DK1"
    },
    "total": 1
  }
} ]]--
Reply


Messages In This Thread
External eletric pricing on API - by Tue - 09.02.2022, 09:20
RE: External eletric pricing on API - by Tue - 09.02.2022, 12:30
RE: External eletric pricing on API - by Tue - 10.02.2022, 16:29
RE: External eletric pricing on API - by Tue - 11.02.2022, 15:01

Forum Jump: