Calculate and add custom attribute

I have a smart plug where the data point home assistant shows is total kwh. I want to show the current watts and I’m able to calculate the data I need in node red but I can’t figure out how to add this as an attribute to the switch. Is this possible at all, let alone through node red? I assumed this would be a service call but I can’t find a service that does what I want.

You could do this using a python_script which would read the current state of the entity using hass.states.get(), modify its attributes to add the new attribute, and then write it back to the state machine using hass.states.set(). Of course, if the entity overwrites its state after that…

I don’t use node red, so I can’t answer that part, but I suspect it gives you access to the same methods for getting and setting states from/to the state machine.