Runtime Summary API

I’m using the API to get the runtime summary but I don’t understand what the runtime_thermostat_summary_id is. It seems I have to determine that value first before I can drill down to get detailed info. Is that correct? I’m using TCL and I convert the JSON to a DICT and when I check the data key I get the entire remainder of the JSON when I just want the id so I can drill down to get just the data I want. Does this make sense?

Any recommendations?

Thanks,

Bob

You don’t actually need the runtime_thermostat_summary_id for anything. That’s just a unique ID for that specific row in my database. Beestat typically returns data in objects with the ID pointing at the data.

I believe in your cases you just want to use dict values to turn that object into an array you could iterate over. That should throw away those IDs.

Hi Jon,

So in TCL, after converting the returned data to a dict, I would normally have to use the following to get the date:

set hpdate [dict get $api data $therm_id date]

where $api is the dict created from the JSON returned from my request, data is the key value, and $therm_id is the ID. If I just use:

set hpdate [dict get $api date] without drilling down I get an error.

I can get the therm_id by using a string command to get the value from the $api variable like this:

set therm_id [string range $api 19 26] but that doesn’t seem like good practice.

Maybe I need to check in with some TCL folks who are way more knowledgeable than me.

Thanks,

Bob

I’m not too familiar with TCL, but one of the following might work.

Normally you would want to loop over the records; something like this:

set records [dict get $api data]

foreach therm_id [dict keys $records] {
    set rec_data [dict get $records $therm_id]
    set hpdate   [dict get $rec_data date]

    # do whatever you need with $hpdate here
}

If you just care about the first record, you could do this:

set records [dict get $api data]
set therm_id [lindex [dict keys $records] 0]
set hpdate   [dict get $records $therm_id date]

Thanks Jon, I’ll try these ideas and let you know how I make out.

Bob

Jon,

The second method worked perfectly and I am now able to access any or all of the items in the summary.

Thanks for the help - greatly appreciated. I definitely appreciate Beestat.

Bob

1 Like