Getting json data from Bluewalker UPS running Winpower software

Hi,

This is my first post because I haven’t been able to find an answer elsewhere on this great forum.

I try to get data from this json file into home assistant, but I keep getting ‘value_json’ is undefined in Template editor under Developer tools.

    - platform: rest
      name: ups_data
      resource: https://172.16.1.14:8888/0/json
      scan_interval: 5
      verify_ssl: false
      value_template: "{{value_json[0].batCapacity}}
      value_template: 'OK'

    -  platform: template
       sensors:
         ups_batcapacity:
           value_template: '{{ states.sensor.ups_data["batCapacity"] }}'
           friendly_name: "UPS Batcapacity"

I would like to have so I can see this data in Home Assistant:
“batCapacity”: “100%”
“inVolt”: “228.0V”
“loadPercent”: “20%”
“batTimeRemain”: “32m3s”
“outVolt”: “229.0V”
“batV”: “27.1V”

This is the raw file from my UPS website

{“key”:“USB/LINE-INT_000000000”,“device”:{“key”:“USB/LINE-INT_000000000”,“id”:0,“protocol”:4,“portIndex”:4,“ip”:null,“status”:“”,“upsIndex”:0,“hasWarn”:false,“statusIcon”:“online”},“version”:“”,“status”:“Normal”,“model”:“LINE-INT”,“warning”:“”,“inFreq”:“”,“outFreq”:“49.6Hz”,“emdHumidity”:“”,“batTemp”:“”,“batCapacity”:“100%”,“lsCounter”:-1,“oidType”:0,“inVolt”:“228.0V”,“loadPercent”:“20%”,“batTimeRemain”:“32m3s”,“bypassFreq”:“”,“outVolt”:“229.0V”,“noModule”:false,“workMode”:-1,“extStatus”:0,“bypassVolt”:“”,“iStatus”:0,“loadPercentMax”:20,“loadSegment1State”:“”,“loadSegment2State”:“”,“redundantNumber”:“”,“batV”:“27.1V”,“ls1”:-1,“ls2”:-1,“outA”:“”,“outVA”:“”,“outW”:“”,“lastEvent1”:“”,“abmState”:“”,“emdAlarm1”:“”,“emdTemp”:“”,“lastEvent2”:“22/01/2024 06:10:58 Start Agent”,“emdAlarm2”:“”,“cfgKVA”:“”,“cfgBatNumber”:“”,“upsTemp”:“”,“supportTest”:true,“statusColor”:0}

This is from JSON Online Validator

    "key": "USB/LINE-INT_000000000",
    "device": {
        "key": "USB/LINE-INT_000000000",
        "id": 0,
        "protocol": 4,
        "portIndex": 4,
        "ip": null,
        "status": "",
        "upsIndex": 0,
        "hasWarn": false,
        "statusIcon": "online"
    },
    "version": "",
    "status": "Normal",
    "model": "LINE-INT",
    "warning": "",
    "inFreq": "",
    "outFreq": "49.6Hz",
    "emdHumidity": "",
    "batTemp": "",
    "batCapacity": "100%",
    "lsCounter": -1,
    "oidType": 0,
    "inVolt": "228.0V",
    "loadPercent": "20%",
    "batTimeRemain": "32m3s",
    "bypassFreq": "",
    "outVolt": "229.0V",
    "noModule": false,
    "workMode": -1,
    "extStatus": 0,
    "bypassVolt": "",
    "iStatus": 0,
    "loadPercentMax": 20,
    "loadSegment1State": "",
    "loadSegment2State": "",
    "redundantNumber": "",
    "batV": "27.1V",
    "ls1": -1,
    "ls2": -1,
    "outA": "",
    "outVA": "",
    "outW": "",
    "lastEvent1": "",
    "abmState": "",
    "emdAlarm1": "",
    "emdTemp": "",
    "lastEvent2": "22/01/2024 06:10:58 Start Agent",
    "emdAlarm2": "",
    "cfgKVA": "",
    "cfgBatNumber": "",
    "upsTemp": "",
    "supportTest": true,
    "statusColor": 0
}

can anyone help me to make the right code?

Thanks,

Jesper

Here is the example of using attributes and as json_attributes_path you can use just the $

RESTful Sensor - Home Assistant (home-assistant.io)

Hi,

There is something I don’t understand, even if I copy the example from the HA website, I get an error (UndefinedError: ‘value_json’ is undefined).

Is there anything i need to install in HA to make it work?

I have copied this:

  - platform: rest
    name: JSON users
    json_attributes_path: "$.[0].address"
    json_attributes:
      - street
      - suite
      - city
      - zipcode
    resource: https://jsonplaceholder.typicode.com/users
    value_template: "{{ value_json[0].name }}"

Thanks,

Jesper

You cannot use this in devtools, it will not make a call to the resource/url so no result = no value_json
You can easlly put this in your yaml and reload rest entities via YAML tab, i.e. normally it does not need a restart each time, just for the first rest-sensor that you create

1 Like

Hi,

Thanks vingerha, now i got the example from HA site to work but can’t get it to work from my own web page, am i overlooking something in the code.

rest:
 - resource: "https://172.16.1.14:8888/0/json"
   sensor:
     - name: "Json_UPS_Batcapacity"
       value_template: "{{ value_json.batCapcity }}"
  
     - name: "Json_UPS_Involt"
       value_template: "{{ value_json.inVolt }}"

 - resource: "http://date.jsontest.com/"
   sensor:
      - name: "Json_Time"
        value_template: "{{ value_json.time }}"

      - name: "Json_Date"
        value_template: "{{ value_json.date }}"

      - name: "Json_Milliseconds"
        value_template: "{{ value_json.milliseconds_since_epoch }}"

Thanks,

Jesper

Hi,

I have found the error I was supposed to add (verify_ssl: false).

so for it to work it should look like this:

rest:
 - resource: "https://172.16.1.14:8888/0/json"
   verify_ssl: false
   sensor:
     - name: "Json_UPS_Batcapacity"
       value_template: "{{ value_json.batCapcity }}"
  
     - name: "Json_UPS_Involt"
       value_template: "{{ value_json.inVolt }}"

Thanks for all the help,

Jesper

1 Like

@Jesperctc
I am curious how you get this data from the UPS?

If i try to access the endpoint /0/json at the UPSs IP address it just times out.
Are you using some other tool to pull this information from the UPS?