Hello team,
I have gone through all the posts I can find on JSON formatting and have not had much luck.
Here is my code:
`
-platform: rest
name: Sonnen Battery
scan_interval: 60
json_attributes:
- M03
- M04
- M05
- M38
- M39
resource: !secret sonnen_api
value_template: '{{ sonnen_json }}'
- platform: template
sensors:
sonnen_currentpvpower:
friendly_name: 'Sonnen Battery Current Solar Power Production'
value_template: '{{ sonnen_json.M03 }}'
unit_of_measurement: 'W'
entity_id: sensor.sonnen_currentpvpower
sonnen_consumption:
friendly_name: 'Sonnen Battery Current Power Consumption'
value_template: '{{ sonnen_json.M04 }}'
unit_of_measurement: 'W'
sonnen_soc:
friendly_name: 'Sonnen Battery State of Charge'
value_template: '{{ sonnen_json[11].M05 }}'
unit_of_measurement: '%'
sonnen_gridfeed:
friendly_name: 'Sonnen Battery Current Grid Feed-In'
value_template: '{{ (sonnen_json[21].M38 | float / 1000) | round(2) }}'
unit_of_measurement: 'kW'
sonnen_gridpurchase:
friendly_name: 'Sonnen Battery Current Grid Consumption'
value_template: '{{ (sonnen_json[22].M39 | float / 1000) | round(2) }}'
unit_of_measurement: 'kW'
`
I can get one device that has all the values (see screen shot) but my sensors all come back blank.
Any advice?
Here is the raw JSON output
{"C06":10,"C07":0,"C08":0,"C09":0,"C10":0,"C11":0,"C12":0,"C23":0,"C24":0,"M03":0,"M04":788,"M05":95,"M06":10,"M07":660,"M08":128,"M09":0,"M30":95,"M31":6816000,"M34":0,"M35":0,"M37":32689.15,"M38":0,"M39":684,"M40":11267.88,"M41":5806.29,"S01":160,"S07":"US-85339","S08":15,"S15":"45119","S16":"5.01 (405)","S65":8000,"S66":"son","S69":16000,"S70":"3.5","S71":"FALSE"}
Using the template editor, this format works
`
{% set sonnen_json={“C06”:10,“C07”:0,“C08”:0,“C09”:0,“C10”:0,“C11”:0,“C12”:0,“C23”:0,“C24”:0,“M03”:0,“M04”:788,“M05”:95,“M06”:10,“M07”:660,“M08”:128,“M09”:0,“M30”:95,“M31”:6816000,“M34”:0,“M35”:0,“M37”:32689.15,“M38”:0,“M39”:684,“M40”:11267.88,“M41”:5806.29,“S01”:160,“S07”:“US-85339”,“S08”:15,“S15”:“45119”,“S16”:“5.01 (405)”,“S65”:8000,“S66”:“son”,“S69”:16000,“S70”:“3.5”,“S71”:“FALSE”}%}
value_template: '{{ sonnen_json}}'
- platform: template
sensors:
sonnen_currentpvpower:
friendly_name: 'Sonnen Battery Current Solar Power Production'
value_template: '{{ sonnen_json.M03 }}'
unit_of_measurement: 'W'
entity_id: sensor.sonnen_currentpvpower
`
But that gives me blank sensors in the UI.
Any ideas or help?
Thanks!