Extra keys not allowed @ data['min']

I have the following automation

- alias: Update OpenEVSE Min/Max Current
    id: update_openevse_min_max_current
    trigger:
      platform: state
      entity_id: sensor.openevse_rapi_gc
    condition:
      condition: template
      value_template: >-
        {{ state_attr('sensor.openevse_rapi_gc', 'ret') | regex_match('^\$OK [0-9]+ +[0-9]+') }}
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.openevse_pilot
          # Restrict the min to 6A - 10A
          min: >-
            {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
            {%- set rgx = '(?<=^\$OK) +([0-9]+) +([0-9]+)' -%}
            {%- set v = ret | regex_findall_index(rgx) -%}
            {{- [10, [6, v[0]|int]|max] | min -}}
          # Restrict the max to 16A even if L2 returns >16A
          max: >-
            {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
            {%- set rgx = '(?<=^\$OK )([0-9]+) +([0-9]+)' -%}
            {%- set v = ret | regex_findall_index(rgx) -%}
            {{- [16, v[1]|int]|min -}}

And it looks like after the 2021.11 updates it started throwing this error:

2021-11-06 13:31:58 ERROR (MainThread) [homeassistant.components.automation.update_openevse_min_max_current] Update OpenEVSE Min/Max Current: Error executing script. Invalid data for call_service at pos 1: extra keys not allowed @ data['min']
2021-11-06 13:31:58 ERROR (MainThread) [homeassistant.components.automation.update_openevse_min_max_current] Error while executing automation automation.update_openevse_min_max_current: extra keys not allowed @ data['min']

I am not sure why it complains about min as both min and max are required? Can anyone see anything else wrong?

The input_number.set_value service only accepts these options:

https://www.home-assistant.io/integrations/input_number/#services

To me, it seems like you’re approaching your problem from the wrong direction. I think you should be using a template sensor or a number template.

Yes but how about the min/max values, can they not be set also the same way?
image

No. Look at the service document I posted, it lists the only options you can supply, I highlighted them in pink so you would not miss them. The service is to set the value of the input number, not to reconfigure it.

Yes I see that, no data_template there either.
Maybe this automation used to work in the past, in some older version?
I did not create it myself, grabbed it from the forums here.
But as far as I can see the value does keep getting updated, so should it not work at all if that’s the case?
image

It never worked. Don’t use the forums for accurate information.

You can override the attributes, that doesn’t mean it will behave properly. Again, you should be using a template number.

1 Like

Listen to petro. You can set the min and max of a template number. You can’t do it for an input_number. Different kettles of fish.

Can you point me to where you grabbed it from? I’m interested to see the original version.

Cannot find the exact place I grabbed it from, there was a post which linked to a github.
But I did find out what was updating that value and it wasn’t that automation above but this one, so you are correct:

- id: update_input_number_openevse_pilot
    alias: Update input_number OpenEVSE Current
    description: >-
      Reflect changes made to pilot current on OpenEVSE back to the input_number
      slider position.
    trigger:
      platform: state
      entity_id: sensor.openevse_pilot
    condition:
      condition: template
      value_template: >-
        {{
           (states('sensor.openevse_pilot')|int >= state_attr('input_number.openevse_pilot', 'min')|int)
           and
           (states('sensor.openevse_pilot')|int <= state_attr('input_number.openevse_pilot', 'max')|int)
        }}
    action:
      - service: input_number.set_value
        data:
          entity_id: input_number.openevse_pilot
          value: "{{ states('sensor.openevse_pilot')|int }}"

Ok so I need a way to update both automations to use a template number instead of the input_number. I will try to work it out but if you have any examples as a starting point feel free to share :slight_smile:

no, you don’t need an automation, just a number template.

template:
- number:
  - unique_id: openevse_pilot
    name: Pilot
    state: "{{ states('sensor.openevse_pilot') }}"
    availability: "{{  states('sensor.openevse_pilot') not in ['unavailable','unknown'] }}"
    min: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK) +([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [10, [6, v[0]|int]|max] | min -}}
    max: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK )([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [16, v[1]|int]|min -}}

Thank you, but getting this message when trying to set up:
Invalid config for [template]: required key not provided @ data['number'][0]['set_value']. Got None required key not provided @ data['number'][0]['step']. Got None.

My code:

template:
- number:
  - unique_id: openevse_pilot_test
    name: Pilot Test
    state: "{{ states('sensor.openevse_pilot') }}"
    availability: "{{  states('sensor.openevse_pilot') not in ['unavailable','unknown'] }}"
    min: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK) +([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [10, [6, v[0]|int]|max] | min -}}
    max: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK )([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [16, v[1]|int]|min -}}

The sensor with the data:

Anything wrong there?

Let’s take a step back. What’s the point of this input number

There is a script which uses this value like so:

script:
  set_openevse_max_current:
    icon: mdi:content-save
    alias: OpenEVSE Set Pilot
    sequence:
      - service: rest_command.openevse_rapi
        data:
          host: !secret OPENEVSE_HOST
          rapi: "{{ '$SC ' ~ (states('input_number.openevse_pilot')|int) ~ (' V' if not is_state('input_boolean.openevse_save_current', 'on')) }}"

And the second automation above

So you don’t even use the input_number manually? I.E. from the UI? If so, why aren’t you just using a template sensor…

Sorry yes I use it in the UI, with that script
image

So you move the openEvse current slider? And what does set pilot do? post it here

See about 2 posts above, that’s the script.
And the rest_command:

rest_command:
  openevse_rapi:
    method: post
    timeout: 30
    username: !secret OPENEVSE_USERNAME
    password: !secret OPENEVSE_PASSWORD
    url: "{{ url | default('http://' ~ host ~ '/r?json=1&rapi=' ~ rapi, true) }}"

Then all you need is the number:

template:
- number:
  - unique_id: openevse_pilot
    name: Pilot
    step: 1
    state: "{{ states('sensor.openevse_pilot') }}"
    availability: "{{  states('sensor.openevse_pilot') not in ['unavailable','unknown'] }}"
    min: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK) +([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [10, [6, v[0]|int]|max] | min -}}
    max: >
      {%- set ret = state_attr('sensor.openevse_rapi_gc', 'ret') -%}
      {%- set rgx = '(?<=^\$OK )([0-9]+) +([0-9]+)' -%}
      {%- set v = ret | regex_findall_index(rgx) -%}
      {{- [16, v[1]|int]|min -}}
    set_value:
      - service: rest_command.openevse_rapi
        data:
          host: !secret OPENEVSE_HOST
          rapi: >
            $SC {{ value }} {{ '' if is_state('input_boolean.openevse_save_current', 'on') else 'V' }}

When you move the slider it will run the set. You can remove your script.