Help with home assistant YAML to reduce clipping

9 comments started 2024-03-05 last 2024-03-06
Home AutomationGivEnergy ProductsHybridBatteryHome Assistant
Q
#1 Qyaunos1

Hi,

I have got this script from facebook (Greg at givenergy) and tried dumping it in to my config.yaml file.

However, homeassistant doesn't seem to like it. Can someone point out where I have gone wrong please and what I need to amend?

FYI - its to reduce clipping by utilising battery charge after solar production goes above 5Kwh

Home assistant is throwing out the following error

duplicated mapping key (47:1)

44 | entity_id: number.givtcp_ ...
45 | mode: single
46 |
47 | alias: Prioritise Export - Rese ...
------^
48 | description: ""
49 | trigger:

Script start

sensor:

  • platform: template
    sensors:
    charge_rate:
    friendly_name: "Dynamic Charge Rate"
    unit_of_measurement: "W"
    value_template: >
    {% set original_value = states('sensor.givtcp_FD2250G421_pv_power')|float %}
    {% set adjusted_value = original_value - 5000 %}
    {{ adjusted_value if adjusted_value > 0 else 0 }}

alias: Prioritise Export
description: ""
trigger:

  • platform: time_pattern
    seconds: /60
    condition:
  • condition: time
    after: "06:00:00"
    before: "15:44:00"
  • condition: state
    entity_id: input_boolean.prioritise_export
    state: "on"
    action:
  • service: number.set_value
    data:
    value: "{{states('sensor.charge_rate')|float}}"
    target:
    entity_id: number.givtcp_fd2250g421_battery_discharge_rate
    mode: single

alias: Prioritise Export - Reset Charge Rate @ 1545
description: ""
trigger:

  • platform: time
    at: "15:45:00"
    condition: []
    action:
  • device_id: 5f75f57ebceacf500a639469e4eef245
    domain: number
    entity_id: 33e17bf2448db1cdb887317c4a517366
    type: set_value
    value: 2900
    mode: single
#2 PianSom

Qyaunos1
It's almost certain that you have messed up the spaces in the yaml file. SO easy to do. But it's impossible to tell from the way you have pasted the code here.

Try pasting it again but either
(1) use the code button (which looks like "</>") at the bottom of the input panel here after you have pasted and selected the code, or
(2) use three back ticks to start and end the code you paste
like this ```

to give you this
Q
#6 Qyaunos1

PianSom Thank you for responding also and taking a look at it

#7 PianSom

Qyaunos1
Just to check - you are putting the two automations into automations.yaml (and not configuration.yaml) - right?

Q
#8 Qyaunos1

PianSom I wasnt originally I was dropping it in to config.yaml but have just tried to put it in to automations.yaml.

Now getting the following error

end of the stream or a document separator is expected (109:1)

106 | {{ adjusted_value if ...
107 |
108 |
109 | alias: Prioritise Export
-------^
110 | description: ""
111 | trigger:

Q
#9 Qyaunos1

PianSom I think I have figured it out! I was dropping the entire script in to config.yaml and then automations.yaml.

I didnt realise that the sensor needed to be dropped in to config and then the remainder in to automations.

I have put it in and no more errors.

#10 PianSom

Qyaunos1

This needs to go in your configuration.yaml (below whatever is already there). Obviously correct the XXXXXXX.

sensor:
  - platform: template
    sensors:
      charge_rate:
        friendly_name: "Dynamic Charge Rate"
        unit_of_measurement: "W"
        value_template: >
          {% set original_value = states('sensor.givtcp_XXXXXXXX_pv_power')|float %}
          {% set adjusted_value = original_value - 4100 %}
          {{ adjusted_value if adjusted_value > 0 else 0 }}

(See what I did there with three back-ticks at the start and end of what I pasted?)

This will create the sensor in Home Assistant. Do this first, and make sure that you are not getting errors (before re-starting!) and that the sensor is created properly.

Now you need to add in the two automations. If you don't/didn't already have an automations.yaml then you can just put them at the end of configuration.yaml. You need to make sure that the formatting is correct. You will need to put an automation: in. See this page for more help with this route. Check the indentation! Run the test before restarting.

If you do have an automations.yaml file already then make sure the indentation of what you are posting matches EXACTLY what is there atm. It looks like you will need to put two extra spaces at the start of every line.

D
#11 DD

Qyaunos1 You presumably have a hybrid inverter... may I ask which generation and firmware.

As far as I know, recent versions have this exact functionality built into the inverter. Unfortunately, doesn't seem to work for me (though support confirmed that it should...)