I am trying to let "services.yaml" to fill the YAML part of my service-call

I am using following service call in the dev-tools to test a python script service “set_state”:

service: python_script.set_state
data:
  entity_id: input_number.huis_gasverbruik_het_laatste_hele_uur
  state: "{{states('sensor.huis_gasverbruik')}}"
  allow_create: true

This one works and does what is expected.
Then I created the following services.yaml in the /python_scripts folder, for better documenting. as pointed out in: “Phyton Scripts”:

set_state:
  name: Zet gasverbruik
  description: Detecteer een spike d.m.v. trigger en maak deze geldig voor het hele uur
  fields:
    entity_id:
      description: The input-identity to get a new state
      example: input_number.huis_gasverbruik_het_laatste_hele_uur
      default: input_number.huis_gasverbruik_het_laatste_hele_uur
    state:
      description: The state you want to take over
      example: "{{states('sensor.huis_gasverbruik')}}"
      default: "{{states('sensor.huis_gasverbruik')}}"
    allow_create:
      description: Recreates the input-identity (when <true>), when needed.
      example: true
      default: true

When I put the last part in place and reload, I’m getting indeed a nice template and when I press the “Fill examples” button everything is nicely filled, but for the line with “state” I’m getting a strange result:

service: python_script.set_state
data:
  entity_id: input_number.huis_gasverbruik_het_laatste_hele_uur
  state:
    "[object Object]": null
  allow_create: true

I’m new to HA (not to home automation and programming), can somebody point me in the right direction to get this working? I did already try variants with single quotes less accolades etc. but no joy.

I don’t know the answer to your question, but are you aware that setting an entity’s state via a python_script is not permanent? The entity’s state will revert to its previous value after a restart. You can prove it to yourself by using the python_script to set the state of a binary_sensor or sensor and then restart Home Assistant.

Helpers represent an exception but there should be no need to use a python_script to set a helper’s value because they have services. For example, if you want to set an Input Number to a specific value, use one of its service calls like input_number.set_value.

Thanks. This is for an hourly reset value, if the systems re-starts, it will pick up again, that is why I used the “allow_create: true” . You are right, I would have better used the “input_number.set_value” you are proposing, that is my inexperience. Still I do think there should be a way to get this into the “services.yaml”. I saw, looking up “input_number.set_value”, that someone had about the same problem, then it was the difference between “data” and “data_template” in “automations.yaml” (which worked for me), but that shouldn’t make a difference anymore nowadays, “data_template” being depreciated and I already tried that.

service: input_number.set_value
target:
  entity_id: input_number.huis_gasverbruik_het_laatste_hele_uur
data:
  value: "{{ states('sensor.huis_gasverbruik') | int(0) }}"

Thank you !