Help please - trying to calculate a number for number.set_value

Hi.
I’m trying (and failing) to set a battery discharge rate, so I can discharge my giv battery in the evening, before charging it again overnight.
In an Automation, I have a working trigger and condition, but can’t figure out how to get maths into the action, to calculate the required discharge rate. The idea is that at 9:00pm, I check the SoC, work out a suitable discharge rate so it’s down to 20% at 11:30pm, then switch to charging again.

What I have so far:

action: number.set_value
target:
  device_id: 9117e75e28fdd3274821c26a73c4dd0c
  entity_id: number.givtcp_cexxxxxxxx_battery_discharge_rate
data: 
  {% set DischargeRate = states('sensor.givtcp_cexxxxxxxx_soc') * 3000 | float %}  
  {{DischargeRate }}


I've had many error messages as I've played with quotes and alternative structures. The error message for this try is:
Action YAML contains syntax errors, please fix the syntax

Any help much appreciated.
thanks, Dave

Please format your configuration properly so we can tell what is wrong.

Compare what you have to this:

action: number.set_value
target:
  entity_id: number.givtcp_cexxxxxxxx_battery_discharge_rate
data:
  value: "{{ states('sensor.givtcp_cexxxxxxxx_soc') | float(0) * 3000 }}"

Question for you:
Your example specifies an entity_id and a device_id. Are you trying to set the value of two number entities?


EDIT

Correction. Forgot to include the value option.

1 Like

Done!
Thank you for the guidance on how to do it.

" Your example specifies an entity_id and a device_id. Are you trying to set the value of two number entities?"
No. I used the graphical editor to provide an example of what’s needed, and it came up with the 2 entries. Then tried to edit it in yaml, and have been fixated on the maths ever since. Staying with just the entity seems logical.

I’ve tried the example you provided (with the value line), and it worked - thank you so much!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.