Run automation when delivery is at least x value

Hi All,

I’m thinking about this setup for months, and fighting with it for at least a weak now and can’t get the result I want.

I’ll try to describe my goal as clear as possible.

I have solar panels and want to make optimal use of it due to (probably) upcoming regulations in the future.

When I have delivered at least 10kWh to the grid between 15:00h (4pm) and 19:00h (7PM) and current power of panels is at least 1000w, send notification to mobile device to ask if a certain device should activate for 30 minutes.

The notifcation part and the current usage is solved already.
When current power-usage is at between -1000w and -3000w and the automation has not triggered in the last 6 hours, fire the script.

alias: veel stroom
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.power_usage
    below: -1000
    for:
      hours: 0
      minutes: 0
      seconds: 0
    above: -3000
condition:
  - condition: template
    value_template: >-
      {{ (utcnow() | as_timestamp - state_attr('automation.veel_stroom',
      'last_triggered') | as_timestamp) | default(0) | int > 21600 }}
  - condition: time
    after: "15:00:00"
    before: "19:00:00"
action:
  - service: script.1690570106874
    data: {}
mode: single

But now the first part (which I thought was the easiest :)) giving me some headache.

I have a YouLess power meter which is showing perfectly on the energy dashboard.
I thought to use the value of the card “energy-grid-neutrality-gauge”, but eihter I can’t find that value in any sensor or it is due to the calculation done and not written into any sensor.

The sensors I am working with for my power grid:

  • Grid usage:
    Sensor.Energy_High
    Sensor.Energy_Low

  • Grid Delivery
    Sesnro.Energy_deliver_high
    Sesnro.Energy_deliver_low

What I’ve tried to do is create for every sensor a additional counter to keep track of em for a single day, and reset them every day.
then in a additional helper substract them from eachother.
This seemed to work, but at night, i’m still at a a negative number which is impossilbe due to no sun :slight_smile:

Who is able to help me out to do this setup. I’m not very familiair yet with scripting. I know where to find the config files and not scared to do some editing.

I’ve tried multple solutions from other topics to writhe some values into a single sensor, but I’m not able to get that working for some reason and not able to troubleshout. For the simple reason I’m not familair yet with the YAML scripts and where to look where it fails.

Help me ? :slight_smile:

Home Assistant 2023.7.3 on a vmWare environment

Small bump…? :laughing: