How to define a rule which changes the value of a string?

You are triggering on an update but

but are trying to see what the value of a command is. But no command actually happened, so receivedCommand doesn’t exist!

See if the table on this page helps:

https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html

or this section of the Rules doc: