How to state for entity "manually" in automation?

In Developer Tools → States, I can set a state for an entity manually. Is there a way to do this in an automation or script as well?

No. That option in developer tools is just for debug and testing. Integrations manage the state of their entities, not automations, scripts or users.

If you need an variable-like entity where one automation sets a value that another can look at, create an input-type helper (input text, input number, input boolean, etc.)

Rodpayne created a python_script to do that.

However, be advised that if you change a sensor’s state value using either Developer Tools > States > Set State or python_script.set_state, the change is temporary. The new value is overwritten the next time the sensor’s integration updates it or when you restart Home Assistant.

Developer Tools > States > Set State is useful for testing an automation because you can temporarily force a sensor’s value in order to test an automation’s trigger. For example, instead of waiting for a temperature sensor to increase naturally, to trigger an automation with a Numeric State Trigger, you can manually increase the temperature sensor’s value with Set State.