Retrieving Climate properties

In Developer Template I put:

{{ state_attr('climate.wts','status')  }}

In response I get:

{'setpoints': {'this_sp_from': '2020-04-29T00:00:00+10:00', 'this_sp_temp': 24.0, 'next_sp_from': '2020-04-29T07:00:00+10:00', 'next_sp_temp': 20.0}, 'zone_id': '2113469', 'active_faults': [], 'setpoint_status': {'target_heat_temperature': 15.0, 'setpoint_mode': 'FollowSchedule'}, 'temperature_status': {'temperature': 17.5, 'is_available': True}}

How do I extract each of these sub-items elegantly?

state_attr('climate.wts','status')['setpoints']['temperature_status']['temperature']

accessing a dictionary stuff = {'item':'value'} is stuff['item'] returns 'value'.

So you have to walk through your setup and grab each item from each dictionary. i.e. nested dictionary…

stuff = {'junk':{'crap':'value'}}
stuff['junk']['crap']

returns value

I get an error when trying to parse that JSON though.

it’s not json, it’s a dictionary from jinja. You can tell by the use of ' instead of ". JSON requires double quotes for it’s dictionaries. When converted into python/jinja land, those surrounding characters may change.

I get Error rendering template: UndefinedError: ‘dict object’ has no attribute ‘temperature_status’
I see no typos. Your code matches the data but …

ah because i made a typo

state_attr('climate.wts','status')['temperature_status']['temperature']
1 Like

Not with yours, when I try to parse the originally pasted data.

thanks, I just worked it out too.