Reading Values from a JSON File for Solar

Hi, just getting in to HA, and iv spent the last 2 days trying to read a json files that Iv converted from a CSV. The format is:

{
    "Time":  "2022-12-13 23:0:33",
    "Temperature":  "0.0",
    "PV1 Voltage[V]":  "0.0",
    "PV2 Voltage[V]":  "0.0",
    "PV1 Current[A]":  "0.0",
    "PV2 Current[A]":  "0.0",
    "Total energy[KW.Hr]":  "0.0",
    "Total operation hours[Hr]":  "42562",
    "Total AC Power[W]":  "0",
    "Mode":  "PV power off",
    "Daily Energy[KW.Hr]":  "0.99"
}

But even with my best googlefoo I cant just seem to read those values in to HA. Iv managed to create a load of sensors to read another Json source (aBex fish tank water tested) which works fine, but I cant wrap my head around this.

This is one of my sensors:

#Solar
  - platform: rest
    name: Solar Power
    resource: 'http://dc01/solar.json'
    value_template: '{{value_json["Total AC Power[W]"]}}'
    icon: mdi:water
    unit_of_measurement: 'W'
    scan_interval: 60
    json_attributes:
      - ["Total AC Power[W]"]

However I just get Unknown. Could someone explain like im 5 what Im doing wrong please? Thanks!

Nothing in your logs?
Assuming you don’t run a “core” installation, It seems unlikely to me that dc01 would be resolvable inside the HA docker container. What is it?

What happens if you remove this bit?

Hi, its running in a hyperV VM, iv also tried an IP address, its reading from another IP address on my local LAN (the Aquarium tester), dc01 is my Domain controller with IIS serving the file for testing.

Good point. That’s wrong (and unneeded).

Same thing.

Oddly tho, I changed it to this:

  - platform: rest
    name: Solar Power Daily
    resource: 'http://192.168.1.1/solar.json'
    value_template: "{{value_json}}"
    icon: mdi:solar-power
    unit_of_measurement: 'KW Hr'
    scan_interval: 60
    json_attributes:
      - Daily Energy[KW.Hr]

And now I get a reading of 0… so its doing something! lol

Figured it out… Powershell outputs by default as UTF-16 LE files, so HE couldnt read them. Fixed the out-file with -Encoding utf8 and now working. By pure chance i opened them on a server 2022 notepad which shows the encoding lol.

1 Like