So, i was finally able to get this to work!

I use NodeRed to import these statistics, and use the following fuction:

```
var newmsg={payload:{}}
var smmsg={payload:{}}
var ps=msg.payload.energyData
var c_stat={}
var sum_add = 0
if ( msg.sum != 'unknown'){
sum_add = msg.sum
}
function parseDT(rd){
var stats=[{sum:sum_add}]
var i=-1
var hr = 0
var m=0
rd.forEach(function(e){
i += 1
m=i%4
if(i == 0){
hr = 0
m = 0
} else {
if(m == 0){
hr += 1
}
}
var val=e.split('-')[0]
if(i >= 8 && i <=11){
if (val == ''){
hr = 1
} else {
hr = 2
}
}
if(i >= 12 && i <= 15){
if(val == '-'){
hr=3
} else {
hr=2
}
}
//node.warn({"hr":hr,"val":val,"m":m,"len":stats})
if(stats.length-1 == hr){
if (val != '' && val != '-'){
sum_add+=parseFloat(val)
stats[hr].sum = sum_add
} else {
stats[hr].sum = sum_add
}
} else {
if(val != '' && val != '-'){
sum_add += parseFloat(val)
stats.push({sum:sum_add})
} else {
stats.push({sum:sum_add})
}
}
//stats.push({"sum":e.split(',')[0],"hour":hr})
})
return stats
}
var nm=[]
var sm=[]
ps.forEach(function (e){
var dt = new Date(e.DT)
var dh = parseDT(e.RD.split(','))
var ldt = dt
if (e.RT == "C"){
for (var i=0;i<=23;i++){
dt.setHours(i)
nm.push({start:dt.toISOString(),sum:dh[i].sum,last_reset:ldt.toISOString()})
}
//node.warn(nm)
//newmsg.push(parseDT(e.RD.split(',')))
}
else
{
for (var i = 0; i <= 23; i++) {
dt.setHours(i)
sm.push({ start: dt.toISOString(), sum: dh[i].sum, last_reset: ldt.toISOString() })
}
}
})
newmsg.payload.stats=nm
smmsg.payload.stats=sm
//node.warn(newmsg)
//node.warn(nm)
return [newmsg,smmsg];
```

I get the data from SMT via API, into json, and i use jsonata to parse this into the Call Service Node: recorder.import_statistics call:

```
{
"stats":[$.payload.stats],
"statistic_id":"sensor.energy_reading",
"source":"recorder",
"has_mean":false,
"unit_of_measurement":"kWh",
"name":"Energy Reading",
"has_sum":true
}
```

This is all on my Dev box, and i still haven’t been able to determine how to get the state of a particular date/time, so that’s my next call.

I will post an update in my github with my flow as soon as get this working in my production.