Python script "hass.set.state" not working

I have a question about the python script abillity in Home Assistant.

I am trying to set a state of a non existing entity. On the Home assistant page it says it can be done with hass.states.set. This does not seem to be working for me. What am I doing wrong?

https://dev-docs.home-assistant.io/en/master/api/core.html#homeassistant.core.StateMachine

hass.states.set("sensor.file", "off", attributes, force_update=True)