Using attribute data of sensor = undefined when spaces in attribute (Solved)

I know this is easy, but my searching for an hour has not solved. I’m trying to use change node to set a flow to a value from the sensor attributes. This is sensor data:

in the change node: i have:
Screenshot 2023-12-12 112610

But I’m getting undefined in debug. What should the value be?

Template works like this
template:

  • sensor:
    • name: state of charge
      state: “{{ (state_attr(‘sensor.fordpass_elvehcharging’, “State of Charge”)) }}”

So i’ll just create a template helper

Whilst HA does a nice job of turning spaces in names into underscores, Node-RED does not.

Where the JSON key contains spaces (and also apparently ‘-’ which is seen as a minus sign) you need to use the ‘[ ]’ syntax as the ‘.’ property accessor does not work.

data.attributes[‘State of Charge’] should do it

1 Like

Thank you. I created the template helper sensor, but will also try this. Also updated post title to help others when searching.