Struggling with particular JSON to get attributes (others work fine)

Hi, I’m struggling extracting attrubutes from the following JSON: (I have shortened the json, because it’s quite lengthy)
I have used the same JSON in Lua (as a table) using the following x[0-6][Mon-Sun][h00-h23]
If i use the attribute path "$.*" (or no attribute path, or "$.[*]" ) the result is one attribute: “Mon” with the dictionary key-value paires. Any other paths I tried result in “None”, or complaints that it’s not a dictionary.
How to get the other attributes, "Thu" etc.
I’ve read and reread examples and answers to other peoples questions. I’ve used JSONPath online evaluator. To no avail.
What an I doing wrong? (probably something obvious and stupid, but I’m stuck)
Help is really appreciated.

[
{
"Mon": {
"h00": "45",
"h01": "45",
"h02": "45",
"h22": "45",
"h23": "45"
}
},
{
"Thu": {
"h00": "45",
"h01": "45",
"h22": "45",
"h23": "45"
}
},
{
"Sun": {
"h00": "45",
"h01": "45",
"h19": "50",
"h20": "50",
"h21": "50",
"h22": "45",
"h23": "45"
}
}
]

The configuration of the RESTfull:

  - platform: rest
    name: "Tesy P1"
    value_template: "OK"
    timeout: 50
    scan_interval: 1800
    resource: http://192.168.68.121/getP1
    json_attributes_path: "$.[*]"
    json_attributes:
      - "Mon"
      - "Tue"
      - "Wen"
      - "Thu"
      - "Fri"
      - "Sat"
      - "Sun"

I use a rest sensor to grab a json payload with more than one attribute, but the json is structured differently:

[
{
“label”: “Address Here”,
“UPRN”: “1234567890”,
“Results”: “A load of text would be in here about my rubbish collection”
}
]

So all the attributes are at the top level.
When you look at your json, Mon, Tues etc are wrapped in braces. I’m not an expert, but that seems the only obvious difference between yours and mine that works. My sensor looks like this

- platform: rest
  name: bin_collection_restful
  resource: someurlhere.
  timeout: 15
  scan_interval: 43200 # 12 hours
  json_attributes:
    - label
    - Results
  value_template: 'OK'

The attributes are at different leves hence it won’t work.
Options

  • use command_line curl and then jq to filter it out
  • load all attribs in the sensor and create sunsensors out of that
  • use different rest sensors where you change the attributes path to $.0, $.1, etc.

Thank you. Yes, the top level keys array’s are at 0, 1 etc. Tried that, but that results in None. Funny things is that I get Mon even though it is deeper in the JSON.
Edit: As @fingerha noted, these are not keys, just the index numbers

Many thank to all for helping me out on this! (I’m a little embarrassed)

Thank you, that might be a solution one rest and seven sensors. I will try that.
However, why doesn’t
Attributes:

  • 0
  • 1
    Etc not work?

As these are no attributes

So if you put $ as attributes path and Mon as attribute you get that? That would be interesting and … why hot continue on that path

This worked: " * use different rest sensors where you change the attributes path to $.0, $.1, etc."
(See code below)
Thanks, you’ve made my day :slight_smile:

rest:
  - resource: http://192.168.68.121/getP1
    scan_interval: 1800
    sensor:
      - name: "Tesy P1 Mon"
        json_attributes_path: "$.0"
        value_template: "OK"
        json_attributes:
          - "Mon"
      - name: "Tesy P1 Tue"
        json_attributes_path: "$.1"
        value_template: "OK"
        json_attributes:
          - "Tue"
      - name: "Tesy P1 Wen"
        json_attributes_path: "$.2"
        value_template: "OK"
        json_attributes:
          - "Wen"
      - name: "Tesy P1 Thu"
        json_attributes_path: "$.3"
        value_template: "OK"
        json_attributes:
          - "Thu"
      - name: "Tesy P1 Fri"
        json_attributes_path: "$.4"
        value_template: "OK"
        json_attributes:
          - "Fri"
      - name: "Tesy P1 Sat"
        json_attributes_path: "$.5"
        value_template: "OK"
        json_attributes:
          - "Sat"
      - name: "Tesy P1 Sun"
        json_attributes_path: "$.6"
        value_template: "OK"
        json_attributes:
          - "Sun"

Hello Akja,
For what kind of Tesy device this is?
I have the Tesy boiler, which is working fine in HA, as another forum topic has excellent support on it.
Now, I also bought a Tesy convector heater (LivEco CN 051) and I didn’t find any forum topic on this device for the HA integration.
From what I get of your post, it is about interacting with a Tesy device, but I don’t know which one?

It’s a Tesy ModEco boiler with wifi. (ModEco Cloud they call it now)

Right. Thanks for clarifying this.
Were you aware of this topic: New electric water heater / boiler (integrated with HA) - #84 by ValeriGYordanov
Think it addresses your questions too? Maybe not, I’m not sure.

Thanks for pointing out that topic. I solved my problem, but it’s always interesting to read other solutions. I had solved controlling the Tesy boiler in Domoticz, several years ago, using dzVents. However, ‘programming’ in Home Assistant is very different. Yaml feels like filling in a tax return form, with some coding fragments. :slight_smile: