Page 1 of 1

Help Needed

Posted: Sat Mar 23, 2024 4:45 pm
by chris01942
Hi, hope someone has the time to help. I'm trying to set an action for an automation I want to do, but I think it needs a template which I'm no good at :|

I would like, depending on the Agile price, to use the current battery SoC value to set the same value for min SoC on grid, so my battery stops discharging during that period.

This is how far I've got (not very far!) but it doesn't input the value for min SoC on grid. I've spent hours looking at the code here & trying various ways, but can't work it out due to my lack of knowledge with templates


service: input_number.set_value
data_template:
value: "{{states('sensor.battery_soc')}}"
target:
entity_id: number.min_soc_on_grid

Thanks, Chris

Re: Help Needed

Posted: Sat Mar 23, 2024 6:26 pm
by Dave Foster
Hi Chris,

I think this should do what you need -

You have to use number.set_value not input_number.set_value,.

I’ve done it in 2 steps first to load battery_soc into the variable BSoC, set as an integer with a default value of 10 (just in case it’s unavailable) then write it out via the {{ templates }}

Code: Select all

service: number.set_value
data:
  value: >-
    {% set BSoC = states('sensor.battery_soc')|int(10) %}
    {{ BSoC }}
target:
  entity_id: number.min_soc_on_grid


Re: Help Needed

Posted: Sun Mar 24, 2024 4:41 pm
by chris01942
Dave Foster wrote: Sat Mar 23, 2024 6:26 pm Hi Chris,

I think this should do what you need -

You have to use number.set_value not input_number.set_value,.

I’ve done it in 2 steps first to load battery_soc into the variable BSoC, set as an integer with a default value of 10 (just in case it’s unavailable) then write it out via the {{ templates }}

Code: Select all

service: number.set_value
data:
  value: >-
    {% set BSoC = states('sensor.battery_soc')|int(10) %}
    {{ BSoC }}
target:
  entity_id: number.min_soc_on_grid

Hi Dave, many thanks for that, it worked a treat :D