"Template variable warning" from EVSE-WiFi

I get frequent “Template variable warning” from my smartwb implementation and I’m not able to find the problem. In fact, all values are correct in HA and the implementation is working.

Query the smart wallbox with “getParameters” in a browser looks like that:


In raw format:
{"type":"parameters","list":[{"vehicleState":2,"evseState":false,"maxCurrent":16,"actualCurrent":6,"actualPower":0,"duration":4519000,"alwaysActive":false,"lastActionUser":"GUI","lastActionUID":"GUI","energy":5.83,"mileage":34.3,"meterReading":11.66,"currentP1":0,"currentP2":0,"currentP3":0,"useMeter":true}]}

Implementation of the template looks like that:

smartwb is just the template’s name, values are correct. But why do I get this fault messages in the logfile:

2023-08-09 14:34:33.802 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'smartwb' when rendering '{{ value_json.smartwb }}'
2023-08-09 14:34:43.808 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'smartwb' when rendering '{{ value_json.smartwb }}'
2023-08-09 14:34:53.805 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'dict object' has no attribute 'smartwb' when rendering '{{ value_json.smartwb }}'

Whatever you say, you’re actually trying to extract a non-existing smartwb attribute from the json

image

Oh, and never post screenshots of code, only formatted text

Thx @koying!
I assumed something like this… I’m not yet familiar with the templates as you might have noticed.
Can you give me a hint how I could get rid of the fault message? How or what do I have to change that the JSON string from above gets parsed correctly?
I already tried to remove smartwb from value_json.smartwb, but then the implementation stops to work.

Sorry for posting pics instead of code. :pensive:

Here once more the part from config.yaml:

sensor:
  # smartWB
  - platform: rest
    name: smartWB
    headers:
      accept: "application/json" 
    authentication: basic
    scan_interval: 10
    resource: http://192.168.1.69/getParameters
    json_attributes_path: "$.list.[0]"
    value_template: "{{ value_json.smartwb }}"
    json_attributes:
      - "vehicleState"
      - "evseState"
      - "actualCurrent"
      - "actualPower"
      - "duration"

  - platform: template
    sensors:
      smartwb_actualcurrent:
        friendly_name: "Actual Current"
        unit_of_measurement: "A"
        device_class: "current"
        value_template: '{{ states.sensor.smartwb.attributes["actualCurrent"] }}'
      smartwb_actualpower:
        friendly_name: "Actual Power"
        unit_of_measurement: "kW"
        value_template: '{{ states.sensor.smartwb.attributes["actualPower"] }}'
      smartwb_duration:
        friendly_name: "Duration"
        unit_of_measurement: "Minutes"
        value_template: '{{ ((states.sensor.smartwb.attributes["duration"] | int / 60000 | round(1) )) }}'
      smartwb_vehiclestate:
        friendly_name: "Vehicle State"
        value_template: >-
          {% set mapper = ['Unknown', 'Ready', 'Detected', 'Charging'] %}
          {{ mapper[states.sensor.smartwb.attributes["vehicleState"] | int] }}

As you obviously don’t need a state, just that will do

value_template: "OK"
1 Like

lol - that did the trick. :yum:

For my understanding: I don’t need the value_template: at all since I don’t use state in my template?

THX a lot!