Setting sensor value in automation not working

I’m new to homeassistant and been strugling to set a value for a sensor in an automation. But nothing works. Can someone help?

In configuration.yaml
template:

  • sensor:
    • name: test_sensor
      unique_id: test_sensor
      state: >-
      {{ states(‘sensor.p1p2_056_s1_compressor_onoff’) | int (0) }}

In automation
action:

  • service: number.set_value
    target:
    entity_id: sensor.test_sensor
    data:
    value: “{{ states(‘sensor.elec_verbruik’) | float(0) * 10 }}”

Result: 2023-11-28 09:22:01.840 WARNING (MainThread) [homeassistant.helpers.service] Referenced entities sensor.test_sensor are missing or not currently available

Please see section 11: How to help us help you - or How to ask a good question

You can not set the value of a sensor with the number.set_value service. That only acts on number entities. e.g. number.my_test_number.

Please explain what you are trying to achieve rather than your chosen solution, see https://xyproblem.info/ there is probably a better way.

tx for your answer!

I’m really new to homeassistant and i’m still strugling with the syntax. What i am trying to achieve is very simple. I want a entity which has to change it’s (numeric) value when a trigger (and conditions) are executed.

That is still your chosen solution rather than your problem. However…

One way would be to use an input number and an automation.

Another way would be a triggered template sensor but these do not have conditions so you would have to build that into the state template.

You are absolutely right, but the input number works!