Hi,
I’m trying to create a sensor with projected electricity prices within it. I’ve tried everything however I am struggling to parse the data. Any hints would be appreciated.
- platform: command_line
name: test_forecast
scan_interval: 300
command: >-
bash -c '
now=$(date -u +%s); cutoff=$((now+86400));
curl -s "https://api.localvolts.com/v1/customer/interval?NMI=132412341234" \
-H "Authorization: apikey 123412341234123412341234" \
-H "partner: 12345" \
-H "Accept: application/json" \
-H "Accept-Encoding: identity" |
jq --argjson now "$now" --argjson cutoff "$cutoff" '
def ts: sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601 ;
[ .[]
| select(.quality == "Fcst") # forecasts only
| select((.intervalEnd | ts) >= $now and # within 24 h
(.intervalEnd | ts) < $cutoff)
| { time: .intervalEnd, # keep timestamp
costsFlexUp: .costsFlexUp, # import price (¢)
earningsFlexUp: .earningsFlexUp } # export price (¢)
]
'
value_template: "{{ now().timestamp() | int }}"
json_attributes:
- forecasts
If I run this script from the command line…
#!/usr/bin/env bash
NMI="132412341234"
API_KEY="123412341234123412341234"
PARTNER="12345"
now=$(date -u +%s) # current epoch (UTC)
cutoff=$((now + 86400)) # +24 h
curl -s "https://api.localvolts.com/v1/customer/interval?NMI=$NMI" \
-H "Authorization: apikey $API_KEY" \
-H "partner: $PARTNER" |
jq --argjson now "$now" --argjson cutoff "$cutoff" '
def ts: sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601 ;
[ .[]
| select(.quality == "Fcst") # forecasts only
| select((.intervalEnd | ts) >= $now and # within 24 h
(.intervalEnd | ts) < $cutoff)
| { time: .intervalEnd, # keep timestamp
costsFlexUp: .costsFlexUp, # import price (¢)
earningsFlexUp: .earningsFlexUp } # export price (¢)
]
'
It gives me this data.
$ ./test.sh | more
[
{
"time": "2025-04-29T10:15:00.000Z",
"costsFlexUp": 70.27016596,
"earningsFlexUp": 43.5323644
},
{
"time": "2025-04-29T10:20:00.000Z",
"costsFlexUp": 70.27016596,
"earningsFlexUp": 43.5323644
},