Getting data from sensor

probably this is piece of cake for nodered gurus, but im stucked :confused:

i have sensor as follows:

current_price: 29.136
average: 37.92
off peak 1: 28.86
off peak 2: 28.776
peak: 47.016
min: 18.744
max: 57.864
unit: MWh
currency: EUR
country: Estonia
region: EE
low price: true
today:
  - 20.964
  - 19.176
  - 18.744
  - 18.888
  - 32.892
  - 30.108
  - 39.072
  - 51.024
  - 57.864
  - 56.052
  - 47.868
  - 44.04
  - 56.04
  - 44.46
  - 47.46
  - 33
  - 56.076
  - 36.108
  - 56.04
  - 29.136
  - 22.908
  - 44.064
  - 25.236
  - 22.872
tomorrow:
  - 32.136
  - 26.4
  - 17.052
  - 16.332
  - 15.228
  - 21.612
  - 12.444
  - 12.432
  - 32.424
  - 32.424
  - 32.424
  - 32.256
  - 16.884
  - 17.34
  - 15.816
  - 17.976
  - 32.256
  - 32.268
  - 32.268
  - 32.196
  - 16.62
  - 15.96
  - 16.332
  - 16.26
unit_of_measurement: EUR/MWh

my problem: i want to get price now (easy) + price for NEXT hour + hour after that.
i assume i should use formula somehow.
help please :slight_smile: how?

can you put the sensor in node red and post here the debug node’s output. and also, which one is the current hour value the first entry in the array or the array starts from 00 and ends at 23?

here we go:

msg : Object
object
_msgid: "e01299ec.7bfaa8"
topic: ""
payload: "20.412"
data: object
entity_id: "sensor.nordpool_mwh_ee_eur_3_10_02"
state: "20.412"
attributes: object
current_price: 20.412
average: 19.008
off peak 1: 12.852
off peak 2: 21.024
peak: 22.44
min: 9.168
max: 32.448
unit: "MWh"
currency: "EUR"
country: "Estonia"
region: "EE"
low price: false
today: array[24]
[0 … 9]
0: 16.824
1: 13.728
2: 13.164
3: 11.784
4: 9.168
5: 13.836
6: 12.24
7: 12.024
8: 17.832
9: 20.148
[10 … 19]
10: 20.412
11: 20.412
12: 20.352
13: 20.328
14: 20.388
15: 20.892
16: 21.6
17: 32.448
18: 32.424
19: 22.104
[20 … 23]
20: 21.396
21: 21.276
22: 21.084
23: 20.352
tomorrow: array[24]
[0 … 9]
0: 16.824
1: 13.728
2: 13.164
3: 11.784
4: 9.168
5: 13.836
6: 12.24
7: 12.024
8: 17.832
9: 20.148
[10 … 19]
10: 20.412
11: 20.412
12: 20.352
13: 20.328
14: 20.388
15: 20.892
16: 21.6
17: 32.448
18: 32.424
19: 22.104
[20 … 23]
20: 21.396
21: 21.276
22: 21.084
23: 20.352
unit_of_measurement: "EUR/MWh"
friendly_name: "nordpool_mwh_ee_eur_3_10_02"
icon: "mdi:flash"
show_last_changed: true
hidden: false
last_changed: "2020-02-02T09:00:20.123818+00:00"
last_updated: "2020-02-02T09:00:20.123818+00:00"

current value is “current price”

For this kind of situation, I usually go through http://try.jsonata.org
You copy the msg.payload (not the entire msg as you did above).
And then with trial and error, you find what you want.
In your case I would thing that msg.payload.data.today[0] is what you are looking after and [1] for the next hour.
Using the jsonata access is very efficient for those (like me) you are not json fluent.
Then with a change node you can then extract those values and do “stuff”.
GV

so you need to add these 3 values together and that is because it’s 10am where you live?

you can use this in a function node.

var time = new Date();
var hour = time.getHours();
var total = msg.payload.today[hour] + msg.payload.today[hour+1] + msg.payload.today[hour+2]; 
msg.payload = total
return msg;

thanx. this is giving me error:

"TypeError: Cannot read property '12' of undefined"

actually i dont need sum of those values, but values like “price now”, “price next hour”, “price etc”. i think i can get this working myself - my biggest concern was how to get actual next hour. as i understand [hour+1] doing this?

yes that’s what hour+1 is doing. in the example I send, the msg structure is different. i think your values are located msg.payload.data.today[12] but I didn’t use the exact structure you have.

if you don’t need to add them, you can use change nodes also with help of JSONATA as @greengolfer mentioned. I can give you a better example if you can post the entire msg as a json string.

also there is another challange when it’s 23:00…

[{"id":"99e3547d.2a7b88","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"{\"current_price\":29.136,\"average\":37.92,\"off peak 1\":28.86,\"off peak 2\":28.776,\"peak\":47.016,\"min\":18.744,\"max\":57.864,\"unit\":\"MWh\",\"currency\":\"EUR\",\"country\":\"Estonia\",\"region\":\"EE\",\"low price\":true,\"today\":[20.964,19.176,18.744,18.888,32.892,30.108,39.072,51.024,57.864,56.052,47.868,44.04,56.04,44.46,47.46,33,56.076,36.108,56.04,29.136,22.908,44.064,25.236,22.872],\"tomorrow\":[32.136,26.4,17.052,16.332,15.228,21.612,12.444,12.432,32.424,32.424,32.424,32.256,16.884,17.34,15.816,17.976,32.256,32.268,32.268,32.196,16.62,15.96,16.332,16.26],\"unit_of_measurement\":\"EUR/MWh\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":160,"wires":[["4ca34597.d374ec"]]},{"id":"4ca34597.d374ec","type":"change","z":"294e4f5f.46b07","name":"","rules":[{"t":"set","p":"payload.next_hour_price","pt":"msg","to":"today[$number($fromMillis($millis(),\"[H01]\",'0100'))+1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":160,"wires":[[]]}]

guys, THANK YOU! love this community :slight_smile:

@typeonegative, did you get your +1h sensor to work on node red? I’m struggling to get it to work. Do you mind sharing it?

i got it working using in function node

var time = new Date();
var hour = time.getHours();
var tund0 = msg.data.attributes.today[hour-1]; 
var tund1 = msg.data.attributes.today[hour]; 
var tund2 = msg.data.attributes.today[hour+1]; 
msg.tund0 = tund0
msg.tund1 = tund1
msg.tund2 = tund2

return msg;