[WIP] rename state with entity

Fixes #599, at least for new entity changes. (I'll look at a script to handle this for previous entity name changes, using much of the same logic.)

Ready for discussion, but probably not for merging just yet.