\newcommand for a specific chapter

I write a document with LyX, to which I add PSTricks pictures in ERT sections.

I defined a `\newcommand` in a certain ERT section, and it was available during this ERT section, but not available in the next ERT section.

I don't want to define this command in the preamble, because it is specific to a chapter.

How can I define a `\newcommand` that will be available in all ERT sections of a given chapter?

After the chapter title hit `Ctrl-L` for ERT and then insert
``````\begingroup
``````\endgroup