De code in mijn vorige post was niet alleen moeilijk leesbaar, hij was ook niet volledig.

Hoewel ik nog steeds bezig ben om de code te verbeteren, wil ik je deze tussentijdse versie niet onthouden. Doe er je voordeel mee en heb jij zelf verbeteringen aangebracht, ik blijf graag op de hoogte.

configuration.yaml

Hieronder tref je de wijzigingen die ik heb aangebracht in configuration.yaml. Alle sensoren die ik heb gemaakt zitten er in. Bedenk wel dat deze soms refereren naar sensoren in mijn HomeMatic systeem. Je moet deze dus aanpassen naar jouw fysieke sensoren.

template:
  - sensor:
      - name: "EV_Laadpaal_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_18_frequency') | float * 3.6 * 10.0}}
  - sensor:
      - name: "EV_Solar_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_16_frequency') | float * 3.6 * 1.0}}
  - sensor:
      - name: "EV_Tuinhuis_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_17_frequency') | float * 3.6 * 1.0}}
  - sensor:
      - name: "EV_Heating_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_15_frequency') | float * 3.6 * 1.0}}
  - sensor:
      - name: "EV_Huishoudverbruik_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_19_frequency') | float * 3.6 * 10.0}}
  - sensor:
      - name: "EV_Boot_Actueel"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states('sensor.leq0147882_20_frequency') | float * 3.6 * 10.0}}
          
  - sensor:
      - name: "Day_Ahead_Avg_Price"
        device_class: monetary
        unit_of_measurement: €
        state: >
          {{ state_attr ('sensor.day_ahead_price', 'avg_price')}}  
  - sensor:
      - name: "Day_Ahead_Current_Price"
        #device_class: monetary
        unit_of_measurement: €/kWh
        state: >
          {{ state_attr ('sensor.day_ahead_price', 'day_ahead_price')}}
  - sensor:
      - name: "Day_Ahead_Min_Price"
        device_class: monetary
        unit_of_measurement: €
        state: >
          {{ state_attr ('sensor.day_ahead_price', 'min_price')}}
  - sensor:
      - name: "Day_Ahead_Max_Price"
        device_class: monetary
        unit_of_measurement: €
        state: >
          {{ state_attr ('sensor.day_ahead_price', 'max_price')}}
  - sensor:
      - name: "Day_Ahead_Lowerband_Price"
        device_class: monetary
        unit_of_measurement: €
        state: >
          {{ (1-(states ('input_number.ess_price_lower_band')) | int / 100) * (states ('sensor.day_ahead_avg_price') | float ) }}
  - sensor:
      - name: "Day_Ahead_Upperband_Price"
        device_class: monetary
        unit_of_measurement: €
        state: >
          {{ (1+(states ('input_number.ess_price_upper_band')) | int / 100) * (states ('sensor.day_ahead_avg_price') | float )}}        
  - sensor:
      - name: "VE Grid Power"
        device_class: power
        unit_of_measurement: W
        state: >
          {{ states("sensor.ve_grid_power_l1") |float + states("sensor.ve_grid_power_l2") | float + states("sensor.ve_grid_power_l3") |float }}
  - sensor:
      - name: "ESS_Grid_Setpoint"
      ## use this to set ESS grid setpoint. Values are determined by maximum grid connection point
      ## substract value from 65535 for negative vaule
        device_class: power
        unit_of_measurement: W
        state: >
          {% if is_state("input_number.ess_grid_feedin", "0.0") -%}
            0
          {%- elif is_state("input_number.ess_grid_feedin", "1.0") -%}
            17250
          {%- elif is_state("input_number.ess_grid_feedin", "-1.0") -%}
            48285
          {%- endif %}

mqtt: 
  sensor:
    - state_topic: entsoe/day-ahead
      name: 'Day-ahead-price'
      unit_of_measurement: "€"
      value_template: '{{ value_json.day_ahead_price }}'
      json_attributes_topic: entsoe/day-ahead

Automations.yaml

Hieronder de automations die ik heb gemaakt. Meestal heb ik hiervoor de wizzards gebruikt maar uiteindelijk wordt alles in code omgezet. Ik verwijs graag naar mij Youtube video voor uitleg over de automations. Anders begrijp je niet zo goed wat deze doen. Ook voor dit bestand geldt dat enkele verwijzingen refereren aan specifieke hardware en/of sensoren.

- id: '1662234306246'
  alias: Switch on Energy Import and Energy Consumers
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.day_ahead_price
    attribute: day_ahead_price
    below: sensor.day_ahead_lowerband_price
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id:
      - switch.peq1418450_7
  - service: input_number.set_value
    data:
      value: 1
    target:
      entity_id: input_number.ess_grid_feedin
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.peq1418450_8
  mode: single
- id: '1662899027507'
  alias: Set ESS Grid Feed by writing Modbus register
  description: This automation sets the Victron ESS Grid feed to in, out or 0
  trigger:
  - platform: state
    entity_id:
    - input_number.ess_grid_feedin
  condition: []
  action:
  - service: modbus.write_register
    data:
      address: 2700
      slave: 100
      value: '{{ states(''sensor.ess_grid_setpoint'') }}'
      hub: victron
  mode: single
- id: '1663360219833'
  alias: Switch off Energy Import and Consumers and Export Energy to Grid
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.day_ahead_price
    attribute: day_ahead_price
    above: sensor.day_ahead_upperband_price
  condition:
  - condition: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    above: 50
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.peq1418450_7
  - service: input_number.set_value
    data:
      value: -1
    target:
      entity_id: input_number.ess_grid_feedin
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.peq1418450_8
  mode: single
- id: '1663360672817'
  alias: Switch off Energy Import and set Grid setpoint to 0
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.day_ahead_price
    attribute: day_ahead_price
    above: sensor.day_ahead_lowerband_price
    below: sensor.day_ahead_upperband_price
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id:
      - switch.peq1418450_8
      - switch.peq1418450_7
  - service: input_number.set_value
    data:
      value: 0
    target:
      entity_id: input_number.ess_grid_feedin
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.peq1418450_9
  mode: single
- id: '1663598422950'
  alias: Switch off Energy Export to grid if SoC < 50%
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    below: 50
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: 0
    target:
      entity_id: input_number.ess_grid_feedin
  mode: single
- id: '1664573680849'
  alias: VSW ultra low switch on
  description: Schakelt schakelaar aan als de elec prijs zeer laag is.
  trigger:
  - platform: numeric_state
    entity_id: sensor.day_ahead_price
    attribute: day_ahead_price
    below: 0.02
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.peq1418450_9
  mode: single
- id: '1664573871793'
  alias: VSW ultra low switch off
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: sensor.day_ahead_price
    attribute: day_ahead_price
    above: 0.02
  condition: []
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.peq1418450_9
  mode: single
- id: '1665776652412'
  alias: Increase Low Bandwidth Price to 20%
  description: Verlaag de bandbreedte met naar 20 als SoC <50%
  trigger:
  - platform: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    below: 50
    above: 40
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: 20
    target:
      entity_id: input_number.ess_price_lower_band
  mode: single
- id: '1665776936570'
  alias: Decrease Low Bandwidth Price to 10%
  description: Verlaag de bandbreedte naar 10% als SoC <40%
  trigger:
  - platform: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    below: 40
    above: 30
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: 10
    target:
      entity_id: input_number.ess_price_lower_band
  mode: single
- id: '1665778310119'
  alias: Switch off Energy Import when Sunny or Partly Cloudy
  description: ''
  trigger:
  - platform: state
    entity_id:
    - weather.vriendschap
    to:
    - sunny
    - partlycloudy
  condition:
  - condition: numeric_state
    entity_id: sun.sun
    attribute: rising
    above: 0
  action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.peq1418450_7
  mode: single
- id: '1666123826682'
  alias: Decrease Upper Bandwidth to 15% if SoC > 80%
  description: Verlaag de bandbreedte met naar 20 als SoC >80%
  trigger:
  - platform: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    below: 100
    above: 80
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: 15
    target:
      entity_id: input_number.ess_price_upper_band
  mode: single
- id: '1666124043886'
  alias: Increase Upper Bandwidth to 20% if SoC is > 50% and < 80%
  description: Verhoog de bandbreedte met naar 20 als SoC <80%
  trigger:
  - platform: numeric_state
    entity_id: sensor.ve_battery_state_of_charge_system
    below: 80
    above: 50
  condition: []
  action:
  - service: input_number.set_value
    data:
      value: 20
    target:
      entity_id: input_number.ess_price_upper_band
  mode: single

Modbus.yaml

DIt bevat de lijst van registers die ik in modbus aanspreek om de informatie uit te lezen (en te schrijven) voor de Victron Energy Multiplus inverters.

# modbus victron ess
  - name: victron
    retry_on_empty: true
    retries: 10
    type: tcp
    host: <your IP address of the Cerbo/CCGX device>
    port: 502
# REMARK: scan_interval: <5 can cause troubles
    sensors:
    - name: 'VE AC Consumption L1'
      unit_of_measurement: "W"
      slave: 100
      address: 817
      data_type: uint16
      scan_interval: 5
      device_class: power

    - name: 'VE AC Consumption L2'
      unit_of_measurement: "W"
      slave: 100
      address: 818
      data_type: uint16
      scan_interval: 5
      device_class: power

    - name: 'VE AC Consumption L3'
      unit_of_measurement: "W"
      slave: 100
      address: 819
      data_type: uint16
      scan_interval: 5
      device_class: power
  
    - name: 'VE Grid power L1'
      unit_of_measurement: "W"
      slave: 100
      address: 820
      data_type: int16
      scan_interval: 5
      device_class: power

    - name: 'VE Grid power L2'
      unit_of_measurement: "W"
      slave: 100
      address: 821
      data_type: int16
      scan_interval: 5
      device_class: power    

    - name: 'VE Grid power L3'
      unit_of_measurement: "W"
      slave: 100
      address: 822
      data_type: int16
      scan_interval: 5
      device_class: power

    - name: 'VE Critical Loads power L1'
      unit_of_measurement: "W"
      slave: 246
      address: 23
      data_type: int16
      scale: 10
      scan_interval: 5
      device_class: power
    
    - name: 'VE Critical Loads power L2'
      unit_of_measurement: "W"
      slave: 246
      address: 24
      data_type: int16
      scale: 10
      scan_interval: 5
      device_class: power
    
    - name: 'VE Critical Loads power L3'
      unit_of_measurement: "W"
      slave: 246
      address: 25
      data_type: int16
      scale: 10
      scan_interval: 5
      device_class: power

# ESS Settings
    - name: 'VE ESS Minimum SoC setpoint'
      unit_of_measurement: "%"
      data_type: uint16
      slave: 100
      address: 2901
      scan_interval: 5
      scale: 0.1
      
    - name: 'VE Maximum System Grid Feed In'
      unit_of_measurement: "W"
      data_type: uint16
      slave: 100
      address: 2706
      scale: 0.01
      device_class: power
      # command_on: 4000
      # command_off: 40
      # verify_state: false

    - name: 'VE ESS BatteryLife state'
      data_type: uint16
      slave: 100
      address: 2900
      scan_interval: 5
      
    - name: 'VE ESS Grid setpoint'
      unit_of_measurement: "W"
      data_type: int16
      slave: 100
      address: 2700
      device_class: power

#Battery 
    - name: 'VE Battery current'
      unit_of_measurement: "A DC"
      slave: 100
      address: 841
      data_type: int16
      scale: 0.1
      precision: 0
      device_class: current
      
    - name: 'VE Battery Power System'
      unit_of_measurement: "W"
      slave: 100
      address: 842
      data_type: int16
      scale: 1.0
      precision: 0
      device_class: power

      # VE Charge power. deze gebruiken voor omrekenen van min en pos
    - name: 'VE Charge Power System'
      unit_of_measurement: "W"
      slave: 100
      address: 866
      data_type: int16
      scale: 1.0
      precision: 0
      device_class: energy
      
    - name: 'VE Battery State of Charge System'
      unit_of_measurement: "%"
      slave: 100
      address: 843
      data_type: uint16
      scale: 1
      precision: 0

    - name: 'VE Battery Discharged Energy'
      unit_of_measurement: "kWh"
      slave: 245
      address: 301
      data_type: uint16
      scale: 0.1
      precision: 0
      device_class: energy
      state_class: total_increasing

    - name: 'VE Battery Charged Energy'
      unit_of_measurement: "kWh"
      slave: 245
      address: 302
      data_type: uint16
      scale: 0.1
      precision: 0
      device_class: energy
      state_class: total_increasing

 # Victron device over Modbus: vebus
      # Grid Voltage
    - name: 'VE Grid Voltage L1 in'
      unit_of_measurement: "V AC"
      slave: 246
      address: 3
      data_type: uint16
      scale: 0.1
      offset: 0
      precision: 2
      device_class: voltage

    - name: 'VE Grid Voltage L2 in'
      unit_of_measurement: "V AC"
      slave: 246
      address: 4
      data_type: uint16
      scale: 0.1
      offset: 0
      precision: 2
      device_class: voltage

    - name: 'VE Grid Voltage L3 in'
      unit_of_measurement: "V AC"
      slave: 246
      address: 5
      data_type: uint16
      scale: 0.1
      offset: 0
      precision: 2
      device_class: voltage
      
    - name: "VE Multi Inverter State"
      slave: 246
      address: 31
      data_type: uint16
      # Inverter States, 0=Off;1=Low Power;2=Fault;3=Bulk;4=Absorption;5=Float;6=Storage;7=Equalize;8=Passthru;9=Inverting;10=Power assist;11=Power supply;252=Bulk protection   
 
#Alarm Sensors
    - name: 'VE Grid lost alarm'
      slave: 246
      address: 64
      data_type: uint16
      unit_of_measurement: "0=Ok;1=Warning"
      
    - name: 'VE Multi Temperature alarm'
      slave: 246
      address: 34
      data_type: uint16
      unit_of_measurement: "0=Ok;1=Warning;2=Alarm"
      
    - name: 'VE Multi Overload alarm'
      slave: 246
      address: 36
      data_type: uint16
      unit_of_measurement: "0=Ok;1=Warning;2=Alarm"
      

Node Red Generate URL

Vandaag heb ik nog een fout gevonden in de onderstaande code. Deze houdt namelijk geen rekening met de zomertijd waardoor de data in de grafieken een uur te vroeg staat. Het maakt voor de werking niets uit.

const today = new Date()
let todayDate = ("0" + today.getDate()).slice(-2)
let todayMonth = ("0" + (today.getMonth() + 1)).slice(-2);
let todayYear = today.getFullYear();
let todayString = todayYear + todayMonth + todayDate;

var urlAddr = "https://transparency.entsoe.eu/api?securityToken=<your token>&documentType=A44&in_Domain=10YNL----------L&out_Domain=10YNL----------L&periodStart=" + todayString + "0000&periodEnd=" + todayString + "2300"
msg.url = urlAddr;
return msg;

Node Red Get Next Hour Price

In onderstaande code staan nog de max_price en min_price genoemd. Ik gebruik deze verder niet in mijn algoritmes. Maar als je er gebruik van wilt maken dan kan dat.

var priceArray = [];
priceArray = flow.get("pArray");
const today = new Date();
let todayHour = today.getHours();
let todayDate = ("0" + today.getDate()).slice(-2)
let todayMonth = ("0" + (today.getMonth() + 1)).slice(-2);
let todayYear = today.getFullYear();

msg.payload = {
    "day_ahead_price": priceArray[todayHour] / 1000,
    "avg_price": priceArray[24] / 1000,
    "max_price": priceArray[25] / 1000,
    "min_price": priceArray[26] / 1000,
    "records": [
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T00:00:00",
            "Price": priceArray[0] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T01:00:00",
            "Price": priceArray[1] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T02:00:00",
            "Price": priceArray[2] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T03:00:00",
            "Price": priceArray[3] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T04:00:00",
            "Price": priceArray[4] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T05:00:00",
            "Price": priceArray[5] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T06:00:00",
            "Price": priceArray[6] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T07:00:00",
            "Price": priceArray[7] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T08:00:00",
            "Price": priceArray[8] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T09:00:00",
            "Price": priceArray[9] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T10:00:00",
            "Price": priceArray[10] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T11:00:00",
            "Price": priceArray[11] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T12:00:00",
            "Price": priceArray[12] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T13:00:00",
            "Price": priceArray[13] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T14:00:00",
            "Price": priceArray[14] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T15:00:00",
            "Price": priceArray[15] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T16:00:00",
            "Price": priceArray[16] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T17:00:00",
            "Price": priceArray[17] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T18:00:00",
            "Price": priceArray[18] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T19:00:00",
            "Price": priceArray[19] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T20:00:00",
            "Price": priceArray[20] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T21:00:00",
            "Price": priceArray[21] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T22:00:00",
            "Price": priceArray[22] / 1000
        },
        {
            "Time": todayYear + "-" + todayMonth + "-" + todayDate + "T23:00:00",
            "Price": priceArray[23] / 1000
        }
    ]
};
return msg;

De Apex-chart grafiek

Hier kan nog iets aan verbeterd worden maar inmiddels geeft het wel een goed overzicht.

de apex-chart grafiek
type: custom:apexcharts-card
experimental:
  color_threshold: true
graph_span: 24h
show:
  last_updated: true
span:
  start: day
header:
  title: Energy Prices today
  standard_format: false
  show: true
  show_states: false
  colorize_states: true
apex_config:
  chart:
    height: 370
    curve: stepline
  legend:
    show: true
    showForSingleSeries: false
    showForNullSeries: true
    showForZeroSeries: true
    position: bottom
    horizontalAlign: left
    floating: false
    inverseorder: true
    onItemHover:
      highlightDataSeries: false
    ontimeClick:
      toggleDataSeries: false
    tooltip:
      enabled: true
now:
  show: false
  color: red
  label: Now
yaxis:
  - id: first
    min: -0.1
    max: ~0.5
    decimals: 2
    apex_config:
      tickAmount: 12
  - id: second
    opposite: true
    min: 0
    max: 100
    decimals: 0
    apex_config:
      tickAmount: 10
series:
  - entity: sensor.day_ahead_lowerband_price
    yaxis_id: first
    type: line
    color: hotpink
    unit: ' €'
    float_precision: 3
    stroke_width: 2
  - entity: sensor.day_ahead_upperband_price
    yaxis_id: first
    type: line
    color: steelblue
    unit: ' €'
    float_precision: 3
    stroke_width: 2
  - entity: sensor.day_ahead_price
    yaxis_id: first
    type: column
    color: black
    unit: ' €'
    float_precision: 3
    stroke_width: 10
    show:
      header_color_threshold: true
      legend_value: false
    data_generator: |
      return entity.attributes.records.map((record, index) => {
        return [record.Time, record.Price];
      });
    color_threshold:
      - value: 0
        color: green
      - value: 0.05
        color: lightgreen
      - value: 0.1
        color: yellowgreen
      - value: 0.15
        color: yellow
      - value: 0.2
        color: yelloworange
      - value: 0.3
        color: orange
      - value: 0.4
        color: orangered
      - value: 0.5
        color: red
      - value: 0.6
        color: purple
      - value: 0.7
        color: blue
  - entity: sensor.ve_battery_state_of_charge_system
    yaxis_id: second
    stroke_width: 3
    color: blue
view_layout:
  position: main

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *

Deze site gebruikt Akismet om spam te verminderen. Bekijk hoe je reactie-gegevens worden verwerkt.