Using API to reset state after changing the state

Hi, sorry if this is the wrong place for this question was going to add it to development section but that seemed more like if you were developing add ons to HA.

I am creating a python script that I will monitor a separate service, and perform actions to change state of items within home assistant, mainly lights.

I am trying to do a proof of concept where I have helpers created that is a collection of light where the entity is called something like light.bedroom_lights. Each of these bulbs within this collection is set to a different colour.

I first of all do a GET request to get the current state of the lights by sending a request to “http://homeassistant.local:8123/api/states/light.bedroom_lights

I then send a POST request to turn them off, wait 5 seconds and then turn them back on passing an rgb_color attribute to the body of the request to set all lights to white, then wait 2 seconds and then turn the lights off again.

Want I then want to do, is restore the original state that the lights were on before so I send a post request to “http://homeassistant.local:8123/api/states/light.bedroom_lights” passing the state that I returned earlier as the JSON data. I understand this action doesn’t actually change the lights themselves just updates the internal state within HA.

However when I call the URL to the lights back on again, this time just passing the entity id, I was expecting they would come back on with the state they were originally due to the prior state setting request being done.

Am I going about this the right way, or is there another way that I need to maintain the original state and restore the state back to how it was.

Thanks for any help in advance.

Chris