Posts: 1
Threads: 1
Joined: Dec 2022
Reputation:
0
Hi!
Has anyone had any experience with getting (integrating) NordPool prices into LogicMachine?
Tried different versions but nothing worked.
What about this one?
https://dashboard.elering.ee/en/nps/pric...59:59.999Z
https://dashboard.elering.ee/api/nps/pri...%3A00.999Z
Anyone had any luck or experience? Can you please share scripts for getting NordPool prices into logic machine?
Posts: 56
Threads: 1
Joined: Dec 2020
Reputation:
22
Hi!
Here is a script, that gives six objects 1.current_time; 2.current_price; 3.cheapest_hour; 4.cheapest_price; 5.costly_hour; 6.costly_price
Code: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 https = require( 'ssl.https')
json = require( 'json')
ltn12 = require( 'ltn12')
country = 'lv'
obj_current_time = grp.create({ datatype = dt.time, address = '35/5/11', name = 'current_time'})
obj_current_price = grp.create({ datatype = dt.float32, address = '35/5/12', name = 'current_price'})
obj_cheapest_hour = grp.create({ datatype = dt.time, address = '35/5/13', name = 'cheapest_hour'})
obj_cheapest_hour_price = grp.create({ datatype = dt.float32, address = '35/5/14', name = 'cheapest_price'})
obj_costly_hour = grp.create({ datatype = dt.time, address = '35/5/15', name = 'costly_hour'})
obj_costly_hour_price = grp.create({ datatype = dt.float32, address = '35/5/16', name = 'costly_price'})
current_date = os.date( '*t')
previous_date = os.date( '*t', os.time()- 24* 60* 60)
if previous_date.month < 10 then
previous_date.month = '0' .. previous_date.month
end
if previous_date.day < 10 then
previous_date.day = '0' .. previous_date.day
end
previous_date_str = previous_date.year .. '-' .. previous_date.month .. '-' .. previous_date.day
next_date = os.date( '*t', os.time() + 24* 60* 60)
if next_date.month < 10 then
next_date.month = '0' .. next_date.month
end
if next_date.day < 10 then
next_date.day = '0' .. next_date.day
end
next_date_str = next_date.year .. '-' .. next_date.month .. '-' .. next_date.day
url = 'https://dashboard.elering.ee/api/nps/price?start='.. previous_date_str .. 'T00%3A00%3A00.999Z&end=' .. next_date_str .. 'T00%3A00%3A00.999Z'
mac = 0
io.readfile( '/sys/class/net/eth0/address'): gsub( '%x%x', function( v)
mac = mac * 256 + tonumber( v, 16)
end)
response = {}
res, code = https.request({
url = url,
protocol = 'tlsv12',
headers = {
[ 'user-agent'] = 'LM ' .. mac
},
sink = ltn12.sink.table( response)
})
if res and code == 200 then
data = json.pdecode( table.concat( response))
else
log( 'request error', res, code)
end
min_price = 99999
max_price = - 1
min_price_hour = - 1
max_price_hour = - 1
for i = 23, 47, 1 do
if data[ 'data'][ country][ i] then
price = data[ 'data'][ country][ i][ 'price']
if price < min_price then
min_price = price
min_price_hour = i - 23
end
if price > max_price then
max_price = price
max_price_hour = i - 23
end
end
end
curr_day_time = {}
if current_date[ 'wday'] > 1 then
current_date[ 'wday'] = current_date[ 'wday'] - 1
else
current_date[ 'wday'] = 7
end
curr_day_time[ 'day'] = current_date[ 'wday']
curr_day_time[ 'hour'] = current_date[ 'hour']
curr_day_time[ 'minute'] = current_date[ 'min']
grp.write( obj_current_time, curr_day_time)
current_price = data[ 'data'][ country][ current_date[ 'hour'] + 23 ][ 'price']
grp.write( obj_current_price, current_price)
cheapest_day_time = {}
cheapest_day_time[ 'day'] = current_date[ 'wday']
cheapest_day_time[ 'hour'] = min_price_hour
grp.write( obj_cheapest_hour, cheapest_day_time)
grp.write( obj_cheapest_hour_price, min_price)
costly_day_time = {}
costly_day_time[ 'day'] = current_date[ 'wday']
costly_day_time[ 'hour'] = max_price_hour
grp.write( obj_costly_hour, costly_day_time)
grp.write( obj_costly_hour_price, max_price)
|