I’ve connected the P1 port of my smartmeter to a node-red node which reads the serial data and creates MQTT json payload.
I’m trying to read parts of the json payload and display that in Homeassistant but it generates parsing value errors.
Error:
2017-09-14 22:49:02 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: 'value_json' is undefined (value: {"smartmeter":{"timestamp":1505422143, "DeliveredKWTariff1":2821.950, "DeliveredKWTariff2":1774.072, "GeneratedKWTariff1":0.000, "GeneratedKWTariff2":0.000, "CurrentKWTariff":1, "CurrentWattDelivered":503, "CurrentWattGenerated":0, "DeliveredGasM3":01084.937}}, template: {{ value_json.DeliveredKWTariff1 }})
Configuration.yaml
sensor:
- platform: mqtt
state_topic: ‘smarthome/energy/smartmeter’
name: ‘Smartmeter - Verbruik kWH (tarief 1)’
unit_of_measurement: ‘kWH’
value_template: “{{ value_json.[“smartmeter”][“DeliveredKWTariff1”] }}”
What am i doing wrong?
TD22057
September 14, 2017, 9:11pm
2
Check the docs: https://home-assistant.io/docs/mqtt/processing_json/
[] is used for arrays. “.NAME” is used for sub-attributes. value_json.smartmeter.DeliveredKWTariff1 is what you want I think.
I’ve tried that before but that isn’t working:
2017-09-14 23:20:16 ERROR (MainThread) [homeassistant.helpers.template] Error parsing value: ‘value_json’ is undefined (value: {“smartmeter”:{“timestamp”:1505424017, “DeliveredKWTariff1”:2822.233, “DeliveredKWTariff2”:1774.072, “GeneratedKWTariff1”:0.000, “GeneratedKWTariff2”:0.000, “CurrentKWTariff”:1, “CurrentWattDelivered”:588, “CurrentWattGenerated”:0, “DeliveredGasM3”:01084.937}}, template: {{ value_json.smartmeter.DeliveredKWTariff1 }})
other json payload is working well.
Code:
platform: mqtt
state_topic: ‘smarthome/kitchen/fridge’
name: ‘Temperatuur Koelkast’
unit_of_measurement: ‘°C’
value_template: ‘{{ value_json[“koelkast”][“koelkast”] }}’
Payload:
{“koelkast”:{“koelkast”:4.125, “vriezer”:-13.437}}
gpbenton
(Graham)
September 15, 2017, 5:34am
4
You have an extra ‘.’ after value_json.
That was only a part of the solution, the reason why it did not work was that there was a leading zero in one of the json items.
Changed my node red flow/fuction to remove the leading zero in the DeliverdGasM3 item.
changed:
“DeliveredGasM3”:01084.937}},
to:
“DeliveredGasM3”:1084.937}},
And everything is woking fine now.
Thanks for your help…
1 Like