Just wanted to put this here for future reference:
I have a smartmeter that enacpsulates its data over MQTT in JSON like so:
{
"timestamp":"23.10.2023 22:12:36",
"+A":77.205,
"-A":0,
"+R":2.152,
"-R":185.659,
"+P":647,
"-P":0,
"+Q":7,
"-Q":204
}
using this in a sensor like this:
- name: "energy_P"
unique_id: "energy_P"
state_topic: "house/smartmeter/state"
unit_of_measurement: "W"
value_template: "{{ value_json.+P }}"
just gives an error on the last line, because âvalue_json.+Pâ does not parse correctly.
But since âvalue_jsonâ is a dictionary, we can write
value_template: "{{ value_json['+P'] }}"
instead and it works fine!
(Note the single quotes, since double quotes are already used on the outside!)