Altering the state of an input_number

I’m getting these 3 errors when attempting to set the state of an input_number:

2023-01-04 15:18:00.011 ERROR (MainThread) [homeassistant.components.automation.sprinker_water_control] Sprinkler Water Control: Choose at step 1: choice 1: Error executing script. Error for call_service at pos 1: Error rendering data template: Result is not a Dictionary
2023-01-04 15:18:00.014 ERROR (MainThread) [homeassistant.components.automation.sprinker_water_control] Sprinkler Water Control: Error executing script. Error for choose at pos 1: Error rendering data template: Result is not a Dictionary
2023-01-04 15:18:00.020 ERROR (MainThread) [homeassistant.components.automation.sprinker_water_control] Error while executing automation automation.sprinker_water_control: Error rendering data template: Result is not a Dictionary

The code in question is this:

action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: trigger
                id: calc_rain_delay
        sequence:
          - service: input_number.set_value
            target:
              entity_id: input_number.sprinkler_rain_delay_days
            data: >-
              {% set rain_delay = (states('input_number.sprinkler_rain_delay') |
              float(0)) %} {% if rain_delay >= 1.0 %}
                {% set rain_delay = rain_delay - 1.0 %}
              {% endif %} {% set addl_rain_delay =
              ((states('sensor.miriam_daily_rain')) | float(0) / 0.25) %} 
              {% set new_rain_delay = (rain_delay  + addl_rain_delay) | round(0)  %}
              state: "{{ new_rain_delay }}"

The last statement of jinja seems to be the issue. How do I update the input number’s state using a dictionary?

You have a couple issues in your template.

  1. You cannot build yaml configuration variable keys with Jinja. You can use Jinja templates to render/calculate the values you want to have assigned to keys.
  2. state is not a valid variable key for an input_number.set_value service
  3. Your and condition isn’t doing anything.
action:
  - choose:
      - conditions:
          - condition: trigger
            id: calc_rain_delay
        sequence:
          - service: input_number.set_value
            target:
              entity_id: input_number.sprinkler_rain_delay_days
            data:
              value: >
                {% set rain_delay = (states('input_number.sprinkler_rain_delay') | float(0)) %}
                {% if rain_delay >= 1.0 %}
                {% set rain_delay = rain_delay - 1.0 %} {% endif %} 
                {% set addl_rain_delay = ((states('sensor.miriam_daily_rain')) | float(0) / 0.25) %} 
                {% set new_rain_delay = (rain_delay  + addl_rain_delay) | round(0)  %}
                {{ new_rain_delay }}

I’ve been down that path with yaml with (if/then) and it’s messy doing it that way.

Regarding #1. According to the docs using Jinja in a data template should be acceptable as of recent update. I only need to figure out how to export the final output to the service call its embedded in.

I need to do math somewhere in the yaml. for the desired calculations. Can you provide
some info on how to combine the yaml and the jinja in order to do this.

I’ve been through the docs several times and cannot find any way to do what I need to do.

I do concur on the and conditon not doing anything. It’s there for future expansion.

Drew did already:

I didn’t see it the first time around. My apologies.