- 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?
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?
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
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 -}}