Hi there, I’ve been using a REST API call to get some solar PV power consumption data from my inverter into home assistant. I’ve got the easy values imported such as pv_to_date and pv_today into the sensors, by referencing value_json.stats.kpis.pv_to_date and value_json.stats.kpis.pv_today, as these are easily identifiable at the end of the data feed. However I’m struggling to get the consumed energy for today into a sensor. As you can see below, the data structure has an inverter serial number, followed by each day of month and a corresponding value. So I’d like to get the consumed value matching today’s date (i.e. ‘stats’.‘graphs’.‘consumed_energy’.‘2731042228110002’.. into a sensor for using in the HA energy tab.
I’ve been trying a few things but I’m not knowledgeable enough in coding yet… .
- name: "consumed_today"
value_template: >
{% set today = now().strftime('%Y-%m-%d') %}
{% set items = value_json | selectattr('stats'.'graphs'.'consumed_energy'.'2731042228110002','eq',today) | list | first %}
Can anyone show me how to get appropriate value, and can it be retrieved at the same time as I gather the other sensor data?
{
"stats": {
"graphs": {
"pv_energy": {
"2731042228110002": {
"2023-12-01": 0,
"2023-12-02": 0,
"2023-12-03": 0,
"2023-12-04": 0,
"2023-12-05": 0,
"2023-12-06": 0,
"2023-12-07": 0,
"2023-12-08": 0,
"2023-12-09": 0,
"2023-12-10": 0,
"2023-12-11": 1,
"2023-12-12": 2,
"2023-12-13": 5,
"2023-12-14": 1,
"2023-12-15": 0,
"2023-12-16": 0,
"2023-12-17": 0,
"2023-12-18": 0,
"2023-12-19": 0,
"2023-12-20": 0,
"2023-12-21": 0,
"2023-12-22": 0,
"2023-12-23": 0,
"2023-12-24": 0,
"2023-12-25": 0,
"2023-12-26": 0,
"2023-12-27": 0,
"2023-12-28": 0,
"2023-12-29": 0,
"2023-12-30": 0,
"2023-12-31": 0
}
},
"consumed_energy": {
"2731042228110002": {
"2023-12-01": 0,
"2023-12-02": 0,
"2023-12-03": 0,
"2023-12-04": 0,
"2023-12-05": 0,
"2023-12-06": 0,
"2023-12-07": 0,
"2023-12-08": 0,
"2023-12-09": 0,
"2023-12-10": 1,
"2023-12-11": 3,
"2023-12-12": 19,
"2023-12-13": 33,
"2023-12-14": 14,
"2023-12-15": 0,
"2023-12-16": 0,
"2023-12-17": 0,
"2023-12-18": 0,
"2023-12-19": 0,
"2023-12-20": 0,
"2023-12-21": 0,
"2023-12-22": 0,
"2023-12-23": 0,
"2023-12-24": 0,
"2023-12-25": 0,
"2023-12-26": 0,
"2023-12-27": 0,
"2023-12-28": 0,
"2023-12-29": 0,
"2023-12-30": 0,
"2023-12-31": 0
}
},
"no_comms": [
]
},
"kpis": {
"pv_today": 1,
"pv_month": 6,
"pv_to_date": 6
}
}
}
Thanks in advance.