Using trend for detecting power to grid?

Hi All,

I am relative new to H.A, using it for some months now, and slowly enhancing my install.

At this moment I would like to send a message via telegram when my P1 readings have increasing values for either low, or high tariff power returning to the grid (in other words, I should be doing something more useful with this energy: charging car, heating water etc…)

I created two sensors for this purpose, with this in the configuration file:

binary_sensor:
  - platform: trend
    sensors:
      trend_ret_low:
        entity_id: sensor.ret_low
        #sample_duration: 180
        #max_samples: 3
        #min_gradient: -0.0008
        device_class: power
      trend_ret_high:
        entity_id: sensor.ret_high
        #sample_duration: 180
        #max_samples: 3
        #min_gradient: 0.0008
        device_class: power

and an automation:

- id: '1000000000001'
  alias: return_high
  trigger:
  - platform: numeric_state
    entity_id: sensor.ret_high
    above: '5'
  action:
  - service: telegram_bot.send_message
    data:
      message: <I>return high!</I>
      title: <b>Home Assistant:</b>
      parse_mode: html
- id: '1652598475510'
  alias: return_low
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.ret_low
    above: '5'
  condition: []
  action:
  - service: telegram_bot.send_message
    data:
      message: <I>return low!</I>
      title: <b>Home Assistant:</b>
      parse_mode: html
  mode: single

If I check the statistics for both the ‘ret_low’ or ‘ret_high’ sensors, they show a increment:

However, the messages are send at really strange times (in the night), which is a but strange when there is no sun :slight_smile:

Any tips are welcome for improvements on either my config, and my knowledge of how this should be interpreted…